Skip to content

Commit 7bf8f38

Browse files
committed
Consistently use test names for MRI tests and refactor
1 parent 8bf5f48 commit 7bf8f38

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

tool/jt.rb

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
require 'pathname'
2222

2323
TRUFFLERUBY_DIR = File.expand_path('../..', File.realpath(__FILE__))
24-
MRI_TEST_CEXT_DIR = "#{TRUFFLERUBY_DIR}/test/mri/tests/cext-c"
25-
MRI_TEST_CEXT_LIB_DIR = "#{TRUFFLERUBY_DIR}/.ext/c"
2624
PROFILES_DIR = "#{TRUFFLERUBY_DIR}/profiles"
2725

2826
TRUFFLERUBY_GEM_TEST_PACK_VERSION = "8b57f6022f0fa17ace7c8d2a3af730357715e0a2"
@@ -52,39 +50,42 @@
5250

5351
require "#{TRUFFLERUBY_DIR}/lib/truffle/truffle/openssl-prefix.rb"
5452

53+
MRI_TEST_RELATIVE_PREFIX = "test/mri/tests"
54+
MRI_TEST_PREFIX = "#{TRUFFLERUBY_DIR}/#{MRI_TEST_RELATIVE_PREFIX}"
55+
MRI_TEST_CEXT_DIR = "#{MRI_TEST_PREFIX}/cext-c"
56+
MRI_TEST_CEXT_LIB_DIR = "#{TRUFFLERUBY_DIR}/.ext/c"
57+
5558
# A list of MRI C API tests we can run. Files that do not load at all are in failing.exclude.
56-
MRI_TEST_CAPI_TESTS = File.readlines("#{TRUFFLERUBY_DIR}/test/mri/capi_tests.list").map { |line|
57-
"#{TRUFFLERUBY_DIR}/test/mri/tests/#{line.chomp}"
58-
}
59+
MRI_TEST_CAPI_TESTS = File.readlines("#{TRUFFLERUBY_DIR}/test/mri/capi_tests.list").map(&:chomp)
5960

6061
MRI_TEST_MODULES = {
6162
'--openssl' => {
6263
help: 'include only openssl tests',
63-
include: openssl = Dir["#{TRUFFLERUBY_DIR}/test/mri/tests/openssl/test_*.rb"].sort,
64+
include: openssl = ["openssl/test_*.rb"],
6465
},
6566
'--syslog' => {
6667
help: 'include only syslog tests',
6768
include: syslog = [
68-
"#{TRUFFLERUBY_DIR}/test/mri/tests/test_syslog.rb",
69-
"#{TRUFFLERUBY_DIR}/test/mri/tests/syslog/test_syslog_logger.rb"
69+
"test_syslog.rb",
70+
"syslog/test_syslog_logger.rb"
7071
]
7172
},
7273
'--cexts' => {
7374
help: 'run all MRI tests testing C extensions',
7475
include: cexts = openssl + syslog + [
75-
"#{TRUFFLERUBY_DIR}/test/mri/tests/etc/test_etc.rb",
76-
"#{TRUFFLERUBY_DIR}/test/mri/tests/nkf/test_kconv.rb",
77-
"#{TRUFFLERUBY_DIR}/test/mri/tests/nkf/test_nkf.rb",
78-
"#{TRUFFLERUBY_DIR}/test/mri/tests/zlib/test_zlib.rb",
76+
"etc/test_etc.rb",
77+
"nkf/test_kconv.rb",
78+
"nkf/test_nkf.rb",
79+
"zlib/test_zlib.rb",
7980
]
8081
},
8182
'--capi' => {
8283
help: 'run all C-API MRI tests',
83-
include: MRI_TEST_CAPI_TESTS,
84+
include: capi = MRI_TEST_CAPI_TESTS,
8485
},
8586
'--all-sulong' => {
8687
help: 'run all tests requiring Sulong (C exts and C API)',
87-
include: all_sulong = cexts + MRI_TEST_CAPI_TESTS
88+
include: all_sulong = cexts + capi
8889
},
8990
'--no-sulong' => {
9091
help: 'exclude all tests requiring Sulong',
@@ -985,7 +986,6 @@ def test_mri(*args)
985986
end
986987

987988
mri_args = []
988-
prefix = "#{TRUFFLERUBY_DIR}/test/mri/tests/"
989989
excluded_files = File.readlines("#{TRUFFLERUBY_DIR}/test/mri/failing.exclude").
990990
map { |line| line.gsub(/#.*/, '').strip }.reject(&:empty?)
991991
patterns = []
@@ -1002,34 +1002,39 @@ def test_mri(*args)
10021002
end
10031003
end
10041004

1005-
patterns.push "#{TRUFFLERUBY_DIR}/test/mri/tests/**/test_*.rb" if patterns.empty?
1005+
patterns.push "#{MRI_TEST_PREFIX}/**/test_*.rb" if patterns.empty?
10061006

10071007
files_to_run = patterns.flat_map do |pattern|
1008-
Dir.glob(pattern).map do |path|
1009-
expanded_path = File.expand_path path
1010-
raise 'pattern does not match test files' unless expanded_path.start_with?(prefix)
1011-
expanded_path[prefix.size..-1]
1012-
end.reject do |path|
1013-
path.empty?
1008+
if pattern.start_with?(MRI_TEST_RELATIVE_PREFIX)
1009+
pattern = "#{TRUFFLERUBY_DIR}/#{pattern}"
1010+
elsif !pattern.start_with?(MRI_TEST_PREFIX)
1011+
pattern = "#{MRI_TEST_PREFIX}/#{pattern}"
10141012
end
1015-
end.sort - excluded_files
1013+
glob = Dir.glob(pattern)
1014+
abort "pattern #{pattern} matched no files" if glob.empty?
1015+
glob.map { |path| mri_test_name(path) }
1016+
end.sort
1017+
files_to_run -= excluded_files
10161018

10171019
run_mri_tests(mri_args, files_to_run, runner_args, use_exec: true)
10181020
end
10191021
private :test_mri
10201022

1023+
def mri_test_name(test)
1024+
prefix = "#{MRI_TEST_RELATIVE_PREFIX}/"
1025+
abs_prefix = "#{MRI_TEST_PREFIX}/"
1026+
if test.start_with?(prefix)
1027+
test[prefix.size..-1]
1028+
elsif test.start_with?(abs_prefix)
1029+
test[abs_prefix.size..-1]
1030+
else
1031+
test
1032+
end
1033+
end
1034+
private :mri_test_name
1035+
10211036
def run_mri_tests(extra_args, test_files, runner_args, run_options)
1022-
prefix = "test/mri/tests/"
1023-
abs_prefix = "#{TRUFFLERUBY_DIR}/#{prefix}"
1024-
test_files = test_files.map { |file|
1025-
if file.start_with?(prefix)
1026-
file[prefix.size..-1]
1027-
elsif file.start_with?(abs_prefix)
1028-
file[abs_prefix.size..-1]
1029-
else
1030-
file
1031-
end
1032-
}
1037+
test_files = test_files.map { |file| mri_test_name(file) }
10331038

10341039
truffle_args = []
10351040
if !extra_args.include?('--native')
@@ -1038,7 +1043,7 @@ def run_mri_tests(extra_args, test_files, runner_args, run_options)
10381043

10391044
env_vars = {
10401045
"EXCLUDES" => "test/mri/excludes",
1041-
"RUBYGEMS_TEST_PATH" => "#{TRUFFLERUBY_DIR}/test/mri/tests",
1046+
"RUBYGEMS_TEST_PATH" => MRI_TEST_PREFIX,
10421047
"RUBYOPT" => [*ENV['RUBYOPT'], '--disable-gems'].join(' '),
10431048
"TRUFFLERUBY_RESILIENT_GEM_HOME" => nil,
10441049
}
@@ -1054,7 +1059,7 @@ def run_mri_tests(extra_args, test_files, runner_args, run_options)
10541059
cext_tests.each do |test|
10551060
puts
10561061
puts test
1057-
test_path = "#{TRUFFLERUBY_DIR}/test/mri/tests/#{test}"
1062+
test_path = "#{MRI_TEST_PREFIX}/#{test}"
10581063
match = File.read(test_path).match(/\brequire ['"]c\/(.*?)["']/)
10591064
if match
10601065
cext_name = match[1]

0 commit comments

Comments
 (0)