21
21
require 'pathname'
22
22
23
23
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"
26
24
PROFILES_DIR = "#{ TRUFFLERUBY_DIR } /profiles"
27
25
28
26
TRUFFLERUBY_GEM_TEST_PACK_VERSION = "8b57f6022f0fa17ace7c8d2a3af730357715e0a2"
52
50
53
51
require "#{ TRUFFLERUBY_DIR } /lib/truffle/truffle/openssl-prefix.rb"
54
52
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
+
55
58
# 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 )
59
60
60
61
MRI_TEST_MODULES = {
61
62
'--openssl' => {
62
63
help : 'include only openssl tests' ,
63
- include : openssl = Dir [ " #{ TRUFFLERUBY_DIR } /test/mri/tests/ openssl/test_*.rb"] . sort ,
64
+ include : openssl = [ " openssl/test_*.rb"] ,
64
65
} ,
65
66
'--syslog' => {
66
67
help : 'include only syslog tests' ,
67
68
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"
70
71
]
71
72
} ,
72
73
'--cexts' => {
73
74
help : 'run all MRI tests testing C extensions' ,
74
75
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" ,
79
80
]
80
81
} ,
81
82
'--capi' => {
82
83
help : 'run all C-API MRI tests' ,
83
- include : MRI_TEST_CAPI_TESTS ,
84
+ include : capi = MRI_TEST_CAPI_TESTS ,
84
85
} ,
85
86
'--all-sulong' => {
86
87
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
88
89
} ,
89
90
'--no-sulong' => {
90
91
help : 'exclude all tests requiring Sulong' ,
@@ -985,7 +986,6 @@ def test_mri(*args)
985
986
end
986
987
987
988
mri_args = [ ]
988
- prefix = "#{ TRUFFLERUBY_DIR } /test/mri/tests/"
989
989
excluded_files = File . readlines ( "#{ TRUFFLERUBY_DIR } /test/mri/failing.exclude" ) .
990
990
map { |line | line . gsub ( /#.*/ , '' ) . strip } . reject ( &:empty? )
991
991
patterns = [ ]
@@ -1002,34 +1002,39 @@ def test_mri(*args)
1002
1002
end
1003
1003
end
1004
1004
1005
- patterns . push "#{ TRUFFLERUBY_DIR } /test/mri/tests /**/test_*.rb" if patterns . empty?
1005
+ patterns . push "#{ MRI_TEST_PREFIX } /**/test_*.rb" if patterns . empty?
1006
1006
1007
1007
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 } "
1014
1012
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
1016
1018
1017
1019
run_mri_tests ( mri_args , files_to_run , runner_args , use_exec : true )
1018
1020
end
1019
1021
private :test_mri
1020
1022
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
+
1021
1036
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 ) }
1033
1038
1034
1039
truffle_args = [ ]
1035
1040
if !extra_args . include? ( '--native' )
@@ -1038,7 +1043,7 @@ def run_mri_tests(extra_args, test_files, runner_args, run_options)
1038
1043
1039
1044
env_vars = {
1040
1045
"EXCLUDES" => "test/mri/excludes" ,
1041
- "RUBYGEMS_TEST_PATH" => " #{ TRUFFLERUBY_DIR } /test/mri/tests" ,
1046
+ "RUBYGEMS_TEST_PATH" => MRI_TEST_PREFIX ,
1042
1047
"RUBYOPT" => [ *ENV [ 'RUBYOPT' ] , '--disable-gems' ] . join ( ' ' ) ,
1043
1048
"TRUFFLERUBY_RESILIENT_GEM_HOME" => nil ,
1044
1049
}
@@ -1054,7 +1059,7 @@ def run_mri_tests(extra_args, test_files, runner_args, run_options)
1054
1059
cext_tests . each do |test |
1055
1060
puts
1056
1061
puts test
1057
- test_path = "#{ TRUFFLERUBY_DIR } /test/mri/tests /#{ test } "
1062
+ test_path = "#{ MRI_TEST_PREFIX } /#{ test } "
1058
1063
match = File . read ( test_path ) . match ( /\b require ['"]c\/ (.*?)["']/ )
1059
1064
if match
1060
1065
cext_name = match [ 1 ]
0 commit comments