File Coverage: t/xsession-d.t

# File Coverage

File: | t/xsession-d.t
Coverage: | 100.0%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 |  |  |  |  |  |  | #!/usr/bin/perl -wl
2 |
3 | 1 1 1 |  |  | 1 |  | 4831 45896 62 | use Test::More;
4 | 1 1 1 |  |  | 1 |  | 2183 31661 235 | use Test::Differences;
5 | 1 1 1 |  |  | 1 |  | 16 5 168 | use File::Path qw(mkpath rmtree);
6 | 1 1 1 |  |  | 1 |  | 928 9871 289 | use File::Copy;
7 | 1 1 1 |  |  | 1 |  | 1434 52018 199 | use File::Slurp;
8 | 1 1 1 |  |  | 1 |  | 764 2797 159 | use File::Which;
9 | 1 1 1 |  |  | 1 |  | 1192 19873 574504 | use Data::Dumper;
10 |
11 | 1 |  |  |  |  | 8 | my $BASE = 't/xsession-d';
12 | 1 |  |  |  |  | 8 | my $HOME = "$BASE/1";
13 | 1 |  |  |  |  | 7 | my $TARGET = "$BASE/2";
14 | 1 |  |  |  |  | 8 | my $BINDIR = "$BASE/bin";
15 | 1 |  |  |  |  | 7 | my $XSESSIOND = "$BASE/Xsession.d";
16 | 1 |  |  |  |  | 7 | my $RPSCRIPT = "95unburden-home-dir";
17 | 1 |  |  |  |  | 10 | my $BASENAME = "unburden-home-dir_TEST_$$";
18 |
19 | 1 |  |  |  |  | 6 | my ($cmd, $wanted, $output, $stderr);
20 |
21 |  |  |  |  |  |  | # Set a debug environment
22 | 1 |  |  |  |  | 14 | $ENV{HOME} = $HOME;
23 | 1 |  |  |  |  | 11 | $ENV{PATH} = $BINDIR;
24 | 1 |  |  |  |  | 32 | $ENV{UNBURDEN_BASENAME} = $BASENAME;
25 |
26 |  |  |  |  |  |  | # Clean up possible remainders of aborted tests
27 | 1 |  |  |  |  | 322 | rmtree("$BASE");
28 |
29 | 1 |  |  |  |  | 1350 | ok( mkpath($HOME, $XSESSIOND, $BINDIR, {}), "Create test environment (directories)" );
30 | 1 |  |  |  |  | 1553 | ok( -d "$HOME", "Home directory has been created" );
31 | 1 |  |  |  |  | 1785 | ok( -d "$BINDIR", "Script directory has been created" );
32 | 1 |  |  |  |  | 1415 | ok( -d "$XSESSIOND", "Xsession.d directory has been created" );
33 |
34 | 1 |  |  |  |  | 1197 | ok( copy( "Xsession.d/$RPSCRIPT", "$XSESSIOND/" ), "Install Xsession.d script" );
35 | 1 |  |  |  |  | 2408 | ok( write_file("$BINDIR/unburden-home-dir", "#!/bin/sh\necho \$0 called\n"), "Create test script" );
36 | 1 |  |  |  |  | 1802 | ok( chmod( 0755, "$BINDIR/unburden-home-dir" ), "Set executable bit on testscript" );
37 | 1 |  |  |  |  | 1129 | ok( write_file("$HOME/.$BASENAME", "UNBURDEN_HOME=yes\n"), "Configure Xsession.d script to run unburden-home-dir" );
38 |
39 | 1 |  |  |  |  | 1794 | $cmd = "/bin/run-parts --list $XSESSIOND > $BASE/output 2> $BASE/stderr";
40 | 1 |  |  |  |  | 6305 | ok( system($cmd) == 0, "Call '$cmd'" );
41 |
42 | 1 |  |  |  |  | 1310 | $wanted = "";
43 |
44 | 1 |  |  |  |  | 73 | $stderr = read_file("$BASE/stderr");
45 | 1 |  |  |  |  | 772 | eq_or_diff_text( $stderr, $wanted, "Check run-parts STDERR output" );
46 | 1 |  |  |  |  | 1840 | ok( unlink("$BASE/stderr"), "Clean output" );
47 |
48 | 1 |  |  |  |  | 1152 | $wanted = "$XSESSIOND/$RPSCRIPT\n";
49 |
50 | 1 |  |  |  |  | 123 | $output = read_file("$BASE/output");
51 | 1 |  |  |  |  | 324 | eq_or_diff_text( $output, $wanted, "Check run-parts STDOUT" );
52 | 1 |  |  |  |  | 1686 | ok( unlink("$BASE/output"), "Clean output" );
53 |
54 | 1 |  |  |  |  | 1035 | $cmd = "/bin/sh $XSESSIOND/$RPSCRIPT > $BASE/output 2> $BASE/stderr";
55 | 1 |  |  |  |  | 8949 | ok( system($cmd) == 0, "Call '$cmd'" );
56 |
57 | 1 |  |  |  |  | 1249 | $wanted = "";
58 |
59 | 1 |  |  |  |  | 71 | $stderr = read_file("$BASE/stderr");
60 | 1 |  |  |  |  | 734 | eq_or_diff_text( $stderr, $wanted, "Check Xsession.d STDERR output" );
61 | 1 |  |  |  |  | 2027 | ok( unlink("$BASE/stderr"), "Clean output" );
62 |
63 | 1 |  |  |  |  | 1017 | $wanted = "$BINDIR/unburden-home-dir called\n";
64 |
65 | 1 |  |  |  |  | 58 | $output = read_file("$BASE/output");
66 | 1 |  |  |  |  | 347 | eq_or_diff_text( $output, $wanted, "Check Xsession.d STDOUT" );
67 | 1 |  |  |  |  | 1789 | ok( unlink("$BASE/output"), "Clean output" );
68 |
69 | 1 |  |  |  |  | 1149 | ok( write_file("$HOME/.$BASENAME", "UNBURDEN_HOME=no\n"), "Configure Xsession.d script to NOT run unburden-home-dir" );
70 |
71 | 1 |  |  |  |  | 1709 | $cmd = "/bin/sh $XSESSIOND/$RPSCRIPT > $BASE/output 2> $BASE/stderr";
72 | 1 |  |  |  |  | 6322 | ok( system($cmd) == 0, "Call '$cmd'" );
73 |
74 | 1 |  |  |  |  | 1235 | $wanted = "";
75 |
76 | 1 |  |  |  |  | 73 | $stderr = read_file("$BASE/stderr");
77 | 1 |  |  |  |  | 739 | eq_or_diff_text( $stderr, $wanted, "Check Xsession.d STDERR output" );
78 | 1 |  |  |  |  | 1875 | ok( unlink("$BASE/stderr"), "Clean output" );
79 |
80 | 1 |  |  |  |  | 1015 | $wanted = "";
81 |
82 | 1 |  |  |  |  | 58 | $output = read_file("$BASE/output");
83 | 1 |  |  |  |  | 636 | eq_or_diff_text( $output, $wanted, "Check Xsession.d STDOUT" );
84 | 1 |  |  |  |  | 1714 | ok( unlink("$BASE/output"), "Clean output" );
85 |
86 | 1 |  |  |  |  | 4372 | ok( rmtree("$BASE"), "Clean up" );
87 |
88 | 1 |  |  |  |  | 1019 | done_testing();