Skip to content

Commit

Permalink
[rubygems/rubygems] Provide more insightful test error output
Browse files Browse the repository at this point in the history
Original output:

~~~
Failure: test_realworld_upgraded_default_gem(TestGemRequire): <false> is not true.
/mnt/test/rubygems/test_require.rb:474:in `test_realworld_upgraded_default_gem'
     471:     File.write(path, code)
     472:
     473:     output = Gem::Util.popen({ "GEM_HOME" => @gemhome }, *ruby_with_rubygems_in_load_path, path).strip
  => 474:     assert $?.success?
     475:     refute_empty output
     476:     assert_equal "999.99.9", output.lines[0].chomp
     477:     # Make sure only files from the newer json gem are loaded, and no files from the default json gem
~~~

New output:

~~~
Failure: test_realworld_upgraded_default_gem(TestGemRequire)
/mnt/test/rubygems/test_require.rb:475:in `test_realworld_upgraded_default_gem'
     472:
     473:     output = Gem::Util.popen({ "GEM_HOME" => @gemhome }, *ruby_with_rubygems_in_load_path, path).strip
     474:     refute_empty output
  => 475:     assert_equal "999.99.9", output.lines[0].chomp
     476:     # Make sure only files from the newer json gem are loaded, and no files from the default json gem
     477:     assert_equal ["#{@gemhome}/gems/json-999.99.9/lib/json.rb"], output.lines.grep(%r{/gems/json-}).map(&:chomp)
     478:     assert $?.success?
<"999.99.9"> expected but was
<"/mnt/tmp/test_rubygems_20231110-36663-of405r/test_realworld_upgraded_default_gem.rb:3:in `<main>': undefined method `version' for nil:NilClass (NoMethodError)">

diff:
? 999                                                                             .99.9
? /mnt/tmp/test_rubygems_20231110-36663-of405r/test_realworld_upgraded_default_gem rb:3:in `<main>': undefined method `version' for nil:NilClass (NoMethodError)
? ??? ????
~~~

It is more valuable to check the command output then the error code. If
the command fails for some reason, the output probably contains some
detail, while checking the return code tells not much.

rubygems/rubygems@b76062e852
  • Loading branch information
voxik authored and hsbt committed Nov 13, 2023
1 parent 6989664 commit 3053e89
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion test/rubygems/test_require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,11 @@ def test_realworld_upgraded_default_gem
File.write(path, code)

output = Gem::Util.popen({ "GEM_HOME" => @gemhome }, *ruby_with_rubygems_in_load_path, path).strip
assert $?.success?
refute_empty output
assert_equal "999.99.9", output.lines[0].chomp
# Make sure only files from the newer json gem are loaded, and no files from the default json gem
assert_equal ["#{@gemhome}/gems/json-999.99.9/lib/json.rb"], output.lines.grep(%r{/gems/json-}).map(&:chomp)
assert $?.success?
end

def test_default_gem_and_normal_gem
Expand Down

0 comments on commit 3053e89

Please sign in to comment.