File Coverage: t/skip-non-home.t

# File Coverage

File: | t/skip-non-home.t
Coverage: | 96.3%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 |  |  |  |  |  |  | #!/usr/bin/perl -wl
2 |
3 | 1 1 1 |  |  | 1 |  | 4995 46798 62 | use Test::More;
4 | 1 1 1 |  |  | 1 |  | 2295 30681 349 | use Test::Differences;
5 | 1 1 1 |  |  | 1 |  | 26 8 272 | use File::Path qw(mkpath rmtree);
6 | 1 1 1 |  |  | 1 |  | 1576 62929 334 | use File::Slurp;
7 | 1 1 1 |  |  | 1 |  | 1134 4657 255 | use File::Which;
8 | 1 1 1 |  |  | 1 |  | 1768 19511 524750 | use Data::Dumper;
9 |
10 | 1 |  |  |  |  | 12 | my $BASE = 't/skip-non-home';
11 | 1 |  |  |  |  | 13 | my $HOME = "$BASE/1";
12 | 1 |  |  |  |  | 11 | my $TARGET = "$BASE/2";
13 | 1 |  |  |  |  | 8 | my $PREFIX = "u";
14 |
15 |  |  |  |  |  |  | # Set a debug environment
16 | 1 |  |  |  |  | 18 | $ENV{HOME} = $HOME;
17 |
18 |  |  |  |  |  |  | # Clean up possible remainders of aborted tests
19 | 1 |  |  |  |  | 398 | rmtree("$BASE");
20 |
21 | 1 |  |  |  |  | 13 | foreach my $example (qw(/foobar ../foobar)) {
22 |  |  |  |  |  |  | # Create test environment
23 | 2 |  |  |  |  | 77266 | ok( mkpath("$HOME/foobar", {}), "Create test environment (directories)" );
24 | 2 |  |  |  |  | 2621 | ok( -d "$HOME/foobar", "Original directory has been created" );
25 |
26 | 2 |  |  |  |  | 2729 | ok( ! -d "$BASE/foobar", "$BASE/foobar does not exist (check for safe environment)" );
27 | 2 |  |  |  |  | 5903 | ok( ! -d "/foobar", "$BASE/foobar does not exist (check for safe environment)" );
28 |
29 | 2 |  |  |  |  | 2877 | ok( write_file("$BASE/list", "m d $example foobar") );
30 | 2 |  |  |  |  | 5443 | ok( write_file("$BASE/config", "TARGETDIR=$TARGET\nFILELAYOUT=$PREFIX-\%s") );
31 |
32 | 2 |  |  |  |  | 4403 | my $cmd = "bin/unburden-home-dir -C $BASE/config -L $BASE/list > $BASE/output 2> $BASE/stderr";
33 | 2 |  |  |  |  | 5237301 | ok( system($cmd) == 0, "Call '$cmd'" );
34 |
35 | 2 |  |  |  |  | 2599 | my $wanted = "$example would be outside of the home directory, skipping...\n";
36 | 2 | 50 |  |  |  | 138 | unless (which('lsof')) {
37 | 0 |  |  |  |  | 0 | $wanted = "WARNING: lsof not found, not checking for files in use.\n".$wanted;
38 |  |  |  |  |  |  | }
39 |
40 | 2 |  |  |  |  | 3199 | my $stderr = read_file("$BASE/stderr");
41 | 2 |  |  |  |  | 634 | eq_or_diff_text( $stderr, $wanted, "Check command STDERR output" );
42 |
43 | 2 |  |  |  |  | 3707 | my $output = read_file("$BASE/output");
44 | 2 |  |  |  |  | 1459 | eq_or_diff_text( $output, '', "Check command STDOUT (should be empty)" );
45 |
46 | 2 |  |  |  |  | 2770 | ok( ! -d "$TARGET/$PREFIX-foobar", "Nothing created" );
47 | 2 |  |  |  |  | 2582 | ok( ! -d "$TARGET", "Nothing created" );
48 |
49 | 2 |  |  |  |  | 2655 | ok( ! -d "$BASE/foobar", "$BASE/foobar still does not exist" );
50 | 2 |  |  |  |  | 2199 | ok( ! -d "/foobar", "$BASE/foobar still does not exist" );
51 |
52 | 2 |  |  |  |  | 9551 | ok( rmtree("$BASE"), "Clean up" );
53 |  |  |  |  |  |  | }
54 |
55 | 1 |  |  |  |  | 1232 | done_testing();