File: | t/watches.t |
Coverage: | 100.0% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 1 1 1 | 60165 5 149 | use strict; | ||||
2 | 1 1 1 | 7 3 33 | use warnings; | ||||
3 | |||||||
4 | 1 1 1 | 624 65133 8 | use Test::Most; | ||||
5 | 1 1 1 | 185724 10 121 | use File::Path 'mkpath'; | ||||
6 | 1 1 1 | 625 1029 8 | use lib 't'; | ||||
7 | 1 1 1 | 401 4 6785 | use TestLib qw( t_module t_startup t_teardown t_capture ); | ||||
8 | |||||||
9 | 1 | 206191 | exit main(); | ||||
10 | |||||||
11 | sub main { | ||||||
12 | 1 | 6 | require_ok( t_module() ); | ||||
13 | 1 | 1944 | t_startup(); | ||||
14 | |||||||
15 | 1 | 7 | t_module->init; | ||||
16 | |||||||
17 | 1 | 7 | add(); | ||||
18 | 1 | 544 | rm(); | ||||
19 | 1 | 495 | make(); | ||||
20 | 1 | 498 | list(); | ||||
21 | 1 | 592 | watches(); | ||||
22 | |||||||
23 | 1 | 433 | t_teardown(); | ||||
24 | 1 | 10 | done_testing(); | ||||
25 | 1 | 809 | return 0; | ||||
26 | } | ||||||
27 | |||||||
28 | sub add { | ||||||
29 | 1 | 67 | mkpath('atd'); | ||||
30 | |||||||
31 | 1 1 | 6 6 | eval{ t_module->add('atd') }; | ||||
32 | |||||||
33 | 1 | 10 | ok( !$@, 'add' ); | ||||
34 | 1 | 635 | ok( -d '.dest/atd', 'add() += directory' ); | ||||
35 | 1 | 374 | is_deeply( [ t_module->_watches ], ['atd'], 'add() -> (watch file)++' ); | ||||
36 | |||||||
37 | throws_ok( | ||||||
38 | 1 | 34 | sub { t_module->add() }, | ||||
39 | 1 | 592 | qr/No directory specified; usage: dest add \[directory\]/, | ||||
40 | 'no dir specified', | ||||||
41 | ); | ||||||
42 | |||||||
43 | throws_ok( | ||||||
44 | 1 | 21 | sub { t_module->add('notexists') }, | ||||
45 | 1 | 356 | qr/Directory specified does not exist/, | ||||
46 | 'dir not exists', | ||||||
47 | ); | ||||||
48 | |||||||
49 | throws_ok( | ||||||
50 | 1 | 21 | sub { t_module->add('atd') }, | ||||
51 | 1 | 510 | qr/Directory atd already added/, | ||||
52 | 'dir already exists', | ||||||
53 | ); | ||||||
54 | } | ||||||
55 | |||||||
56 | sub rm { | ||||||
57 | 1 | 207 | mkpath('atd2'); | ||||
58 | 1 | 6 | t_module->add('atd2'); | ||||
59 | |||||||
60 | 1 1 | 4 5 | eval{ t_module->rm('atd2') }; | ||||
61 | 1 | 9 | ok( !$@, 'rm' ); | ||||
62 | 1 | 995 | ok( ! -d '.dest/atd2', 'rm() -= directory' ); | ||||
63 | 1 | 763 | is_deeply( [ t_module->_watches ], ['atd'], 'rm() -> (watch file)--' ); | ||||
64 | |||||||
65 | throws_ok( | ||||||
66 | 1 | 35 | sub { t_module->rm() }, | ||||
67 | 1 | 760 | qr/No directory specified; usage: dest rm \[directory\]/, | ||||
68 | 'no dir specified for rm', | ||||||
69 | ); | ||||||
70 | |||||||
71 | throws_ok( | ||||||
72 | 1 | 26 | sub { t_module->rm('untracked') }, | ||||
73 | 1 | 607 | qr/Directory untracked not currently tracked/, | ||||
74 | 'dir not tracked', | ||||||
75 | ); | ||||||
76 | } | ||||||
77 | |||||||
78 | sub make { | ||||||
79 | 1 1 | 6 9 | my ( $out, $err, $exp ) = t_capture( sub { t_module->make('atd/state') } ); | ||||
80 | 1 | 13 | ok( ! $exp, 'make' ); | ||||
81 | 1 | 740 | ok( $out eq "atd/state/deploy atd/state/verify atd/state/revert\n", 'make() output correct' ); | ||||
82 | |||||||
83 | throws_ok( | ||||||
84 | 1 | 67 | sub { t_module->make() }, | ||||
85 | 1 | 494 | qr/No name specified; usage: dest make \[path\]/, | ||||
86 | 'no name specified for make', | ||||||
87 | ); | ||||||
88 | } | ||||||
89 | |||||||
90 | sub list { | ||||||
91 | 1 | 338 | mkpath('new'); | ||||
92 | 1 | 7 | t_module->add('new'); | ||||
93 | |||||||
94 | 1 1 | 11 5 | ok( ( t_capture( sub { t_module->list } ) )[0] eq "atd\n atd/state\nnew\n", 'list (blank)' ); | ||||
95 | ok( | ||||||
96 | ( t_capture( | ||||||
97 | 1 | 5 | sub { t_module->list('atd/state') } | ||||
98 | 1 | 810 | ) )[0] eq "atd/state/deploy atd/state/verify atd/state/revert\n", | ||||
99 | 'list (action)', | ||||||
100 | ); | ||||||
101 | |||||||
102 | 1 | 558 | t_module->rm('new'); | ||||
103 | |||||||
104 | 1 1 | 15 6 | ok( ( t_capture( sub { t_module->list } ) )[0] eq "atd\n atd/state\n", 'list (again)' ); | ||||
105 | } | ||||||
106 | |||||||
107 | sub watches { | ||||||
108 | 1 1 | 5 8 | is( ( t_capture( sub { t_module->watches } ) )[0], "atd\n", 'watches()' ); | ||||
109 | } |