Skip to content

Commit

Permalink
test_child_process: Replace some UTF-8 byte sequences with named vari…
Browse files Browse the repository at this point in the history
…ables

Make easy to understand what these tests do.

Signed-off-by: Takuro Ashie <[email protected]>
  • Loading branch information
ashie committed Jan 10, 2024
1 parent 93b8e18 commit ec90c2e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions test/plugin_helper/test_child_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,9 @@ def configure(conf)
sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran
m.lock
assert_equal Encoding.find('utf-8'), str.encoding
expected = "\xEF\xBF\xBD\xEF\xBF\xBD\x00\xEF\xBF\xBD\xEF\xBF\xBD".force_encoding("utf-8")
replacement = "\uFFFD" # U+FFFD (REPLACEMENT CHARATER)
nul = "\x00" # U+0000 (NUL)
expected = replacement * 2 + nul + replacement * 2
assert_equal expected, str
@d.stop; @d.shutdown; @d.close; @d.terminate
end
Expand All @@ -538,10 +540,11 @@ def configure(conf)
test 'can scrub characters without exceptions and replace specified chars' do
m = Mutex.new
str = nil
replacement = "?"
Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
ran = false
args = ['-e', 'STDOUT.set_encoding("ascii-8bit"); STDOUT.write "\xFF\xFF\x00\xF0\xF0"']
@d.child_process_execute(:t13b, "ruby", arguments: args, mode: [:read], scrub: true, replace_string: '?') do |io|
@d.child_process_execute(:t13b, "ruby", arguments: args, mode: [:read], scrub: true, replace_string: replacement) do |io|
m.lock
ran = true
str = io.read
Expand All @@ -550,7 +553,8 @@ def configure(conf)
sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran
m.lock
assert_equal Encoding.find('utf-8'), str.encoding
expected = "??\x00??".force_encoding("utf-8")
nul = "\x00" # U+0000 (NUL)
expected = replacement * 2 + nul + replacement * 2
assert_equal expected, str
@d.stop; @d.shutdown; @d.close; @d.terminate
end
Expand Down

0 comments on commit ec90c2e

Please sign in to comment.