From 704d7a4810d6a40fe99d1373e1dd9cae17d08f08 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Tue, 17 Sep 2024 11:07:38 +0200 Subject: [PATCH] Scrub invalid characters from shell outputs before regexp match This avoids hidden error messages due to encoding error. --- test/test_gem_install.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/test_gem_install.rb b/test/test_gem_install.rb index 0f2e1cbab..141a67dfa 100644 --- a/test/test_gem_install.rb +++ b/test/test_gem_install.rb @@ -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") @@ -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:(.*)====/ @@ -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 @@ -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