From 546145283c3408266f70dc1ae1741944a7b9a8ed Mon Sep 17 00:00:00 2001 From: Ola Nilsson Date: Wed, 12 Aug 2020 22:55:38 +0200 Subject: [PATCH] Accept a list of regexes in buttercup-mark-skipped This means regexes are accepted on the command line --pattern option again. --pattern was downgraded to substring matching in 41424d5fa0732c96cd54fdbbcb8800a6e6170f34. Fixes #191. --- bin/buttercup | 9 +++++---- bin/buttercup.bat | 6 +++++- buttercup.el | 17 ++++++++++++----- tests/test-buttercup.el | 6 ++++-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/bin/buttercup b/bin/buttercup index 8562905..601a8e0 100755 --- a/bin/buttercup +++ b/bin/buttercup @@ -29,10 +29,11 @@ Buttercup options: --pattern, -p PATTERN Only run tests with names matching PATTERN. This option can be used multiple times, in which case tests will be run if they match - any of the given patterns. PATTERN is - matched as a substring of the full test - description (the concatenation of the test - and all paremt suites descriptions). + any of the given patterns. PATTERN should be + an Emacs regex that will be matched against + the full test description (the concatenation + of the test and all parent suites + descriptions). --no-skip Do not print the descriptions for tests that are filtered out with "--pattern" or disabled diff --git a/bin/buttercup.bat b/bin/buttercup.bat index eda7eca..edff81d 100644 --- a/bin/buttercup.bat +++ b/bin/buttercup.bat @@ -33,7 +33,11 @@ echo. echo --pattern, -p PATTERN Only run tests with names matching PATTERN. echo This option can be used multiple times, in echo which case tests will be run if they match -echo any of the given patterns. +echo any of the given patterns. PATTERN should be +echo an Emacs regex that will be matched against +echo the full test description (the concatenation +echo of the test and all parent suites +echo descriptions). echo. echo --no-skip Do not print the descriptions for tests that echo are filtered out with "--pattern" or disabled diff --git a/buttercup.el b/buttercup.el index df1aa72..66f6bcc 100644 --- a/buttercup.el +++ b/buttercup.el @@ -1399,21 +1399,28 @@ current directory." (when (not (string-match "\\(^\\|/\\)\\." (file-relative-name file))) (load file nil t)))) (when patterns - (buttercup-mark-skipped (regexp-opt patterns) t)) + (buttercup-mark-skipped patterns t)) (buttercup-run))) (defun buttercup-mark-skipped (matcher &optional reverse) "Mark any spec that match MATCHER as skipped. -MATCHER can be either a regex or a function taking a spec as the -single argument. If REVERSE is non-nil, specs will be marked as -pending when MATCHER does not match." +MATCHER can be either a regex, a list of regexes, or a function +taking a spec as the single argument. If REVERSE is non-nil, +specs will be marked as pending when MATCHER does not match." (cl-etypecase matcher (string (buttercup--mark-skipped buttercup-suites (lambda (spec) (string-match matcher (buttercup-spec-full-name spec))) reverse)) - (function (buttercup--mark-skipped buttercup-suites matcher reverse)))) + (function (buttercup--mark-skipped buttercup-suites matcher reverse)) + (list (cond + ((seq-every-p #'stringp matcher) + (buttercup-mark-skipped (mapconcat (lambda (re) + (concat "\\(?:" re "\\)")) + matcher "\\|") + reverse)) + (t (error "Bad matcher list: %s, should be list of strings" matcher)))))) (defun buttercup--mark-skipped (suites predicate &optional reverse-predicate) "Mark all specs in SUITES as skipped if PREDICATE(spec) is true. diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el index b9fbf54..cdf493a 100644 --- a/tests/test-buttercup.el +++ b/tests/test-buttercup.el @@ -1549,7 +1549,7 @@ text properties using `ansi-color-apply'." (expect (buttercup-suites-total-specs-pending suites) :to-equal 11)) (it "should handle multiple patterns" (with-local-buttercup :suites suites - (buttercup-mark-skipped (regexp-opt '("1-1-1" "1-1-2" "1-4" "2-4")) t)) + (buttercup-mark-skipped '("1-1-1" "1-1-2" "1-4" "2-4") t)) (expect (buttercup-suites-total-specs-defined suites) :to-equal 11) (expect (buttercup-suites-total-specs-pending suites) :to-equal 8)) (it "should support predicates" @@ -1567,7 +1567,9 @@ text properties using `ansi-color-apply'." (expect (buttercup-suites-total-specs-pending suites) :to-equal 6)) (it "should signal an error for invalid matchers" (with-local-buttercup - (expect (buttercup-mark-skipped 4) :to-throw))) + (expect (buttercup-mark-skipped 4) :to-throw)) + (with-local-buttercup + (expect (buttercup-mark-skipped (list "re" "re" 5 "re")) :to-throw))) ) ;;;;;;;;;;;;;;;;;;;;;