File: | t/status.t |
Coverage: | 97.8% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 1 1 1 | 26513 6 37 | use strict; | ||||
2 | 1 1 1 | 8 5 38 | use warnings; | ||||
3 | |||||||
4 | 1 1 1 | 408 124952 8 | use Test::Most; | ||||
5 | 1 1 1 | 168970 25 8881 | use File::Path 'mkpath'; | ||||
6 | 1 1 1 | 544 5198 88 | use File::Copy 'copy'; | ||||
7 | 1 1 1 | 470 8969 19 | use lib 't'; | ||||
8 | 1 1 1 | 399 4 3878 | use TestLib qw( t_module t_startup t_teardown t_capture ); | ||||
9 | |||||||
10 | 1 | 225448 | exit main(); | ||||
11 | |||||||
12 | sub main { | ||||||
13 | 1 | 6 | require_ok( t_module() ); | ||||
14 | 1 | 9445 | t_startup(); | ||||
15 | |||||||
16 | 1 | 6 | t_module->init; | ||||
17 | 1 | 64 | mkpath('adt'); | ||||
18 | 1 | 5 | t_module->add('adt'); | ||||
19 | 1 1 | 10 5 | t_capture( sub { t_module->make('adt/state') } ); | ||||
20 | |||||||
21 | 1 | 8 | status(); | ||||
22 | 1 | 15575 | diff(); | ||||
23 | |||||||
24 | 1 | 6078 | t_teardown(); | ||||
25 | 1 | 6 | done_testing(); | ||||
26 | 1 | 13281 | return 0; | ||||
27 | } | ||||||
28 | |||||||
29 | sub status { | ||||||
30 | is( | ||||||
31 | 1 1 | 5 7 | ( t_capture( sub { t_module->status } ) )[0], | ||||
32 | join( "\n", | ||||||
33 | 'diff - adt', | ||||||
34 | ' + adt/state', | ||||||
35 | ) . "\n", | ||||||
36 | 'status() reports diff', | ||||||
37 | ); | ||||||
38 | |||||||
39 | 1 | 10540 | copy( '.dest/watch', 'dest.watch' ); | ||||
40 | is( | ||||||
41 | 1 1 | 268 5 | ( t_capture( sub { t_module->status } ) )[0], | ||||
42 | join( "\n", | ||||||
43 | 'diff - adt', | ||||||
44 | ' + adt/state', | ||||||
45 | ) . "\n", | ||||||
46 | 'status() reports diff (with watch file)', | ||||||
47 | ); | ||||||
48 | |||||||
49 | 1 1 | 647 38 | lives_ok( sub { t_module->clean }, 't_module->clean' ); | ||||
50 | 1 1 | 8739 6 | is( ( t_capture( sub { t_module->status } ) )[0], "ok - adt\n", 'status() reports ok after clean' ); | ||||
51 | |||||||
52 | 1 1 | 1230 38 | lives_ok( sub { t_module->preinstall }, 't_module->preinstall' ); | ||||
53 | is( | ||||||
54 | 1 1 | 7936 5 | ( t_capture( sub { t_module->status } ) )[0], | ||||
55 | join( "\n", | ||||||
56 | 'diff - adt', | ||||||
57 | ' + adt/state', | ||||||
58 | ) . "\n", | ||||||
59 | 'status() reports ok after preinstall', | ||||||
60 | ); | ||||||
61 | |||||||
62 | 1 | 2917 | t_module->clean; | ||||
63 | |||||||
64 | 1 | 6 | my $state_deploy; | ||||
65 | 1 | 49 | ok( open( $state_deploy, '>', 'adt/state/deploy' ) || 0, 'open deploy file for write' ); | ||||
66 | 1 | 5140 | print $state_deploy 'new content', "\n"; | ||||
67 | |||||||
68 | is( | ||||||
69 | 1 1 | 12 5 | ( t_capture( sub { t_module->status } ) )[0], | ||||
70 | join( "\n", | ||||||
71 | 'diff - adt', | ||||||
72 | ' adt/state', | ||||||
73 | ' M adt/state/deploy', | ||||||
74 | ) . "\n", | ||||||
75 | 'status() output correct', | ||||||
76 | ); | ||||||
77 | |||||||
78 | 1 | 5861 | my $dest_watch; | ||||
79 | 1 | 96 | ok( open( $dest_watch, '>', 'dest.watch' ) || 0, 'open dest.watch file for write' ); | ||||
80 | 1 | 2016 | print $dest_watch 'not_exists_watch', "\n"; | ||||
81 | like( | ||||||
82 | 1 1 | 12 6 | ( t_capture( sub { t_module->status } ) )[1], | ||||
83 | qr/Diff between current watch list and dest.watch file/, | ||||||
84 | 'watch list diff warn', | ||||||
85 | ); | ||||||
86 | } | ||||||
87 | |||||||
88 | sub diff { | ||||||
89 | like( | ||||||
90 | 1 1 | 5 11 | ( t_capture( sub { t_module->diff } ) )[0], | ||||
91 | qr|--- .dest/adt/state/deploy[^\n]*\n\+\+\+ adt/state/deploy[^\n]*\n\@\@ \-1 \+1 \@\@[^\n]*\n\-[^\n]*\n\+new content|, | ||||||
92 | 'messy diff appears correct', | ||||||
93 | ); | ||||||
94 | |||||||
95 | like( | ||||||
96 | 1 1 | 6645 6 | ( t_capture( sub { t_module->diff('adt') } ) )[0], | ||||
97 | qr|--- .dest/adt/state/deploy[^\n]*\n\+\+\+ adt/state/deploy[^\n]*\n\@\@ \-1 \+1 \@\@[^\n]*\n\-[^\n]*\n\+new content|, | ||||||
98 | 'messy diff appears correct with path', | ||||||
99 | ); | ||||||
100 | |||||||
101 | 1 | 5513 | t_module->clean; | ||||
102 | |||||||
103 | is( | ||||||
104 | 1 1 | 11 5 | ( t_capture( sub { t_module->diff } ) )[0], | ||||
105 | undef, | ||||||
106 | 'clean diff appears correct', | ||||||
107 | ); | ||||||
108 | } |