Repository navigation
Expand file tree
/
Copy pathRakefile
More file actions
108 lines (93 loc) · 3.77 KB
/
Copy pathRakefile
File metadata and controls
108 lines (93 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rake/extensiontask'
require 'rake/testtask'
Rake::ExtensionTask.new('ox') do |ext|
ext.lib_dir = 'lib/ox'
end
# Ractors leave the process in multi-Ractor mode, where old Rubies can hang
# later, for example Ruby 3.1 on the first use of UTF-16 (Ruby bug #19562).
# So test_all runs these in their own processes too.
RACTOR_TESTS = %w[test/load_ractor_test.rb test/sax/ractor_test.rb].freeze
# test_all invokes this. Without it Rake::Task['test'] silently resolved to a
# synthesized file task for the test/ directory, so everything below never ran.
#
# tests.rb and sax/sax_test.rb are excluded because test_all runs them
# separately through run(), which adds the ASAN preload when OX_ASAN is set.
# cache_test.rb / cache8_test.rb call Ox.cache_test / Ox.cache8_test, C
# self-tests only compiled into a debug build, and smart_test.rb runs
# opts.parse(ARGV) at load and exits on the test runner's -v flag.
Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/**/*_test.rb']
.exclude('test/cache_test.rb',
'test/cache8_test.rb',
'test/sax/smart_test.rb',
'test/sax/sax_test.rb',
*RACTOR_TESTS)
t.verbose = true
end
if RUBY_PLATFORM.include?('linux')
begin
require 'ruby_memcheck'
RubyMemcheck.config(
binary_name: 'ox',
# Valgrind and YJIT interfere with each other, adding noise and slowdown,
# so keep YJIT disabled while running under Valgrind.
ruby: "#{FileUtils::RUBY} --disable-yjit"
)
# Every *_test.rb in test/, plus tests.rb (which does not match that glob).
# Excluded: cache_test.rb / cache8_test.rb call Ox.cache_test / Ox.cache8_test,
# C self-tests only compiled into a debug build; smart_test.rb runs
# opts.parse(ARGV) at load and exits on the test runner's -v flag. The two
# fork-based tests in tests.rb are skipped under Valgrind via OX_SKIP_FORK_TESTS
# (a forked child stays under Valgrind and only adds noise).
memcheck_test_files =
FileList['test/**/*_test.rb']
.exclude('test/cache_test.rb', 'test/cache8_test.rb', 'test/sax/smart_test.rb') + ['test/tests.rb']
namespace :test do
desc 'Fail early with a clear message when Valgrind is not installed'
task :check_valgrind do
unless system('command -v valgrind > /dev/null 2>&1')
abort("\nValgrind is required for `rake test:valgrind` but was not found.\n" \
"Install it first (Linux only), e.g. `sudo apt-get install valgrind`.\n")
end
# Inherited by the Ruby child that Valgrind traces; see the note above.
ENV['OX_SKIP_FORK_TESTS'] = '1'
end
RubyMemcheck::TestTask.new(valgrind: [:check_valgrind, :compile]) do |t|
t.test_files = memcheck_test_files
t.verbose = true
end
end
rescue LoadError
# ruby_memcheck is an optional, Linux-only development dependency. If it is
# not installed just skip defining the task instead of breaking the Rakefile.
end
end
def run(command)
if ENV['OX_ASAN']
@ld_preload ||= `gcc -print-file-name=libasan.so`.strip
command = "LD_PRELOAD=#{@ld_preload} ASAN_OPTIONS=detect_leaks=0 #{command}"
end
system command
end
task test_all: [:clean, :compile] do
$stdout.flush
exitcode = 0
status = true
(%w[test/tests.rb test/sax/sax_test.rb] + RACTOR_TESTS).each do |test|
cmds = "bundle exec ruby #{test} -v"
$stdout.syswrite "\n#{'#' * 90}\n#{cmds}\n"
Bundler.with_original_env do
status = status && run(cmds)
end
end
exitcode = 1 unless status
unless ENV['OX_ASAN']
Rake::Task['test'].invoke
else
run('rake test')
end
exit(1) if exitcode == 1
end
task default: :test_all