File: | t/find-per-user-stuff-xdg.t |
Coverage: | 96.5% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | #!/usr/bin/perl -wl | ||||||
2 | |||||||
3 | 1 1 1 | 4870 59062 63 | use Test::More; | ||||
4 | 1 1 1 | 2172 31506 256 | use Test::Differences; | ||||
5 | 1 1 1 | 16 5 179 | use File::Path qw(mkpath rmtree); | ||||
6 | 1 1 1 | 975 53689 208 | use File::Slurp; | ||||
7 | 1 1 1 | 729 2991 166 | use File::Which; | ||||
8 | 1 1 1 | 1140 18452 568917 | use Data::Dumper; | ||||
9 | |||||||
10 | 1 | 10 | my $BASE = 't/find-per-user-stuff'; | ||||
11 | 1 | 8 | my $HOME = "$BASE/1"; | ||||
12 | 1 | 8 | my $TARGET = "$BASE/2"; | ||||
13 | 1 | 10 | my $BASENAME = "unburden-home-dir_TEST_$$"; | ||||
14 | 1 | 6 | my $PREFIX = "u"; | ||||
15 | |||||||
16 | # Set a debug environment | ||||||
17 | 1 | 15 | $ENV{HOME} = $HOME; | ||||
18 | |||||||
19 | # Clean up possible remainders of aborted tests | ||||||
20 | 1 | 322 | rmtree("$BASE"); | ||||
21 | |||||||
22 | 1 | 1880 | ok( mkpath("$HOME/.foobar/fnord/bla", "$TARGET", "$HOME/.config/$BASENAME", {}), "Create test environment (directories)" ); | ||||
23 | 1 | 1224 | ok( -d "$HOME/.foobar/fnord/bla", "Original directory has been created" ); | ||||
24 | 1 | 1542 | ok( -d "$TARGET", "Target directory has been created" ); | ||||
25 | |||||||
26 | 1 | 1595 | ok( symlink("$HOME/.foobar/fnord", "$HOME/.fnord"), "Create test environment (Symlink 1)" ); | ||||
27 | 1 | 1191 | ok( -l "$HOME/.fnord", "Symlink 1 has been created" ); | ||||
28 | 1 | 1518 | ok( symlink("fnord", "$HOME/.foobar/blafasel"), "Create test environment (Symlink 2)" ); | ||||
29 | 1 | 1253 | ok( -l "$HOME/.foobar/blafasel", "Symlink 2 has been created" ); | ||||
30 | |||||||
31 | 1 | 1258 | ok( write_file("$HOME/.config/$BASENAME/list", "m d .foobar/fnord/bla foobar-fnord-bla\nm d .fnord/bla fnord-bla\nm d .foobar/blafasel/bla foobar-blafasel-bla\n") ); | ||||
32 | 1 | 1780 | ok( write_file("$HOME/.config/$BASENAME/config", "TARGETDIR=$TARGET\nFILELAYOUT=$PREFIX-\%s") ); | ||||
33 | |||||||
34 | 1 | 1765 | my $cmd = "bin/unburden-home-dir -b $BASENAME > $BASE/output 2> $BASE/stderr"; | ||||
35 | 1 | 2976901 | ok( system($cmd) == 0, "Call '$cmd'" ); | ||||
36 | |||||||
37 | 1 | 1300 | my $wanted = "Skipping '$HOME/.fnord/bla' due to symlink in path: $HOME/.fnord | ||||
38 | Skipping '$HOME/.foobar/blafasel/bla' due to symlink in path: $HOME/.foobar/blafasel | ||||||
39 | "; | ||||||
40 | 1 | 72 | unless (which('lsof')) { | ||||
41 | 0 | 0 | $wanted = "WARNING: lsof not found, not checking for files in use.\n".$wanted; | ||||
42 | } | ||||||
43 | |||||||
44 | 1 | 1863 | my $stderr = read_file("$BASE/stderr"); | ||||
45 | 1 | 284 | eq_or_diff_text( $stderr, $wanted, "Check command STDERR output" ); | ||||
46 | |||||||
47 | 1 | 1606 | $wanted = "Moving $HOME/.foobar/fnord/bla -> $TARGET/u-foobar-fnord-bla | ||||
48 | sending incremental file list | ||||||
49 | created directory $TARGET/u-foobar-fnord-bla | ||||||
50 | ./ | ||||||
51 | Symlinking $TARGET/u-foobar-fnord-bla -> $HOME/.foobar/fnord/bla | ||||||
52 | "; | ||||||
53 | |||||||
54 | 1 | 66 | my $output = read_file("$BASE/output"); | ||||
55 | 1 | 326 | eq_or_diff_text( $output, $wanted, "Check command STDOUT" ); | ||||
56 | |||||||
57 | 1 | 1627 | ok( -d "$TARGET/$PREFIX-foobar-fnord-bla", "First directory moved" ); | ||||
58 | 1 | 1212 | ok( ! -e "$TARGET/$PREFIX-fnord-bla", "Symlink 1 not moved" ); | ||||
59 | 1 | 1324 | ok( ! -e "$TARGET/$PREFIX-foobar-blafasel-bla", "Symlink 2 not moved" ); | ||||
60 | |||||||
61 | 1 | 8267 | ok( rmtree("$BASE"), "Clean up" ); | ||||
62 | |||||||
63 | 1 | 1123 | done_testing(); |