File: | t/create-empty-directories.t |
Coverage: | 96.2% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | #!/usr/bin/perl -wl | ||||||
2 | |||||||
3 | 1 1 1 | 4918 47719 61 | use Test::More; | ||||
4 | 1 1 1 | 2175 33159 399 | use Test::Differences; | ||||
5 | 1 1 1 | 27 6 290 | use File::Path qw(mkpath rmtree); | ||||
6 | 1 1 1 | 980 45095 210 | use File::Slurp; | ||||
7 | 1 1 1 | 972 2776 159 | use File::Which; | ||||
8 | 1 1 1 | 1600 27215 551802 | use Data::Dumper; | ||||
9 | |||||||
10 | 1 | 8 | my $BASE = 't/create-empty-directories'; | ||||
11 | 1 | 10 | my $HOME = "$BASE/home"; | ||||
12 | 1 | 8 | my $TARGET = "$BASE/target"; | ||||
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 | 328 | rmtree("$BASE"); | ||||
20 | |||||||
21 | 1 | 871 | ok( mkpath("$HOME", "$TARGET", {}), "Create test environment (directories)" ); | ||||
22 | 1 | 1210 | ok( -d "$HOME", "Original directory has been created" ); | ||||
23 | 1 | 1629 | ok( -d "$TARGET", "Target directory has been created" ); | ||||
24 | 1 | 1338 | ok( ! -d "$TARGET/$PREFIX-foobar-fnord", "unburden directory doesn't yet exist" ); | ||||
25 | |||||||
26 | 1 | 1484 | ok( write_file("$BASE/list", "r D .foobar/fnord foobar-fnord"), "Create list" ); | ||||
27 | 1 | 2535 | ok( write_file("$BASE/config", "TARGETDIR=$TARGET\nFILELAYOUT=$PREFIX-\%s"), "Create config" ); | ||||
28 | |||||||
29 | 1 | 2314 | my $cmd = "bin/unburden-home-dir -C $BASE/config -L $BASE/list > $BASE/output 2> $BASE/stderr"; | ||||
30 | 1 | 2516500 | ok( system($cmd) == 0, "Call '$cmd'" ); | ||||
31 | |||||||
32 | 1 | 1993 | my $wanted = ""; | ||||
33 | 1 | 72 | unless (which('lsof')) { | ||||
34 | 0 | 0 | $wanted = "WARNING: lsof not found, not checking for files in use.\n".$wanted; | ||||
35 | } | ||||||
36 | |||||||
37 | 1 | 2642 | my $stderr = read_file("$BASE/stderr"); | ||||
38 | 1 | 874 | eq_or_diff_text( $stderr, $wanted, "Check command STDERR output (should be empty)" ); | ||||
39 | |||||||
40 | 1 | 2399 | $wanted = "Create directory t/create-empty-directories/target/u-foobar-fnord and parents | ||||
41 | mkdir t/create-empty-directories/target/u-foobar-fnord | ||||||
42 | Create parent directories for $HOME/.foobar/fnord | ||||||
43 | mkdir $HOME/.foobar | ||||||
44 | Symlinking $HOME/.foobar/fnord -> $TARGET/u-foobar-fnord | ||||||
45 | "; | ||||||
46 | |||||||
47 | 1 | 62 | my $output = read_file("$BASE/output"); | ||||
48 | 1 | 380 | eq_or_diff_text( $output, $wanted, "Check command STDOUT" ); | ||||
49 | |||||||
50 | 1 | 2139 | ok( -d "$TARGET/$PREFIX-foobar-fnord", "Directory has been created" ); | ||||
51 | 1 | 3066 | ok( -d "$HOME/.foobar", "Parent directory of symlink has been created." ); | ||||
52 | 1 | 1528 | ok( -l "$HOME/.foobar/fnord", "Symlink has been created." ); | ||||
53 | |||||||
54 | 1 | 8600 | ok( rmtree("$BASE"), "Clean up" ); | ||||
55 | |||||||
56 | 1 | 1036 | done_testing(); |