File Coverage: t/check-symlinks-in-path.t

# File Coverage

File: | t/check-symlinks-in-path.t
Coverage: | 96.4%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 |  |  |  |  |  |  | #!/usr/bin/perl -wl
2 |
3 | 1 1 1 |  |  | 1 |  | 4716 45734 63 | use Test::More;
4 | 1 1 1 |  |  | 1 |  | 2279 33709 241 | use Test::Differences;
5 | 1 1 1 |  |  | 1 |  | 15 5 171 | use File::Path qw(mkpath rmtree);
6 | 1 1 1 |  |  | 1 |  | 946 52382 208 | use File::Slurp;
7 | 1 1 1 |  |  | 1 |  | 725 2927 162 | use File::Which;
8 | 1 1 1 |  |  | 1 |  | 1107 18731 510248 | use Data::Dumper;
9 |
10 | 1 |  |  |  |  | 14 | my $BASE = 't/check-symlinks-in-path';
11 | 1 |  |  |  |  | 14 | my $HOME = "$BASE/1";
12 | 1 |  |  |  |  | 11 | my $TARGET = "$BASE/2";
13 | 1 |  |  |  |  | 8 | my $PREFIX = "u";
14 |
15 |  |  |  |  |  |  | # Set a debug environment
16 | 1 |  |  |  |  | 25 | $ENV{HOME} = $HOME;
17 |
18 |  |  |  |  |  |  | # Clean up possible remainders of aborted tests
19 | 1 |  |  |  |  | 489 | rmtree("$BASE");
20 |
21 | 1 |  |  |  |  | 2532 | ok( mkpath("$HOME/.foobar/fnord/bla", "$TARGET", {}), "Create test environment (directories)" );
22 | 1 |  |  |  |  | 1642 | ok( -d "$HOME/.foobar/fnord/bla", "Original directory has been created" );
23 | 1 |  |  |  |  | 1803 | ok( -d "$TARGET", "Target directory has been created" );
24 |
25 | 1 |  |  |  |  | 1629 | ok( symlink("$HOME/.foobar/fnord", "$HOME/.fnord"), "Create test environment (Symlink 1)" );
26 | 1 |  |  |  |  | 1161 | ok( -l "$HOME/.fnord", "Symlink 1 has been created" );
27 | 1 |  |  |  |  | 1400 | ok( symlink("fnord", "$HOME/.foobar/blafasel"), "Create test environment (Symlink 2)" );
28 | 1 |  |  |  |  | 1342 | ok( -l "$HOME/.foobar/blafasel", "Symlink 2 has been created" );
29 |
30 | 1 |  |  |  |  | 1178 | ok( write_file("$BASE/list", "m d .foobar/fnord/bla foobar-fnord-bla\nm d .fnord/bla fnord-bla\nm d .foobar/blafasel/bla foobar-blafasel-bla\n") );
31 | 1 |  |  |  |  | 1754 | ok( write_file("$BASE/config", "TARGETDIR=$TARGET\nFILELAYOUT=$PREFIX-\%s") );
32 |
33 | 1 |  |  |  |  | 1751 | my $cmd = "bin/unburden-home-dir -C $BASE/config -L $BASE/list > $BASE/output 2> $BASE/stderr";
34 | 1 |  |  |  |  | 3301314 | ok( system($cmd) == 0, "Call '$cmd'" );
35 |
36 | 1 |  |  |  |  | 1278 | 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 |  |  |  | 80 | unless (which('lsof')) {
40 | 0 |  |  |  |  | 0 | $wanted = "WARNING: lsof not found, not checking for files in use.\n".$wanted;
41 |  |  |  |  |  |  | }
42 |
43 | 1 |  |  |  |  | 1729 | my $stderr = read_file("$BASE/stderr");
44 | 1 |  |  |  |  | 293 | eq_or_diff_text( $stderr, $wanted, "Check command STDERR output" );
45 |
46 | 1 |  |  |  |  | 1595 | $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 |  |  |  |  | 60 | my $output = read_file("$BASE/output");
54 | 1 |  |  |  |  | 320 | eq_or_diff_text( $output, $wanted, "Check command STDOUT" );
55 |
56 | 1 |  |  |  |  | 1629 | ok( -d "$TARGET/$PREFIX-foobar-fnord-bla", "First directory moved" );
57 | 1 |  |  |  |  | 1218 | ok( ! -e "$TARGET/$PREFIX-fnord-bla", "Symlink 1 not moved" );
58 | 1 |  |  |  |  | 1341 | ok( ! -e "$TARGET/$PREFIX-foobar-blafasel-bla", "Symlink 2 not moved" );
59 |
60 | 1 |  |  |  |  | 6187 | ok( rmtree("$BASE"), "Clean up" );
61 |
62 | 1 |  |  |  |  | 1079 | done_testing();