Skip to content

Commit a71f7d8

Browse files
authored
Merge pull request #1 from ruby/test-unit
Use test-unit
2 parents 1744e33 + 7858486 commit a71f7d8

File tree

13 files changed

+52
-4195
lines changed

13 files changed

+52
-4195
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
/pkg/
77
/spec/reports/
88
/tmp/
9+
Gemfile.lock
10+
*.bundle
11+
*.so

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ gemspec
44

55
gem "rake"
66
gem "rake-compiler"
7+
gem "test-unit"

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ require "rake/testtask"
33

44
Rake::TestTask.new(:test) do |t|
55
t.libs << "test/lib"
6+
t.ruby_opts << "-rhelper"
67
t.test_files = FileList["test/**/test_*.rb"]
78
end
89

10+
task :sync_tool do
11+
require 'fileutils'
12+
FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
13+
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
14+
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
15+
end
16+
917
require 'rake/extensiontask'
1018
Rake::ExtensionTask.new("pathname")
1119

test/lib/core_assertions.rb

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def syntax_check(code, fname, line)
115115

116116
def assert_no_memory_leak(args, prepare, code, message=nil, limit: 2.0, rss: false, **opt)
117117
# TODO: consider choosing some appropriate limit for MJIT and stop skipping this once it does not randomly fail
118-
pend 'assert_no_memory_leak may consider MJIT memory usage as leak' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
118+
pend 'assert_no_memory_leak may consider MJIT memory usage as leak' if defined?(RubyVM::JIT) && RubyVM::JIT.enabled?
119119

120120
require_relative '../../memory_status'
121121
raise MiniTest::Skip, "unsupported platform" unless defined?(Memory::Status)
@@ -264,7 +264,7 @@ def separated_runner(out = nil)
264264
at_exit {
265265
out.puts [Marshal.dump($!)].pack('m'), "assertions=\#{self._assertions}"
266266
}
267-
Test::Unit::Runner.class_variable_set(:@@stop_auto_run, true)
267+
Test::Unit::Runner.class_variable_set(:@@stop_auto_run, true) if defined?(Test::Unit::Runner)
268268
end
269269

270270
def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **opt)
@@ -276,7 +276,7 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o
276276
capture_stdout = true
277277
unless /mswin|mingw/ =~ RUBY_PLATFORM
278278
capture_stdout = false
279-
opt[:out] = MiniTest::Unit.output
279+
opt[:out] = MiniTest::Unit.output if defined?(MiniTest::Unit)
280280
res_p, res_c = IO.pipe
281281
opt[res_c.fileno] = res_c.fileno
282282
end
@@ -330,6 +330,27 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o
330330
raise marshal_error if marshal_error
331331
end
332332

333+
# Run Ractor-related test without influencing the main test suite
334+
def assert_ractor(src, args: [], require: nil, require_relative: nil, file: nil, line: nil, ignore_stderr: nil, **opt)
335+
return unless defined?(Ractor)
336+
337+
require = "require #{require.inspect}" if require
338+
if require_relative
339+
dir = File.dirname(caller_locations[0,1][0].absolute_path)
340+
full_path = File.expand_path(require_relative, dir)
341+
require = "#{require}; require #{full_path.inspect}"
342+
end
343+
344+
assert_separately(args, file, line, <<~RUBY, ignore_stderr: ignore_stderr, **opt)
345+
#{require}
346+
previous_verbose = $VERBOSE
347+
$VERBOSE = nil
348+
Ractor.new {} # trigger initial warning
349+
$VERBOSE = previous_verbose
350+
#{src}
351+
RUBY
352+
end
353+
333354
# :call-seq:
334355
# assert_throw( tag, failure_message = nil, &block )
335356
#
@@ -587,6 +608,20 @@ def assert_warn(*args)
587608
assert_warning(*args) {$VERBOSE = false; yield}
588609
end
589610

611+
def assert_deprecated_warning(mesg = /deprecated/)
612+
assert_warning(mesg) do
613+
Warning[:deprecated] = true
614+
yield
615+
end
616+
end
617+
618+
def assert_deprecated_warn(mesg = /deprecated/)
619+
assert_warn(mesg) do
620+
Warning[:deprecated] = true
621+
yield
622+
end
623+
end
624+
590625
class << (AssertFile = Struct.new(:failure_message).new)
591626
include CoreAssertions
592627
def assert_file_predicate(predicate, *args)

test/lib/leakchecker.rb

Lines changed: 0 additions & 203 deletions
This file was deleted.

test/lib/minitest/autorun.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)