Skip to content

Commit

Permalink
testunit: negative filter
Browse files Browse the repository at this point in the history
* test/lib/test/unit.rb (Options#non_options): make regexp name
  options prefixed with "!" negative filters.
* common.mk (TEST_EXCLUDES): use negative filter to exclude memory
  leak tests.  -x option excludes test files, not test methods.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Mar 11, 2016
1 parent 5976664 commit 83e36bb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,3 +1,11 @@
Fri Mar 11 17:03:09 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>

* test/lib/test/unit.rb (Options#non_options): make regexp name
options prefixed with "!" negative filters.

* common.mk (TEST_EXCLUDES): use negative filter to exclude memory
leak tests. -x option excludes test files, not test methods.

Fri Mar 11 16:11:27 2016 Martin Duerst <duerst@it.aoyama.ac.jp>

* enc/unicode/case-folding.rb, casefold.h: Streamlining approach to
Expand Down
2 changes: 1 addition & 1 deletion common.mk
Expand Up @@ -154,7 +154,7 @@ PRE_LIBRUBY_UPDATE = $(MINIRUBY) -e 'ARGV[1] or File.unlink(ARGV[0]) rescue nil'
$(LIBRUBY_EXTS) $(LIBRUBY_SO_UPDATE)

TESTSDIR = $(srcdir)/test
TEST_EXCLUDES = --excludes=$(TESTSDIR)/excludes -x /memory_leak/
TEST_EXCLUDES = --excludes=$(TESTSDIR)/excludes --name=!/memory_leak/
EXCLUDE_TESTFRAMEWORK = -x /testunit/ -x /minitest/
TESTWORKDIR = testwork
TESTOPTS = $(RUBY_TESTOPTS)
Expand Down
30 changes: 26 additions & 4 deletions test/lib/test/unit.rb
Expand Up @@ -87,7 +87,7 @@ def setup_options(opts, options)
end

opts.on '-n', '--name PATTERN', "Filter test method names on pattern: /REGEXP/ or STRING" do |a|
options[:filter] = a
(options[:filter] ||= []) << a
end

opts.on '--test-order=random|alpha|sorted', [:random, :alpha, :sorted] do |a|
Expand All @@ -96,6 +96,30 @@ def setup_options(opts, options)
end

def non_options(files, options)
filter = options[:filter]
if filter
pos_pat = /\A\/(.*)\/\z/
neg_pat = /\A!\/(.*)\/\z/
negative, positive = filter.partition {|s| neg_pat =~ s}
if positive.empty?
filter = nil
elsif negative.empty? and positive.size == 1 and pos_pat !~ positive[0]
filter = positive[0]
else
filter = Regexp.union(*positive.map! {|s| s[pos_pat, 1] || "\\A#{Regexp.quote(s)}\\z"})
end
unless negative.empty?
negative = Regexp.union(*negative.map! {|s| s[neg_pat, 1]})
filter = /\A(?!.*#{negative})#{filter}/
end
if Regexp === filter
# bypass conversion in minitest
def filter.=~(other) # :nodoc:
super unless Regexp === other
end
end
options[:filter] = filter
end
true
end
end
Expand Down Expand Up @@ -594,9 +618,7 @@ def _prepare_run(suites, type)
@verbose = !options[:parallel]
end
@output = Output.new(self) unless @options[:testing]
if /\A\/(.*)\/\z/ =~ (filter = options[:filter])
filter = Regexp.new($1)
end
filter = options[:filter]
type = "#{type}_methods"
total = if filter
suites.inject(0) {|n, suite| n + suite.send(type).grep(filter).size}
Expand Down

0 comments on commit 83e36bb

Please sign in to comment.