| File: | t/check-symlinks-without-trailing-slash.t |
| Coverage: | 96.1% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/perl -wl | ||||||
| 2 | |||||||
| 3 | 1 1 1 | 4994 46366 62 | use Test::More; | ||||
| 4 | 1 1 1 | 2250 30834 263 | use Test::Differences; | ||||
| 5 | 1 1 1 | 17 5 182 | use File::Path qw(mkpath rmtree); | ||||
| 6 | 1 1 1 | 947 40478 207 | use File::Slurp; | ||||
| 7 | 1 1 1 | 736 3013 182 | use File::Which; | ||||
| 8 | 1 1 1 | 1132 18205 497832 | use Data::Dumper; | ||||
| 9 | |||||||
| 10 | 1 | 9 | my $BASE = 't/check-symlinks-without-trailing-slash'; | ||||
| 11 | 1 | 10 | my $HOME = "$BASE/1"; | ||||
| 12 | 1 | 8 | 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 | 901 | ok( mkpath("$HOME/.foobar", {}), "Create test environment (directories)" ); | ||||
| 22 | 1 | 1277 | ok( ! -d "$TARGET/fnord", "Target directory does not exist" ); | ||||
| 23 | |||||||
| 24 | 1 | 1810 | ok( symlink("$TARGET/u-foobar-fnord", "$HOME/.foobar/fnord"), "Create test environment (Symlink)" ); | ||||
| 25 | 1 | 1771 | ok( -l "$HOME/.foobar/fnord", "Symlink has been created" ); | ||||
| 26 | |||||||
| 27 | 1 | 1603 | ok( write_file("$BASE/list", "m d .foobar/fnord foobar-fnord/\n") ); | ||||
| 28 | 1 | 2516 | ok( write_file("$BASE/config", "TARGETDIR=$TARGET\nFILELAYOUT=$PREFIX-\%s") ); | ||||
| 29 | |||||||
| 30 | 1 | 2410 | my $cmd = "bin/unburden-home-dir -C $BASE/config -L $BASE/list > $BASE/output 2> $BASE/stderr"; | ||||
| 31 | 1 | 2676031 | ok( system($cmd) == 0, "Call '$cmd'" ); | ||||
| 32 | |||||||
| 33 | 1 | 1303 | my $wanted = ""; | ||||
| 34 | 1 | 72 | unless (which('lsof')) { | ||||
| 35 | 0 | 0 | $wanted = "WARNING: lsof not found, not checking for files in use.\n".$wanted; | ||||
| 36 | } | ||||||
| 37 | |||||||
| 38 | 1 | 1590 | my $stderr = read_file("$BASE/stderr"); | ||||
| 39 | 1 | 581 | eq_or_diff_text( $stderr, $wanted, "Check command STDERR output" ); | ||||
| 40 | |||||||
| 41 | 1 | 1597 | $wanted = "Create $TARGET/u-foobar-fnord | ||||
| 42 | mkdir $TARGET | ||||||
| 43 | mkdir $TARGET/u-foobar-fnord | ||||||
| 44 | "; | ||||||
| 45 | |||||||
| 46 | 1 | 61 | my $output = read_file("$BASE/output"); | ||||
| 47 | 1 | 343 | eq_or_diff_text( $output, $wanted, "Check command STDOUT" ); | ||||
| 48 | |||||||
| 49 | 1 | 1457 | ok( -d "$TARGET/u-foobar-fnord", "Directory created" ); | ||||
| 50 | |||||||
| 51 | 1 | 5414 | ok( rmtree("$BASE"), "Clean up" ); | ||||
| 52 | |||||||
| 53 | 1 | 1412 | done_testing(); | ||||