File Coverage

File:t/init.t
Coverage:98.3%

linestmtbrancondsubpodtimecode
1
1
1
1
28998
13
65
use strict;
2
1
1
1
14
9
43
use warnings;
3
4
1
1
1
708
107664
24
use Test::Most;
5
1
1
1
162251
4
157
use File::Path qw( mkpath rmtree );
6
1
1
1
727
1459
7
use lib 't';
7
1
1
1
687
5
2784
use TestLib qw( t_module t_startup t_teardown t_capture );
8
9
1
227789
exit main();
10
11sub main {
12
1
5
    require_ok( t_module() );
13
14
1
11642
    basic();
15
1
7
    watch_file();
16
17
1
7
    done_testing();
18
1
3445
    return 0;
19}
20
21sub basic {
22
1
44
    t_startup();
23
24
1
1
17
27
    eval{ t_module->init };
25
1
19
    ok( !$@, 'init' );
26
27
1
4292
    ok( -d '.dest', 'init() += directory' );
28
1
1955
    ok( -f '.dest/watch', 'init() += watch file' );
29
30
1
1
514
31
    throws_ok( sub { t_module->init }, qr/Project already initialized/, 'project already initialized' );
31
32
1
8642
    t_teardown();
33}
34
35sub watch_file {
36
1
5
    t_startup();
37
38
1
6
    my $dest_watch;
39
1
50
    ok( open( $dest_watch, '>', 'dest.watch' ) || 0, 'open dest.watch file for write' );
40
41
1
3187
    for ( qw( a b c ) ) {
42
3
432
        mkpath($_);
43
3
96
        print $dest_watch $_, "\n";
44    }
45
1
27
    close $dest_watch;
46
47    is(
48
1
1
13
5
        ( t_capture( sub { t_module->init } ) )[1],
49        "Created new watch list based on dest.watch file:\n  a\n  b\n  c\n",
50        'init with dest.watch',
51    );
52
53
1
4996
    ok( -f '.dest/watch', 'init() += watch file with dest.watch' );
54
1
3379
    ok( -d '.dest', 'init() += directory with dest.watch' );
55
56
1
1473
    t_teardown();
57}