This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Encode: sync with CPAN version 3.18
[perl5.git] / cpan / Encode / t / Unicode_trailing_nul.t
1 BEGIN {
2     if ( $] < 5.009 ) {
3         print "1..0 # Skip: Perl <= 5.9 or later required\n";
4         exit 0;
5     }
6 }
7 use strict;
8 use Test::More;
9
10 use Encode;
11 use File::Temp;
12 use File::Spec;
13
14 # This test relies on https://github.com/Perl/perl5/issues/10623;
15 # if that bug is ever fixed then this test may never fail again.
16
17 my $foo = Encode::decode("UTF-16LE", "/\0v\0a\0r\0/\0f\0f\0f\0f\0f\0f\0/\0u\0s\0e\0r\0s\0/\0s\0u\0p\0e\0r\0m\0a\0n\0");
18
19 my ($fh, $path) = File::Temp::tempfile( CLEANUP => 1 );
20
21 note "temp file: $path";
22
23 # Perl gives the internal PV to exec .. which is buggy/wrong but
24 # useful here:
25 system( $^X, '-e', "open my \$fh, '>>', '$path' or die \$!; print {\$fh} \$ARGV[0]", $foo );
26 die if $?;
27
28 my $output = do { local $/; <$fh> };
29
30 is( $output, "/var/ffffff/users/superman", 'UTF-16 decodes with trailing NUL' );
31
32 done_testing();