File: installation2.t

package info (click to toggle)
perlbrew 0.78-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 708 kB
  • sloc: perl: 6,291; makefile: 6
file content (93 lines) | stat: -rw-r--r-- 3,060 bytes parent folder | download
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
#!/usr/bin/env perl
use strict;
use warnings;

use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
use Test::Exception;
require 'test_helpers.pl';

use Test::Spec;

## setup

##

note "PERLBREW_ROOT set to $ENV{PERLBREW_ROOT}";

describe "App::perlbrew" => sub {
    describe "->do_install_url method" => sub {
        it "should accept an URL to perl tarball, and download the tarball." => sub {
            my $app = App::perlbrew->new;

            my @expectations;
            push @expectations, App::perlbrew->expects("http_download")->returns(0);
            push @expectations, $app->expects("do_extract_tarball")->returns("");
            push @expectations, $app->expects("do_install_this")->returns("");

            $app->do_install_url("http://example.com/perl-5.14.0.tar.gz");

            for(@expectations) {
                ok $_->verify;
            }
            pass;
        }
    };

    describe "->do_install_archive method" => sub {
        it "accepts a path to perl tarball and perform installation process." => sub {
            my $app = App::perlbrew->new;

            my $e1 = $app->expects("do_extract_tarball")->returns("/a/fake/path/to/perl-5.12.3");
            my $e2 = $app->expects("do_install_this")->returns("");

            $app->do_install_archive("/a/fake/path/to/perl-5.12.3.tar.gz");

            ok $e1->verify, "do_extract_tarball is called";
            ok $e2->verify, "do_install_this is called";
            pass;
        }
    };
    
    describe "->do_install_this method" => sub {
        it "should log successful brews to the log_file." => sub {
            my $app = App::perlbrew->new;
            $app->{dist_extracted_dir} = '';
            $app->{dist_name} = '';
            
            my %expectations = (
                'do_system' => $app->expects("do_system")->returns(1),
            );
            
            $app->do_install_this('', '5.12.3', 'perl-5.12.3');
            open(my $log_handle, '<', $app->{log_file});
            like(<$log_handle>, qr/##### Brew Finished #####/, 'Success message shows in log');

            foreach my $sub_name (keys %expectations) {
                ok $expectations{$sub_name}->verify, "$sub_name is called";
            }
        };
        
        it "should log brew failure to the log_file if system call fails." => sub {
            my $app = App::perlbrew->new;
            $app->{dist_extracted_dir} = '';
            $app->{dist_name} = '';

            my %expectations = (
                'do_system' => $app->expects("do_system")->returns(0),
            );
            
            throws_ok( sub {$app->do_install_this('', '5.12.3', 'perl-5.12.3')}, qr/Installation process failed/);
            open(my $log_handle, '<', $app->{log_file});
            like(<$log_handle>, qr/##### Brew Failed #####/, 'Failure message shows in log');

            foreach my $sub_name (keys %expectations) {
                ok $expectations{$sub_name}->verify, "$sub_name is called";
            }
        };
    }

};

runtests unless caller;