| File: | t/moving-to-existing-subdir.t |
| Coverage: | 96.7% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/perl -wl | ||||||
| 2 | |||||||
| 3 | 1 1 1 | 7392 80475 175 | use Test::More; | ||||
| 4 | 1 1 1 | 4331 48957 436 | use Test::Differences; | ||||
| 5 | 1 1 1 | 18 5 186 | use File::Path qw(mkpath rmtree); | ||||
| 6 | 1 1 1 | 969 48528 340 | use File::Slurp; | ||||
| 7 | 1 1 1 | 1135 4741 263 | use File::Which; | ||||
| 8 | 1 1 1 | 1669 19976 661509 | use Data::Dumper; | ||||
| 9 | |||||||
| 10 | 1 | 13 | my $BASE = 't/moving-to-existing-subdir'; | ||||
| 11 | 1 | 15 | my $HOME = "$BASE/home"; | ||||
| 12 | 1 | 15 | my $TARGET = "$BASE/target"; | ||||
| 13 | 1 | 11 | my $PREFIX = "u"; | ||||
| 14 | |||||||
| 15 | # Set a debug environment | ||||||
| 16 | 1 | 20 | $ENV{HOME} = $HOME; | ||||
| 17 | 1 | 16 | $ENV{LANG} = 'C'; | ||||
| 18 | |||||||
| 19 | # Clean up possible remainders of aborted tests | ||||||
| 20 | 1 | 531 | rmtree("$BASE"); | ||||
| 21 | |||||||
| 22 | 1 | 2381 | ok( mkpath("$HOME/.foobar/fnord", "$HOME/.foobar/gnarz", | ||||
| 23 | "$TARGET/$PREFIX-foobar-gnarz", {}), "Create test environment (directories)" ); | ||||||
| 24 | 1 | 3257 | ok( -d "$HOME/.foobar/fnord", "Original directory has been created" ); | ||||
| 25 | 1 | 1697 | ok( -d "$TARGET", "Target directory has been created" ); | ||||
| 26 | |||||||
| 27 | 1 | 2547 | ok( write_file("$HOME/.foobar/fnord/bla", "123\n"), "Create file 1" ); | ||||
| 28 | 1 | 3336 | ok( write_file("$HOME/.foobar/gnarz/goo", "456\n"), "Create file 2" ); | ||||
| 29 | 1 | 2265 | ok( write_file("$HOME/.foobar/foo", "abc\n"), "Create file 3" ); | ||||
| 30 | |||||||
| 31 | 1 | 3682 | ok( write_file("$BASE/list", "m d .foobar/fnord foobar-fnord\nm d .foobar/gnarz foobar-gnarz\nm f .foobar/foo foobar-foo\n"), "Create list" ); | ||||
| 32 | 1 | 3116 | ok( write_file("$BASE/config", "TARGETDIR=$TARGET\nFILELAYOUT=$PREFIX-\%s"), "Create config" ); | ||||
| 33 | |||||||
| 34 | 1 | 3061 | my $cmd = "bin/unburden-home-dir -C $BASE/config -L $BASE/list > $BASE/output 2> $BASE/stderr"; | ||||
| 35 | 1 | 3742054 | ok( system($cmd) == 0, "Call '$cmd'" ); | ||||
| 36 | |||||||
| 37 | 1 | 1439 | my $wanted = ""; | ||||
| 38 | 1 | 69 | unless (which('lsof')) { | ||||
| 39 | 0 | 0 | $wanted = "WARNING: lsof not found, not checking for files in use.\n".$wanted; | ||||
| 40 | } | ||||||
| 41 | |||||||
| 42 | 1 | 1624 | my $stderr = read_file("$BASE/stderr"); | ||||
| 43 | 1 | 555 | unified_diff; | ||||
| 44 | 1 | 100 | eq_or_diff_text( $stderr, $wanted, "Check command STDERR output (should be empty)" ); | ||||
| 45 | |||||||
| 46 | 1 | 1671 | $wanted = "Moving $HOME/.foobar/fnord -> $TARGET/u-foobar-fnord | ||||
| 47 | sending incremental file list | ||||||
| 48 | created directory $TARGET/u-foobar-fnord | ||||||
| 49 | ./ | ||||||
| 50 | bla | ||||||
| 51 | Symlinking $TARGET/u-foobar-fnord -> $HOME/.foobar/fnord | ||||||
| 52 | Moving $HOME/.foobar/gnarz -> $TARGET/u-foobar-gnarz | ||||||
| 53 | sending incremental file list | ||||||
| 54 | goo | ||||||
| 55 | Symlinking $TARGET/u-foobar-gnarz -> $HOME/.foobar/gnarz | ||||||
| 56 | Moving $HOME/.foobar/foo -> $TARGET/u-foobar-foo | ||||||
| 57 | '$HOME/.foobar/foo' -> '$TARGET/u-foobar-foo' | ||||||
| 58 | Symlinking $TARGET/u-foobar-foo -> $HOME/.foobar/foo | ||||||
| 59 | "; | ||||||
| 60 | |||||||
| 61 | 1 | 71 | my $output = read_file("$BASE/output"); | ||||
| 62 | |||||||
| 63 | # Somewhere between coreutils 8.13 (until Wheezy/Quantal), and 8.20 | ||||||
| 64 | # (from Jessie/Raring on) the quoting characters in verbose output of | ||||||
| 65 | # mv. changed. $wanted contains the newer style. In case this test | ||||||
| 66 | # runs with older version of coreutils, we change the output to look | ||||||
| 67 | # like the one from the newer versions. | ||||||
| 68 | 1 | 326 | $output =~ s/\`/\'/g; | ||||
| 69 | |||||||
| 70 | 1 | 65 | eq_or_diff_text( $output, $wanted, "Check command STDOUT" ); | ||||
| 71 | |||||||
| 72 | 1 | 1617 | ok( -d "$TARGET/$PREFIX-foobar-fnord", "First directory moved" ); | ||||
| 73 | 1 | 1316 | ok( -d "$TARGET/$PREFIX-foobar-gnarz", "Second directory moved" ); | ||||
| 74 | 1 | 1183 | ok( -f "$TARGET/$PREFIX-foobar-fnord/bla", "File 1 moved" ); | ||||
| 75 | 1 | 1173 | ok( -f "$TARGET/$PREFIX-foobar-gnarz/goo", "File 2 moved" ); | ||||
| 76 | 1 | 1284 | ok( -f "$TARGET/$PREFIX-foobar-foo", "File 3 moved" ); | ||||
| 77 | |||||||
| 78 | 1 | 6724 | ok( rmtree("$BASE"), "Clean up" ); | ||||
| 79 | |||||||
| 80 | 1 | 1036 | done_testing(); | ||||