File: command-make-shim.t

package info (click to toggle)
perlbrew 1.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 752 kB
  • sloc: perl: 9,387; makefile: 7; sh: 1
file content (95 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download | duplicates (2)
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
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env perl
use Test2::V0;
use Test2::Tools::Spec;
use File::Temp qw( tempdir );

use FindBin;
use lib $FindBin::Bin;

use App::perlbrew;
require "test2_helpers.pl";
use PerlbrewTestHelpers qw(read_file write_file);

mock_perlbrew_install("perl-5.36.1");

describe "App::perlbrew->make_shim()" => sub {
    it "should show usage", sub {
        mock_perlbrew_use("perl-5.36.1");

        my $called = 0;
        my $mock = mock 'App::perlbrew',
            override => [
                run_command_help => sub { $called++; "" }
            ];

        ok(
            lives {
                my $app = $mock->class->new("make-shim");
                $app->run;
            },
            "`make-shim` should not trigger any exceptions"
        ) or note($@);
        is $called, 1, "`help` command should be running.";
    };
};

describe "App::perlbrew->make_shim('foo')" => sub {
    it "should err when perlbrew is off" => sub {
        mock_perlbrew_off();

        my $dir = tempdir();
        chdir($dir);

        ok dies {
            my $app = App::perlbrew->new("make-shim", "foo");
            $app->run();
        }, qr(^ERROR:);

        ok ! -f "foo", "foo is not produced";
    };

    it "should err when 'foo' already exists" => sub {
        mock_perlbrew_use("perl-5.36.1");
        my $dir = tempdir();
        chdir($dir);
        write_file ("foo", "hello");

        ok dies {
            my $app = App::perlbrew->new("make-shim", "foo");
            $app->run();
        }, qr(^ERROR:);

        ok dies {
            my $app = App::perlbrew->new("make-shim", "-o", "foo", "bar");
           $app->run();
        }, qr(^ERROR:);
    };

    it "should produce 'foo' in the current dir" => sub {
        mock_perlbrew_use("perl-5.36.1");
        my $dir = tempdir();
        chdir($dir);

        my $app = App::perlbrew->new("make-shim", "foo");
        $app->run();

        ok -f "foo", "foo is produced under current directory.";
        my $shim_content = read_file("foo");
        diag "\nThe content of shim:\n----\n$shim_content\n----\n";
    };

    it "should produce 'foo' in the current dir" => sub {
        mock_perlbrew_use("perl-5.36.1");
        my $dir = tempdir();
        chdir($dir);

        my $app = App::perlbrew->new("make-shim", "-o", "foo", "bar");
        $app->run();

        ok -f "foo", "foo is produced under current directory.";
        my $shim_content = read_file("foo");
        diag "\nThe content of shim:\n----\n$shim_content\n----\n";
    };
};

done_testing;