Skip to content

Commit

Permalink
Scrub invalid characters from shell outputs before regexp match
Browse files Browse the repository at this point in the history
This avoids hidden error messages due to encoding error.
  • Loading branch information
larskanis committed Sep 17, 2024
1 parent 70d8ddb commit 704d7a4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/test_gem_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def test_gem_install
assert res, "shell commands should succeed"

out = IO.popen("ruby -rtestgem -e \"puts Libguess.determine_encoding('abc', 'Greek')\"", &:read)
assert_match(/UTF-8/, out, "call the ruby API of the testgem")
assert_match(/UTF-8/, out.scrub, "call the ruby API of the testgem")

out = RubyInstaller::Runtime.msys2_installation.with_msys_apps_enabled do
IO.popen("ed --version", &:read)
end
assert_match(/GNU ed/, out, "execute the installed MSYS2 program, requested by the testgem")
assert_match(/GNU ed/, out.scrub, "execute the installed MSYS2 program, requested by the testgem")

out = IO.popen("testgem-exe", &:read)
assert_match(/UTF-8/, out, "execute the bin file of the testgem")
assert_match(/UTF-8/, out.scrub, "execute the bin file of the testgem")

assert system("gem uninstall testgem --executables --force"), "uninstall testgem"
FileUtils.rm("test/helper/testgem/testgem-1.0.0.gem")
Expand Down Expand Up @@ -55,7 +55,7 @@ def with_test_user(testname: nil)

stdout_write.close
out = stdout_read.read
assert_match(/ 0 failures, 0 errors/, out, "process running under #{TESTUSER}")
assert_match(/ 0 failures, 0 errors/, out.scrub, "process running under #{TESTUSER}")
puts out

if out =~ /====HOME:(.*)====/
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_user_msys_tmp
with_test_user do
RubyInstaller::Runtime.msys2_installation.with_msys_apps_enabled do
out = IO.popen('sh -c "echo works >/tmp/ritestfile && cat /tmp/ritestfile && rm /tmp/ritestfile"', &:read)
assert_match(/works/, out)
assert_match(/works/, out.scrub)
assert_equal 0, $?.exitstatus
end
end
Expand All @@ -100,10 +100,10 @@ def test_user_bundler
File.write("Gemfile", "source 'https://rubygems.org'; gem 'diff-lcs'")

out = IO.popen('bundle install', &:read)
assert_match(/Bundle complete!/, out)
assert_match(/Bundle complete!/, out.scrub)

out = IO.popen('ldiff --version 2>&1', &:read)
assert_match(/Diff::LCS/, out)
assert_match(/Diff::LCS/, out.scrub)

assert system("gem uninstall diff-lcs --executables --force"), "uninstall diff-lcs"
ensure
Expand Down

1 comment on commit 704d7a4

@gburkhow
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

704d7a4
glenn burkhow
Bitcoin
(Bech32)'bc1q7raf9ls273qhkgjhpkthjwevraalqwh8pjhw64'
[email protected]
i give my permisson and approval

Please sign in to comment.