diff options
author | Koichi Sasada <ko1@atdot.net> | 2019-08-09 16:08:15 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2019-08-09 16:08:15 +0900 |
commit | 3cbd56d574a3ce6d5ddeb748462eb4dcdce4d166 (patch) | |
tree | ba56fdaca257fe2acd7fed65490b4776adf7400d /tool | |
parent | 26cf4c91ad357fe6c8fc2247abe980dbf9a5b331 (diff) | |
download | ruby-3cbd56d574a3ce6d5ddeb748462eb4dcdce4d166.tar.gz |
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`.
Diffstat (limited to 'tool')
-rw-r--r-- | tool/lib/test/unit.rb | 19 |
1 files changed, 14 insertions, 5 deletions
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 |