File: append-utf8.t

package info (click to toggle)
libmodule-faker-perl 0.027-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 340 kB
  • sloc: perl: 1,231; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,160 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use strict;
use warnings;
use Test::More 0.88;

# Archive::Any::Create 0.02 uses this
my $extractor = 'Archive::Tar';
eval "require $extractor"
  or plan skip_all => "$extractor required for this test";

use Cwd ();
use Encode qw( decode_utf8 encode_utf8 );
use Module::Faker::Dist;
use File::Temp ();
use Path::Class 0.06 qw( file );

my $MFD = 'Module::Faker::Dist';

my $tmpdir = File::Temp::tempdir(CLEANUP => 1);

my $dist = $MFD->from_file(file(qw(eg Append-UTF8.json))->stringify);

isa_ok($dist, $MFD);

my $archive = $dist->make_archive({ dir => $tmpdir });

{
  my $old_pwd = Cwd::getcwd();
  chdir $tmpdir or die "Failed to chdir to $tmpdir: $!";
  $extractor->extract_archive($archive)
    or die $extractor->error;
  chdir $old_pwd;
}

(my $dir = $archive) =~ s/\.(zip|tar\.(gz|bz2))$//;
my $file = file($dir, 'Changes');

ok( -e "$file", "file extracted" );

# on 5.14+ this will fail unless the file was passed through
# encode_utf8 before passing to Archive::Tar

like(
  # decode the slurped octects b/c we expect the file to be utf8
  decode_utf8(scalar $file->slurp),
  qr/codename 'M\x{fc}nchen'/,
  'file preserves utf8'
);

done_testing;