| 1 | # | ||||||||||
| 2 | # This file is part of Test-Apocalypse | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is copyright (c) 2014 by Apocalypse. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||
| 8 | # | ||||||||||
| 9 | 38 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | package Test::Apocalypse::PPPort; | ||||||||||
| 11 | 38 | $Test::Apocalypse::PPPort::VERSION = '1.006'; | |||||||||
| 12 | 38 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 38 | $Test::Apocalypse::PPPort::AUTHORITY = 'cpan:APOCAL'; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | # ABSTRACT: Plugin to test for Devel::PPPort warnings | ||||||||||
| 17 | |||||||||||
| 18 | 38 | ▶ | use Test::More; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 38 | ▶ | use Devel::PPPort 3.19; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 38 | ▶ | use Capture::Tiny 0.10 qw( capture_merged ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 37 | ▶ | sub _do_automated { 0 } | ||||||||
|
Subroutine
_do_automated: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub do_test { | ||||||||
|
Subroutine
do_test: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||
| 25 | 0 | plan tests => 2; | |||||||||
| 26 | |||||||||||
| 27 | # do we have an existing ppport.h file? | ||||||||||
| 28 | 0 | my $haveppport = 0; | |||||||||
| 29 | 0 | my $needstrip = 0; | |||||||||
| 30 | 0 | my $ppp = 'ppport.h'; | |||||||||
| 31 | SKIP: { | ||||||||||
| 32 | 0 | ▶ | if ( ! -f $ppp ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | # generate our own ppport.h file | ||||||||||
| 34 | 0 | Devel::PPPort::WriteFile( $ppp ); | |||||||||
| 35 | |||||||||||
| 36 | 0 | skip( "Distro did not come with a $ppp file", 1 ); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 0 | $haveppport++; | |||||||||
| 40 | |||||||||||
| 41 | # was it already stripped or not? | ||||||||||
| 42 | 0 | ▶ | my $oldver = capture_merged { system( $^X, $ppp, '--version' ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | 0 | ▶ | if ( length $oldver ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | ▶ | if ( $oldver =~ /^This is ppport\.h ([\d\.]+)$/ms ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | fail( "$ppp file needs to be stripped" ); | |||||||||
| 46 | } else { | ||||||||||
| 47 | 0 | $needstrip++; | |||||||||
| 48 | 0 | pass( "$ppp file was already stripped" ); | |||||||||
| 49 | } | ||||||||||
| 50 | } else { | ||||||||||
| 51 | 0 | die "Unable to run $ppp and get the output"; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | # remove it and create a new one so we have the latest one, always | ||||||||||
| 55 | 0 | ▶ | unlink( $ppp ) or die "Unable to unlink '$ppp': $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | Devel::PPPort::WriteFile( $ppp ); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | # Then, we run it :) | ||||||||||
| 60 | 0 | ▶ | my $result = capture_merged { system( $^X, $ppp ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | if ( length $result ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | # Did we have any xs files? | ||||||||||
| 64 | 0 | ▶ | if ( $result =~ /^No input files given/m ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | pass( 'No XS files detected' ); | |||||||||
| 66 | } else { | ||||||||||
| 67 | # is the last line saying "OK" ? | ||||||||||
| 68 | 0 | ▶ | if ( $result =~ /Looks good$/m ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | # Did we get any warnings? Display them in case they're useful... | ||||||||||
| 70 | 0 | my @warns; | |||||||||
| 71 | 0 | foreach my $l ( split( "\n", $result ) ) { | |||||||||
| 72 | 0 | ▶ | if ( $l =~ /^\*\*\*\s+WARNING:\s+/s ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | push( @warns, $l ); | |||||||||
| 74 | } | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | if ( @warns ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | pass( "$ppp says you are good to go with some warnings" ); | |||||||||
| 79 | 0 | diag( $_ ) for @warns; | |||||||||
| 80 | } else { | ||||||||||
| 81 | 0 | pass( "$ppp says you are good to go" ); | |||||||||
| 82 | } | ||||||||||
| 83 | } else { | ||||||||||
| 84 | 0 | fail( "$ppp caught some errors" ); | |||||||||
| 85 | 0 | diag( $result ); | |||||||||
| 86 | } | ||||||||||
| 87 | } | ||||||||||
| 88 | } else { | ||||||||||
| 89 | 0 | die "Unable to run $ppp and get the output"; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | # remove our generated ppport.h file | ||||||||||
| 93 | 0 | ▶ | if ( ! $haveppport ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | ▶ | unlink( $ppp ) or die "Unable to unlink '$ppp': $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | } else { | ||||||||||
| 96 | 0 | ▶ | if ( $needstrip ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | ▶ | $result = capture_merged { system( $^X, $ppp, '--strip' ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 98 | 0 | ▶ | if ( length $result ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | 0 | die "Unable to strip $ppp file: $result"; | |||||||||
| 100 | } | ||||||||||
| 101 | } | ||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 0 | return; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 38 | 1; | |||||||||
| 108 | |||||||||||
| 109 | __END__ | ||||||||||