File Coverage: t/undo.t

# File Coverage

File: | t/undo.t
Coverage: | 96.3%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 |  |  |  |  |  |  | #!/usr/bin/perl -w
2 |
3 | 1 1 1 |  |  | 1 |  | 7990 66867 91 | use Test::More;
4 | 1 1 1 |  |  | 1 |  | 3448 44815 310 | use Test::Differences;
5 | 1 1 1 |  |  | 1 |  | 16 4 175 | use File::Path qw(mkpath rmtree);
6 | 1 1 1 |  |  | 1 |  | 992 43521 200 | use File::Slurp;
7 | 1 1 1 |  |  | 1 |  | 776 2849 164 | use File::Which;
8 | 1 1 1 |  |  | 1 |  | 1095 18973 626375 | use Data::Dumper;
9 |
10 | 1 |  |  |  |  | 9 | my $BASE = 't/undo';
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 |  |  |  |  | 14 | $ENV{HOME} = $HOME;
17 |
18 |  |  |  |  |  |  | # Clean up possible remainders of aborted tests
19 | 1 |  |  |  |  | 323 | rmtree("$BASE");
20 |
21 | 1 |  |  |  |  | 1362 | ok( mkpath("$HOME/.foobar/blatest", "$TARGET/$PREFIX-barba-blatest-foobar", {}), "Create test environment (directories)" );
22 | 1 |  |  |  |  | 1222 | ok( -d "$TARGET", "Target directory has been created" );
23 | 1 |  |  |  |  | 1773 | ok( symlink("$TARGET/$PREFIX-barba-blatest-foobar", "$HOME/.foobar/blatest/barba"), "Create test environment (symlink)" );
24 | 1 |  |  |  |  | 1214 | ok( -l "$HOME/.foobar/blatest/barba", "Symlink has been created" );
25 |
26 | 1 |  |  |  |  | 1176 | ok( write_file("$BASE/list", 'm d .foo*/bla*/bar* bar%3-bla%2-foo%1'), "Create list" );
27 | 1 |  |  |  |  | 1951 | ok( write_file("$BASE/config", "TARGETDIR=$TARGET\nFILELAYOUT=$PREFIX-\%s"), "Create config" );
28 |
29 | 1 |  |  |  |  | 1742 | my $cmd = "bin/unburden-home-dir -u -C $BASE/config -L $BASE/list > $BASE/output 2> $BASE/stderr";
30 | 1 |  |  |  |  | 2681183 | ok( system($cmd) == 0, "Call '$cmd'" );
31 |
32 | 1 |  |  |  |  | 1329 | my $wanted = "Trying to revert $TARGET/$PREFIX-barba-blatest-foobar to $HOME/.foobar/blatest/barba
33 |  |  |  |  |  |  | Removing symlink $HOME/.foobar/blatest/barba
34 |  |  |  |  |  |  | Moving $TARGET/$PREFIX-barba-blatest-foobar -> $HOME/.foobar/blatest/barba
35 |  |  |  |  |  |  | sending incremental file list
36 |  |  |  |  |  |  | created directory $HOME/.foobar/blatest/barba
37 |  |  |  |  |  |  | ./
38 |  |  |  |  |  |  | ";
39 |
40 | 1 |  |  |  |  | 77 | my $contents = read_file("$BASE/output");
41 | 1 |  |  |  |  | 379 | eq_or_diff_text( $contents, $wanted, "Check command output" );
42 |
43 | 1 |  |  |  |  | 2055 | $wanted = '';
44 | 1 | 50 |  |  |  | 71 | unless (which('lsof')) {
45 | 0 |  |  |  |  | 0 | $wanted = "WARNING: lsof not found, not checking for files in use.\n".$wanted;
46 |  |  |  |  |  |  | }
47 |
48 | 1 |  |  |  |  | 1276 | my $stderr = read_file("$BASE/stderr");
49 | 1 |  |  |  |  | 533 | print "\nSTDERR:\n\n$stderr\n";
50 | 1 |  |  |  |  | 72 | eq_or_diff_text( $stderr, $wanted, "Check command STDERR output (should be empty)" );
51 |
52 | 1 |  |  |  |  | 1541 | ok( -d "$TARGET", "Base directory still exists" );
53 | 1 |  |  |  |  | 1179 | ok( ! -e "$TARGET/$PREFIX-barba-blatest-foobar", "Directory no more exists" );
54 | 1 |  |  |  |  | 1378 | ok( -d "$HOME/.foobar/blatest/barba", "Symlink is a directory again" );
55 |
56 | 1 |  |  |  |  | 7594 | ok( rmtree("$BASE"), "Remove test environment" );
57 |
58 | 1 |  |  |  |  | 1582 | done_testing();