File: 6-write-read-crlf.t

package info (click to toggle)
libtest-reporter-perl 1.62-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 248 kB
  • sloc: perl: 1,045; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,557 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl -w

use strict;
use FileHandle;
use Test::More 0.88;
use Test::Reporter;
use Data::Dumper;

$Test::Reporter::VERSION ||= 999; # dzil will set it for us on release

plan tests => 14;

my $CR   = "\015";
my $LF   = "\012";

my $distro = "Foo-Bar-1.23";
my $distfile = "AUTHOR/" . $distro . ".tar.gz";

my $reporter = Test::Reporter->new
(
    grade => 'pass',
    distribution => $distro,
    distfile => $distfile,
    from => 'johndoe@example.net',
);
isa_ok($reporter, 'Test::Reporter');
my $file = $reporter->write();
like($file, "/$distro/");
ok(-e $file);
my $orig_subject = $reporter->subject;
my $orig_from = $reporter->from;
my $orig_report = $reporter->report;

undef $reporter;

# convert line endings
open my $in_fh, "<", $file;
my $slurp = do { local $/; <$in_fh> };
close $in_fh;

$slurp =~ s{$CR?$LF}{$CR$LF}g;

open my $out_fh, ">", $file;
binmode $out_fh;
print {$out_fh} $slurp;
close $out_fh;


# read in

$reporter = Test::Reporter->new
(
)->read($file);
isa_ok($reporter, 'Test::Reporter');
like($reporter->subject,"/^PASS $distro\\s/");
like($reporter->report, '/This distribution has been tested/');
like($reporter->report,'/Summary of my/');
is($reporter->grade, 'pass');
is($reporter->distribution, $distro);
is($reporter->distfile, $distfile);
like($reporter->perl_version->{_myconfig}, '/Summary of my/', "Regenerated _myconfig");

# confirm roundtrip -- particularly newlines
is($reporter->subject, $orig_subject);
is($reporter->from, $orig_from);
is($reporter->report, $orig_report);

unlink $file;

done_testing;