File Coverage: t/undo-dryrun.t

# File Coverage

File: | t/undo-dryrun.t
Coverage: | 100.0%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 |  |  |  |  |  |  | #!/usr/bin/perl -wl
2 |
3 | 1 1 1 |  |  | 1 |  | 13796 46042 62 | use Test::More;
4 | 1 1 1 |  |  | 1 |  | 2182 38668 393 | use Test::Differences;
5 | 1 1 1 |  |  | 1 |  | 27 7 317 | use File::Path qw(mkpath rmtree);
6 | 1 1 1 |  |  | 1 |  | 1519 56665 318 | use File::Slurp;
7 | 1 1 1 |  |  | 1 |  | 1560 27475 587000 | use Data::Dumper;
8 |
9 | 1 |  |  |  |  | 8 | my $BASE = 't/undo-dryrun';
10 | 1 |  |  |  |  | 23 | my $HOME = "$BASE/1";
11 | 1 |  |  |  |  | 8 | my $TARGET = "$BASE/2";
12 | 1 |  |  |  |  | 6 | my $PREFIX = "u";
13 |
14 |  |  |  |  |  |  | # Set a debug environment
15 | 1 |  |  |  |  | 14 | $ENV{HOME} = $HOME;
16 |
17 | 1 |  |  |  |  | 1389 | ok( mkpath("$HOME/.foobar/blatest", "$TARGET/$PREFIX-barba-blatest-foobar", {}), "Create test environment (directories)" );
18 | 1 |  |  |  |  | 1289 | ok( -d "$TARGET", "Target directory has been created" );
19 | 1 |  |  |  |  | 1743 | ok( symlink("$TARGET/$PREFIX-barba-blatest-foobar", "$HOME/.foobar/blatest/barba"), "Create test environment (symlink)" );
20 |
21 | 1 |  |  |  |  | 1155 | ok( write_file("$BASE/list", 'm d .foo*/bla*/bar* bar%3-bla%2-foo%1'), "Create list" );
22 | 1 |  |  |  |  | 1861 | ok( write_file("$BASE/config", "TARGETDIR=$TARGET\nFILELAYOUT=$PREFIX-\%s"), "Create config" );
23 |
24 | 1 |  |  |  |  | 1681 | my $cmd = "bin/unburden-home-dir -n -u -C $BASE/config -L $BASE/list > $BASE/output 2> $BASE/stderr";
25 | 1 |  |  |  |  | 2868484 | ok( system($cmd) == 0, "Call '$cmd'" );
26 |
27 | 1 |  |  |  |  | 2056 | my $wanted = <<EOF;
28 |  |  |  |  |  |  | Trying to revert $TARGET/u-barba-blatest-foobar to $HOME/.foobar/blatest/barba
29 |  |  |  |  |  |  | Removing symlink $HOME/.foobar/blatest/barba
30 |  |  |  |  |  |  | Moving $TARGET/u-barba-blatest-foobar -> $HOME/.foobar/blatest/barba
31 |  |  |  |  |  |  | EOF
32 | 1 |  |  |  |  | 89 | my $contents = read_file("$BASE/output");
33 | 1 |  |  |  |  | 383 | eq_or_diff_text( $contents, $wanted, "Check command output" );
34 |
35 | 1 |  |  |  |  | 2313 | ok( -d "$TARGET", "Base directory still exists" );
36 | 1 |  |  |  |  | 3182 | ok( -d "$TARGET/$PREFIX-barba-blatest-foobar", "Directory still exists" );
37 | 1 |  |  |  |  | 2415 | ok( -l "$HOME/.foobar/blatest/barba", "Symlink still exists" );
38 | 1 |  |  |  |  | 1487 | eq_or_diff_text( "$TARGET/$PREFIX-barba-blatest-foobar",
39 |  |  |  |  |  |  | readlink("$HOME/.foobar/blatest/barba"),
40 |  |  |  |  |  |  | "Symlink still has right target" );
41 |
42 | 1 |  |  |  |  | 11117 | ok( rmtree("$BASE"), "Remove test environment" );
43 |
44 | 1 |  |  |  |  | 1520 | done_testing();