Skip to content

Commit

Permalink
Accept a list of regexes in buttercup-mark-skipped
Browse files Browse the repository at this point in the history
This means regexes are accepted on the command line --pattern option
again.  --pattern was downgraded to substring matching in
41424d5.

Fixes jorgenschaefer#191.
  • Loading branch information
snogge committed Aug 12, 2020
1 parent b76ff35 commit 562ce55
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
9 changes: 5 additions & 4 deletions bin/buttercup
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion bin/buttercup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -1399,21 +1399,25 @@ 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 (buttercup-mark-skipped (mapconcat (lambda (re)
(concat "\\(?:" re "\\)"))
matcher "\\|")
reverse))))

(defun buttercup--mark-skipped (suites predicate &optional reverse-predicate)
"Mark all specs in SUITES as skipped if PREDICATE(spec) is true.
Expand Down
2 changes: 1 addition & 1 deletion tests/test-buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 562ce55

Please sign in to comment.