File Coverage: t/parse-comments-and-blank-lines.t

# File Coverage

File: | t/parse-comments-and-blank-lines.t
Coverage: | 96.4%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 |  |  |  |  |  |  | #!/usr/bin/perl -wl
2 |
3 | 1 1 1 |  |  | 1 |  | 5216 47187 61 | use Test::More;
4 | 1 1 1 |  |  | 1 |  | 2308 30764 254 | use Test::Differences;
5 | 1 1 1 |  |  | 1 |  | 15 5 171 | use File::Path qw(mkpath rmtree);
6 | 1 1 1 |  |  | 1 |  | 1023 40424 205 | use File::Slurp;
7 | 1 1 1 |  |  | 1 |  | 730 2879 161 | use File::Which;
8 | 1 1 1 |  |  | 1 |  | 1122 18792 518197 | use Data::Dumper;
9 |
10 | 1 |  |  |  |  | 8 | my $BASE = 't/parse-comments-and-blank-lines';
11 | 1 |  |  |  |  | 9 | my $HOME = "$BASE/1";
12 | 1 |  |  |  |  | 7 | my $TARGET = "$BASE/2";
13 | 1 |  |  |  |  | 6 | my $PREFIX = "u";
14 |
15 |  |  |  |  |  |  | # Set a debug environment
16 | 1 |  |  |  |  | 15 | $ENV{HOME} = $HOME;
17 |
18 |  |  |  |  |  |  | # Clean up possible remainders of aborted tests
19 | 1 |  |  |  |  | 339 | rmtree("$BASE");
20 |
21 | 1 |  |  |  |  | 1578 | ok( mkpath("$HOME/.foobar/fnord/bla", "$TARGET", {}), "Create test environment (directories)" );
22 | 1 |  |  |  |  | 1210 | ok( -d "$HOME/.foobar/fnord/bla", "Original directory has been created" );
23 | 1 |  |  |  |  | 1810 | ok( -d "$TARGET", "Target directory has been created" );
24 |
25 | 1 |  |  |  |  | 1452 | ok( symlink("$HOME/.foobar/fnord", "$HOME/.fnord"), "Create test environment (Symlink 1)" );
26 | 1 |  |  |  |  | 1197 | ok( -l "$HOME/.fnord", "Symlink 1 has been created" );
27 | 1 |  |  |  |  | 1487 | ok( symlink("fnord", "$HOME/.foobar/blafasel"), "Create test environment (Symlink 2)" );
28 | 1 |  |  |  |  | 1189 | ok( -l "$HOME/.foobar/blafasel", "Symlink 2 has been created" );
29 |
30 | 1 |  |  |  |  | 1186 | ok( write_file("$BASE/list", "m d .foobar/fnord/bla foobar-fnord-bla\n# Comment\n\n \n \nm d .fnord/bla fnord-bla\nm d .foobar/blafasel/bla foobar-blafasel-bla\n") );
31 | 1 |  |  |  |  | 1925 | ok( write_file("$BASE/config", "TARGETDIR=$TARGET\nFILELAYOUT=$PREFIX-\%s") );
32 |
33 | 1 |  |  |  |  | 1681 | my $cmd = "bin/unburden-home-dir -C $BASE/config -L $BASE/list > $BASE/output 2> $BASE/stderr";
34 | 1 |  |  |  |  | 3092054 | ok( system($cmd) == 0, "Call '$cmd'" );
35 |
36 | 1 |  |  |  |  | 1982 | my $wanted = "Skipping '$HOME/.fnord/bla' due to symlink in path: $HOME/.fnord
37 |  |  |  |  |  |  | Skipping '$HOME/.foobar/blafasel/bla' due to symlink in path: $HOME/.foobar/blafasel
38 |  |  |  |  |  |  | ";
39 | 1 | 50 |  |  |  | 73 | unless (which('lsof')) {
40 | 0 |  |  |  |  | 0 | $wanted = "WARNING: lsof not found, not checking for files in use.\n".$wanted;
41 |  |  |  |  |  |  | }
42 |
43 | 1 |  |  |  |  | 1550 | my $stderr = read_file("$BASE/stderr");
44 | 1 |  |  |  |  | 420 | eq_or_diff_text( $stderr, $wanted, "Check command STDERR output" );
45 |
46 | 1 |  |  |  |  | 3560 | $wanted = "Moving $HOME/.foobar/fnord/bla -> $TARGET/u-foobar-fnord-bla
47 |  |  |  |  |  |  | sending incremental file list
48 |  |  |  |  |  |  | created directory $TARGET/u-foobar-fnord-bla
49 |  |  |  |  |  |  | ./
50 |  |  |  |  |  |  | Symlinking $TARGET/u-foobar-fnord-bla -> $HOME/.foobar/fnord/bla
51 |  |  |  |  |  |  | ";
52 |
53 | 1 |  |  |  |  | 67 | my $output = read_file("$BASE/output");
54 | 1 |  |  |  |  | 387 | eq_or_diff_text( $output, $wanted, "Check command STDOUT" );
55 |
56 | 1 |  |  |  |  | 3037 | ok( -d "$TARGET/$PREFIX-foobar-fnord-bla", "First directory moved" );
57 | 1 |  |  |  |  | 1611 | ok( ! -e "$TARGET/$PREFIX-fnord-bla", "Symlink 1 not moved" );
58 | 1 |  |  |  |  | 3278 | ok( ! -e "$TARGET/$PREFIX-foobar-blafasel-bla", "Symlink 2 not moved" );
59 |
60 | 1 |  |  |  |  | 11573 | ok( rmtree("$BASE"), "Clean up" );
61 |
62 | 1 |  |  |  |  | 1617 | done_testing();