File: TestUtils.pm

package info (click to toggle)
libextutils-cppguess-perl 0.27-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: perl: 742; makefile: 2
file content (98 lines) | stat: -rw-r--r-- 2,203 bytes parent folder | download | duplicates (4)
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
96
97
98
package # hide
  TestUtils;

use strict;

use ExtUtils::Manifest qw(manicopy maniread);
use File::Path qw(rmtree);
use File::Spec::Functions qw(rel2abs);
use Cwd qw(cwd);
use Fatal qw(chdir);
use Config qw();
use Capture::Tiny 'capture_merged';

require Exporter; *import = \&Exporter::import;

our @EXPORT = qw(prepare_test build_makemaker build_module_build);

sub _run_capture {
    my @cmd = @_;
    my $captured = capture_merged {
        system(@cmd);
    };
    my $status = $?;
    return($captured, $status);
}

sub prepare_test {
    my( $source, $destination ) = @_;
    my $cwd = cwd();

    $destination = rel2abs( $destination );
    rmtree( $destination );
    chdir( $source );
    manicopy( maniread(), $destination );
    chdir( $cwd );
}

sub build_module_build {
    my( $path ) = @_;
    my $cwd = cwd();
    chdir $path;

    my ($build_pl, $build_pl_ok) = _run_capture($^X, "Build.PL");

    if( $build_pl_ok != 0 ) {
        chdir( $cwd );
        return ( 0, $build_pl, undef, undef );
    }

    my ($build, $build_ok) = _run_capture($^X, "Build");

    if( $build_ok != 0 ) {
        chdir( $cwd );
        return ( 0, $build_pl, $build, undef );
    }

    my ($build_test, $build_test_ok) = _run_capture($^X, "Build", "test");

    if( $build_test_ok != 0 ) {
        chdir( $cwd );
        return ( 0, $build_pl, $build, $build_test );
    } else {
        chdir( $cwd );
        return ( 1, $build_pl, $build, $build_test );
    }
}

sub build_makemaker {
    my( $path ) = @_;
    my $cwd = cwd();
    chdir $path;

    my ($makefile_pl, $makefile_pl_ok) = _run_capture($^X, "Makefile.PL");

    if( $makefile_pl_ok != 0 ) {
        chdir( $cwd );
        return ( 0, $makefile_pl, undef, undef );
    }

    my ($make, $make_ok) = _run_capture($Config::Config{make});

    if( $make_ok != 0 ) {
        chdir( $cwd );
        return ( 0, $makefile_pl, $make, undef );
    }

    my ($make_test, $make_test_ok) = _run_capture($Config::Config{make}, "test");

    if( $make_test_ok != 0 ) {
        chdir( $cwd );
        return ( 0, $makefile_pl, $make, $make_test );
    } else {
        chdir( $cwd );
        return ( 1, $makefile_pl, $make, $make_test );
    }
}

1;