Skip to content

Commit

Permalink
t/op/magic.t - Issue #19504 - fixup tests for utf8 $0
Browse files Browse the repository at this point in the history
Since PR #19334 was merged the tests for it are failing. This should fix
them. I am taking the perspective based on the broken previous tests
that that on some systems /proc/$$/commandline returns a trailing null.
This fixes the code to read /proc/$$/comandline to chop the null off if
it is there so the tests can be agnostic to that.

At the same time I have fixed the tests a bit to not use regexen where
they aren't needed and to avoid a test count issue in the skip logic,
and also to produce better errors if the code to read
/proc/$$/commandline fails.
  • Loading branch information
demerphq committed Mar 7, 2022
1 parent 8b03aeb commit ebd227f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions t/op/magic.t
Expand Up @@ -465,16 +465,22 @@ EOP
is ($0, $char_with_plain_pv, 'compare $0 to non-UTF8-flagged');

my $linux_cmdline_cr = sub {
open my $rfh, '<', "/proc/$$/cmdline" or skip "open: $!", 1;
return do { local $/; <$rfh> };
my $skip = shift // 1;
open my $rfh, '<', "/proc/$$/cmdline"
or skip "failed to read '/proc/$$/cmdline': $!", $skip;
my $got = do { local $/; <$rfh> };
$got=~s/\0\z//;
return $got;
};

SKIP: {
skip "Test is for Linux, not $^O", 2 if $^O ne 'linux';

my $slurp = $linux_cmdline_cr->();
like( $slurp, qr<\A$char_with_utf8_pv\0>, '/proc cmdline shows as expected (compare to UTF8-flagged)' );
like( $slurp, qr<\A$char_with_plain_pv\0>, '/proc cmdline shows as expected (compare to non-UTF8-flagged)' );
my $skip_tests = 2;
skip "Test is for Linux, not $^O", $skip_tests if $^O ne 'linux';
my $slurp = $linux_cmdline_cr->($skip_tests);
is( $slurp, $char_with_utf8_pv,
'/proc cmdline shows as expected (compare to UTF8-flagged)' );
is( $slurp, $char_with_plain_pv,
'/proc cmdline shows as expected (compare to non-UTF8-flagged)' );
}

my $name_unicode = "haha\x{100}hoho";
Expand All @@ -493,8 +499,9 @@ EOP
is( $0, $name_utf8_bytes, '.. and the UTF-8 version is written' );

SKIP: {
my $skip_tests = 1;
skip "Test is for Linux, not $^O" if $^O ne 'linux';
is( $linux_cmdline_cr->(), "$name_utf8_bytes\0", '.. and /proc cmdline shows that');
is( $linux_cmdline_cr->($skip_tests), $name_utf8_bytes, '.. and /proc cmdline shows that');
}

@warnings = ();
Expand Down

0 comments on commit ebd227f

Please sign in to comment.