| 1 | package Test::BDD::Infrastructure::Exec; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | our $VERSION = '1.005'; # VERSION | |||||||||||
| 7 | # ABSTRACT: cucumber step definitions for checking commands | ||||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use Test::More; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 1 | ▶ | use Test::BDD::Cucumber::StepFile qw( Given When Then ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 0 | ▶ | sub S { Test::BDD::Cucumber::StepFile::S } | ||||||||||
|
Subroutine
S: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 13 | |||||||||||||
| 14 | 1 | ▶ | use Test::BDD::Infrastructure::Utils qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 1 | convert_unit convert_cmp_operator $CMP_OPERATOR_RE convert_interval); | |||||||||||
| 16 | |||||||||||||
| 17 | 1 | ▶ | use IPC::Run qw( run timeout ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | |||||||||||||
| 20 | # try to set neutral locale | ||||||||||||
| 21 | 1 | our %DEFAULT_ENV = ( | |||||||||||
| 22 | LANG => 'C', | ||||||||||||
| 23 | LC_ALL => 'C', | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | |||||||||||||
| 26 | 0 | ▶ | Given qr/^the command is (.*)$/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 27 | 0 | my @cmd = split(/\s+/, $1); | |||||||||||
| 28 | 0 | ▶ | if( ! -x $cmd[0] ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 0 | fail( $cmd[0]." is not exist or is not executable"); | |||||||||||
| 30 | } | ||||||||||||
| 31 | 0 | S->{'cmd'} = \@cmd; | |||||||||||
| 32 | 1 | }; | |||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | Given qr/^the command (?:option|parameter) (.*) is appended$/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 35 | 0 | push(@{S->{'cmd'}}, $1); | |||||||||||
| 36 | 1 | }; | |||||||||||
| 37 | |||||||||||||
| 38 | 0 | ▶ | Given qr/^the commands? timeout is (?:set to )?(\d+)(?: seconds)?$/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 39 | 0 | S->{'timeout'} = $1; | |||||||||||
| 40 | 1 | }; | |||||||||||
| 41 | |||||||||||||
| 42 | 0 | ▶ | Given qr/^the commands? environment variable (\S+) is set to (.*)$/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 43 | 0 | ▶ | if( ! defined S->{'env'} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 0 | S->{'env'} = { %DEFAULT_ENV } | |||||||||||
| 45 | } | ||||||||||||
| 46 | 0 | S->{'env'}->{$1} = $2; | |||||||||||
| 47 | 1 | }; | |||||||||||
| 48 | |||||||||||||
| 49 | 0 | ▶ | Given qr/^the commands? working directory is (.*)$/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 50 | 0 | ▶ | if( ! -e $1 ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | 0 | fail("directory $1 does no exist"); | |||||||||||
| 52 | } | ||||||||||||
| 53 | 0 | S->{'cwd'} = $1; | |||||||||||
| 54 | 1 | }; | |||||||||||
| 55 | |||||||||||||
| 56 | 0 | ▶ | When qr/^the command is (executed|run)/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 57 | 0 | ▶ | my $timeout = S->{'timeout'} || 10; | ||||||||||
|
Condition0%0/2
S()->{'timeout'} || 10
MC/DC0%0/1
S()->{'timeout'} || 10
S()->{'timeout'}
Truth table0%0/2
A
A= S()->{'timeout'}
| |||||||||||||
| 58 | 0 | ▶ | my $myenv = S->{'env'} || { %DEFAULT_ENV }; | ||||||||||
|
Condition0%0/2
S()->{'env'} || {%Test::BDD::Infrastructure::Exec::DEFAULT_ENV}
MC/DC0%0/1
S()->{'env'} || {%Test::BDD::Infrastructure::Exec::DEFAULT_ENV}
S()->{'env'}
Truth table0%0/2
A
A= S()->{'env'}
| |||||||||||||
| 59 | 0 | my $cwd = S->{'cwd'}; | |||||||||||
| 60 | 0 | my $cmd = S->{'cmd'}; | |||||||||||
| 61 | 0 | my ( $in, $out, $err ); | |||||||||||
| 62 | |||||||||||||
| 63 | run $cmd, | ||||||||||||
| 64 | 0 | ▶ | init => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 65 | 0 | ▶ | if( defined $cwd ) { chdir( $cwd ); } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | 0 | @$ENV{keys %$myenv} = values %$myenv; | |||||||||||
| 67 | 0 | }, \$in, \$out, \$err, timeout( $timeout ); | |||||||||||
| 68 | |||||||||||||
| 69 | 0 | S->{'ret'} = $?; | |||||||||||
| 70 | 0 | S->{'out'} = $out; | |||||||||||
| 71 | 0 | S->{'err'} = $err; | |||||||||||
| 72 | 1 | }; | |||||||||||
| 73 | |||||||||||||
| 74 | 0 | ▶ | Then qr/^the commands? return value must be (\d+)/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 75 | 0 | cmp_ok(S->{'ret'}, '==', $1, "the return value must be $1"); | |||||||||||
| 76 | 1 | }; | |||||||||||
| 77 | 0 | ▶ | Then qr/^the commands? return value must be $CMP_OPERATOR_RE (\d+)/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 78 | 0 | my $op = convert_cmp_operator( $1 ); | |||||||||||
| 79 | 0 | my $count = $2; | |||||||||||
| 80 | 0 | cmp_ok(S->{'ret'}, $op, $1, "the return value must be $op $1"); | |||||||||||
| 81 | 1 | }; | |||||||||||
| 82 | |||||||||||||
| 83 | 0 | ▶ | Then qr/^the commands? output must be like (.*)$/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 84 | 0 | my $regex = $1; | |||||||||||
| 85 | 0 | like( S->{'out'}, qr/$regex/, "output must be like $1"); | |||||||||||
| 86 | 1 | }; | |||||||||||
| 87 | 0 | ▶ | Then qr/^the commands? (?:error|stderr) output must be like (.*)$/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 88 | 0 | my $regex = $1; | |||||||||||
| 89 | 0 | like( S->{'err'}, qr/$regex/, "error output must be like $1"); | |||||||||||
| 90 | 1 | }; | |||||||||||
| 91 | 0 | ▶ | Then qr/^the commands? output must be empty$/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 92 | 0 | cmp_ok( S->{'out'}, 'eq', '', "output must be empty"); | |||||||||||
| 93 | 1 | }; | |||||||||||
| 94 | 0 | ▶ | Then qr/^the commands? (?:error|stderr) output must be empty$/, sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 95 | 0 | cmp_ok( S->{'err'}, 'eq', '', "error output must be empty"); | |||||||||||
| 96 | 1 | }; | |||||||||||
| 97 | |||||||||||||
| 98 | 1 | 1; | |||||||||||
| 99 | |||||||||||||
| 100 | __END__ | ||||||||||||