File: App-PRT-Command-AddUse.t

package info (click to toggle)
prt 0.20-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 376 kB
  • sloc: perl: 1,154; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 1,956 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package t::App::PRT::Command::AddUse;
use t::test;

sub _require : Test(startup => 1) {
    my ($self) = @_;

    use_ok 'App::PRT::Command::AddUse';
}

sub instantiate : Tests {
    isa_ok App::PRT::Command::AddUse->new, 'App::PRT::Command::AddUse';
}

sub register : Tests {
    subtest 'package' => sub {
        my $command = App::PRT::Command::AddUse->new;
        $command->register('My::Package');
        is $command->namespace, 'My::Package';
    };

    subtest 'package and arguments' => sub {
        my $command = App::PRT::Command::AddUse->new;
        $command->register('My::Package qw()');
        is $command->namespace, 'My::Package qw()';
    };
}

sub execute : Tests {
    my $directory = t::test::prepare_test_code('greeting');

    my $command = App::PRT::Command::AddUse->new;

    $command->register('Hi');

    subtest 'script with use statement, not using Hi' => sub {
        my $file = "$directory/use_greeting.pl";
        $command->execute($file);

        ok -f $file, 'File exists';
        is file($file)->slurp, <<'CODE', 'Hi was added';
use strict;
use warnings;
use lib 'lib';

use Greeting;
use Hi;

print Greeting->hi('Alice');
print Greeting->bye('Bob');
CODE
    };

    subtest 'script, already using Hi' => sub {
        my $file = "$directory/use_greeting_and_hi.pl";
        $command->execute($file);

        ok -f $file, 'File exists';
        is file($file)->slurp, <<'CODE', 'Hi was not added';
use strict;
use warnings;
use lib 'lib';

use Greeting;
use Hi;

print Greeting->hi('Alice');
print Greeting->bye('Bob');
CODE
    };

    subtest 'script without any use, but with package statement' => sub {
        my $file = "$directory/no_use_but_package.pl";
        $command->execute($file);

        ok -f $file, 'File exists';
        is file($file)->slurp, <<'CODE', 'Hi was added after package statement';
package Main;
use Hi;

print Greeting->hi('Alice');
print Greeting->bye('Bob');
CODE
    };
}