From 3cbd56d574a3ce6d5ddeb748462eb4dcdce4d166 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 9 Aug 2019 16:08:15 +0900 Subject: complement `test_` prefix. `make test-all TESTS=name` can specify running test files by name. name can be dirname ('dir/') or a file ('.../test_foo.rb'). This patch complement `test_` prefix for a test. So we only need to specify `TESTS=ruby/hash` which means `TESTS=ruby/test_hash.rb`. --- tool/lib/test/unit.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'tool') diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb index 37c17babb4..8832022fbe 100644 --- a/tool/lib/test/unit.rb +++ b/tool/lib/test/unit.rb @@ -865,6 +865,18 @@ module Test end end + def complement_test_name f, orig_f + basename = File.basename(f) + + if /\.rb\z/ !~ basename + return File.join(File.dirname(f), basename+'.rb') + elsif /\Atest_/ !~ basename + return File.join(File.dirname(f), 'test_'+basename) + end if /#{basename}\z/ =~ f # otherwise basename is dirname/ + + raise ArgumentError, "file not found: #{orig_f}" + end + def non_options(files, options) paths = [options.delete(:base_directory), nil].uniq if reject = options.delete(:reject) @@ -872,6 +884,7 @@ module Test end files.map! {|f| f = f.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR + orig_f = f while true ret = ((paths if /\A\.\.?(?:\z|\/)/ !~ f) || [nil]).any? do |prefix| if prefix @@ -898,11 +911,7 @@ module Test end end if !ret - if /\.rb\z/ =~ f - raise ArgumentError, "file not found: #{f}" - else - f = "#{f}.rb" - end + f = complement_test_name(f, orig_f) else break ret end -- cgit v1.2.3