Skip to content

Commit

Permalink
Merge pull request #536 from ruby/use-test-unit
Browse files Browse the repository at this point in the history
Switch to use test-unit
  • Loading branch information
hsbt committed Jan 10, 2024
2 parents 1a8bee9 + 83ce43e commit 97fa3dc
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
ruby-version: '3.0'
- name: Install dependencies
run: gem install minitest -v "5.15.0"
run: gem install test-unit coveralls
- name: Run test
env:
COVERALLS: "yes"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -32,6 +32,6 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: gem install minitest -v "5.15.0"
run: gem install test-unit
- name: Run test
run: ruby -Ilib exe/rake
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -3,7 +3,7 @@ source "https://rubygems.org"
gemspec

group :development do
gem "minitest"
gem "test-unit"
gem "coveralls"
gem "rubocop"
end
5 changes: 2 additions & 3 deletions test/helper.rb
Expand Up @@ -10,16 +10,15 @@
rescue Gem::LoadError
end

gem "minitest", "~> 5"
require "minitest/autorun"
require "test/unit"
require "rake"
require "tmpdir"

require_relative "support/file_creation"
require_relative "support/ruby_runner"
require_relative "support/rakefile_definitions"

class Rake::TestCase < Minitest::Test
class Rake::TestCase < Test::Unit::TestCase
include FileCreation

include Rake::DSL
Expand Down
60 changes: 30 additions & 30 deletions test/test_rake_application.rb
Expand Up @@ -48,7 +48,7 @@ def test_display_exception_details
rescue => ex
end

out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

@app.display_error_message ex
Expand All @@ -72,7 +72,7 @@ def detailed_message(**)
rescue error_class => ex
end

out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

@app.display_error_message ex
Expand All @@ -91,7 +91,7 @@ def test_display_exception_details_bad_encoding
rescue => ex
end

out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

@app.display_error_message ex
Expand All @@ -111,7 +111,7 @@ def test_display_exception_details_cause
end
end

out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

@app.display_error_message ex
Expand All @@ -129,7 +129,7 @@ def test_display_tasks
@app.options.show_task_pattern = //
@app.last_description = "COMMENT"
@app.define_task(Rake::Task, "t")
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t/, out)
assert_match(/# COMMENT/, out)
end
Expand All @@ -142,7 +142,7 @@ def test_display_tasks_with_long_comments
@app.last_description = numbers
@app.define_task(Rake::Task, "t")

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end

assert_match(/^rake t/, out)
assert_match(/# #{numbers[0, 65]}\.\.\./, out)
Expand All @@ -156,7 +156,7 @@ def test_display_tasks_with_task_name_wider_than_tty_display
@app.last_description = "something short"
@app.define_task(Rake::Task, task_name)

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end

# Ensure the entire task name is output and we end up showing no description
assert_match(/rake #{task_name} # .../, out)
Expand All @@ -171,7 +171,7 @@ def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comm
@app.last_description = "something short"
@app.define_task(Rake::Task, task_name)

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end

# Ensure the entire task name is output and we end up showing no description
assert_match(/rake #{task_name} # #{description}/, out)
Expand All @@ -183,7 +183,7 @@ def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
@app.tty_output = false
@app.last_description = "1234567890" * 8
@app.define_task(Rake::Task, "t")
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t/, out)
assert_match(/# #{@app.last_description}/, out)
end
Expand All @@ -197,7 +197,7 @@ def test_truncating_comments_to_a_non_tty
@app.last_description = numbers
@app.define_task(Rake::Task, "t")

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end

assert_match(/^rake t/, out)
assert_match(/# #{numbers[0, 65]}\.\.\./, out)
Expand All @@ -208,7 +208,7 @@ def test_describe_tasks
@app.options.show_task_pattern = //
@app.last_description = "COMMENT"
@app.define_task(Rake::Task, "t")
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t$/, out)
assert_match(/^ {4}COMMENT$/, out)
end
Expand All @@ -219,7 +219,7 @@ def test_show_lines
@app.last_description = "COMMENT"
@app.define_task(Rake::Task, "t")
@app["t"].locations << "HERE:1"
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t +[^:]+:\d+ *$/, out)
end

Expand Down Expand Up @@ -251,7 +251,7 @@ def test_load_rakefile
def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
rakefile_unittest

_, err = capture_io do
_, err = capture_output do
@app.instance_eval do
# pretend we started from the unittest dir
@original_dir = File.expand_path(".")
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_load_rakefile_prints_rakefile_directory_from_subdir
app = Rake::Application.new
app.options.rakelib = []

_, err = capture_io do
_, err = capture_output do
app.instance_eval do
raw_load_rakefile
end
Expand All @@ -296,7 +296,7 @@ def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
rakefile_unittest
Dir.chdir "subdir"

_, err = capture_io do
_, err = capture_output do
@app.instance_eval do
handle_options []
options.silent = true
Expand All @@ -308,7 +308,7 @@ def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
end

def test_load_rakefile_not_found
skip if jruby9?
omit if jruby9?

Dir.chdir @tempdir
ENV["RAKE_SYSTEM"] = "not_exist"
Expand Down Expand Up @@ -455,7 +455,7 @@ def test_good_run

rakefile_default

out, err = capture_io do
out, err = capture_output do
@app.run %w[--rakelib=""]
end

Expand All @@ -468,7 +468,7 @@ def test_display_task_run
ran = false
@app.last_description = "COMMENT"
@app.define_task(Rake::Task, "default")
out, = capture_io { @app.run %w[-f -s --tasks --rakelib=""] }
out, = capture_output { @app.run %w[-f -s --tasks --rakelib=""] }
assert @app.options.show_tasks
assert ! ran
assert_match(/rake default/, out)
Expand All @@ -482,7 +482,7 @@ def test_display_prereqs
t.enhance([:a, :b])
@app.define_task(Rake::Task, "a")
@app.define_task(Rake::Task, "b")
out, = capture_io { @app.run %w[-f -s --prereqs --rakelib=""] }
out, = capture_output { @app.run %w[-f -s --prereqs --rakelib=""] }
assert @app.options.show_prereqs
assert ! ran
assert_match(/rake a$/, out)
Expand All @@ -492,15 +492,15 @@ def test_display_prereqs

def test_bad_run
@app.intern(Rake::Task, "default").enhance { fail }
_, err = capture_io {
_, err = capture_output {
assert_raises(SystemExit) { @app.run %w[-f -s --rakelib=""] }
}
assert_match(/see full trace/i, err)
end

def test_bad_run_with_trace
@app.intern(Rake::Task, "default").enhance { fail }
_, err = capture_io {
_, err = capture_output {
@app.set_default_options
assert_raises(SystemExit) { @app.run %w[-f -s -t] }
}
Expand All @@ -509,7 +509,7 @@ def test_bad_run_with_trace

def test_bad_run_with_backtrace
@app.intern(Rake::Task, "default").enhance { fail }
_, err = capture_io {
_, err = capture_output {
assert_raises(SystemExit) {
@app.run %w[-f -s --backtrace]
}
Expand All @@ -523,7 +523,7 @@ def test_bad_run_includes_exception_name
@app.intern(Rake::Task, "default").enhance {
raise CustomError, "intentional"
}
_, err = capture_io {
_, err = capture_output {
assert_raises(SystemExit) {
@app.run %w[-f -s]
}
Expand All @@ -535,7 +535,7 @@ def test_rake_error_excludes_exception_name
@app.intern(Rake::Task, "default").enhance {
fail "intentional"
}
_, err = capture_io {
_, err = capture_output {
assert_raises(SystemExit) {
@app.run %w[-f -s]
}
Expand All @@ -558,7 +558,7 @@ def test_printing_original_exception_cause
raise custom_error, "Secondary Error"
end
}
_ ,err = capture_io {
_ ,err = capture_output {
assert_raises(SystemExit) {
@app.run %w[-f -s]
}
Expand All @@ -572,12 +572,12 @@ def test_printing_original_exception_cause
def test_run_with_bad_options
@app.intern(Rake::Task, "default").enhance { fail }
assert_raises(SystemExit) {
capture_io { @app.run %w[-f -s --xyzzy] }
capture_output { @app.run %w[-f -s --xyzzy] }
}
end

def test_standard_exception_handling_invalid_option
out, err = capture_io do
out, err = capture_output do
e = assert_raises SystemExit do
@app.standard_exception_handling do
raise OptionParser::InvalidOption, "blah"
Expand All @@ -592,7 +592,7 @@ def test_standard_exception_handling_invalid_option
end

def test_standard_exception_handling_other
out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

e = assert_raises SystemExit do
Expand All @@ -610,7 +610,7 @@ def test_standard_exception_handling_other
end

def test_standard_exception_handling_system_exit
out, err = capture_io do
out, err = capture_output do
e = assert_raises SystemExit do
@app.standard_exception_handling do
exit 0
Expand All @@ -625,7 +625,7 @@ def test_standard_exception_handling_system_exit
end

def test_standard_exception_handling_system_exit_nonzero
out, err = capture_io do
out, err = capture_output do
e = assert_raises SystemExit do
@app.standard_exception_handling do
exit 5
Expand Down
12 changes: 6 additions & 6 deletions test/test_rake_application_options.rb
Expand Up @@ -107,7 +107,7 @@ def test_execute_and_continue

def test_execute_and_print
$xyzzy = 0
out, = capture_io do
out, = capture_output do
flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do
assert_equal "pugh", $xyzzy
assert_equal :exit, @exit
Expand All @@ -119,7 +119,7 @@ def test_execute_and_print
end

def test_help
out, = capture_io do
out, = capture_output do
flags "--help", "-H", "-h"
end

Expand Down Expand Up @@ -200,7 +200,7 @@ def test_require
end

def test_missing_require
skip if jruby?
omit if jruby?

ex = assert_raises(LoadError) do
flags(["--require", "test/missing"]) do |opts|
Expand Down Expand Up @@ -386,7 +386,7 @@ def test_no_deprecated_messages
end

def test_verbose
capture_io do
capture_output do
flags("--verbose", "-v") do |opts|
assert Rake::FileUtilsExt.verbose_flag, "verbose should be true"
assert ! opts.silent, "opts should not be silent"
Expand All @@ -395,7 +395,7 @@ def test_verbose
end

def test_version
out, _ = capture_io do
out, _ = capture_output do
flags "--version", "-V"
end

Expand All @@ -405,7 +405,7 @@ def test_version
end

def test_bad_option
_, err = capture_io do
_, err = capture_output do
ex = assert_raises(OptionParser::InvalidOption) do
flags("--bad-option")
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_rake_backtrace.rb
Expand Up @@ -40,7 +40,7 @@ class TestRakeBacktrace < Rake::TestCase # :nodoc:
def setup
super

skip "tmpdir is suppressed in backtrace" if
omit "tmpdir is suppressed in backtrace" if
Rake::Backtrace::SUPPRESS_PATTERN =~ Dir.pwd
end

Expand Down

0 comments on commit 97fa3dc

Please sign in to comment.