| 1 | ## no critic: (Modules::ProhibitAutomaticExportation) | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | package Test::Data::Unixish; | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 42 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 42 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 42 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 42 | ▶ | use Data::Unixish qw(aiduxa); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 42 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 42 | ▶ | use File::Which qw(which); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 42 | ▶ | use IPC::Cmd qw(run_forked); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 42 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 42 | ▶ | use Module::Load; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 42 | ▶ | use String::ShellQuote; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 42 | ▶ | use Test::More 0.96; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 42 | our @EXPORT = qw(test_dux_func); | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 42 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||
| 21 | 42 | our $DATE = '2025-02-24'; # DATE | |||||||||||||||||||||||||||||||
| 22 | 42 | our $DIST = 'Data-Unixish'; # DIST | |||||||||||||||||||||||||||||||
| 23 | 42 | our $VERSION = '1.574'; # VERSION | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 42 | my $json = JSON::MaybeXS->new->allow_nonref; | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 38 | ▶ | sub test_dux_func { | ||||||||||||||||||||||||||||||
|
Subroutine
test_dux_func: called CC=2 SCAR=7.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 29 | 42 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 38 | my %args = @_; | |||||||||||||||||||||||||||||||
| 32 | 38 | my $fn = $args{func}; | |||||||||||||||||||||||||||||||
| 33 | 38 | my $fnl = $fn; $fnl =~ s/.+:://; | |||||||||||||||||||||||||||||||
| 34 | 38 | load "Data::Unixish::$fn"; | |||||||||||||||||||||||||||||||
| 35 | 38 | my $f = "Data::Unixish::$fn\::$fnl"; | |||||||||||||||||||||||||||||||
| 36 | 38 | my $spec = \%{"Data::Unixish::$fn\::SPEC"}; | |||||||||||||||||||||||||||||||
| 37 | 38 | my $meta = $spec->{$fn}; | |||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 38 | ▶ | $meta or die "BUG: func $fn not found or does not have meta"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 38 | my $i = 0; | |||||||||||||||||||||||||||||||
| 42 | 38 | ▶ | subtest $fn => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.8
| |||||||||||||||||||||||||||||||||
| 43 | TEST: | ||||||||||||||||||||||||||||||||
| 44 | 38 | for my $t (@{$args{tests}}) { | |||||||||||||||||||||||||||||||
| 45 | 84 | $i++; | |||||||||||||||||||||||||||||||
| 46 | 84 | ▶ | my $tn = $t->{name} // "test[$i]"; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$t->{"name"} // "test[$i]"
MC/DC100%1/1
$t->{"name"} // "test[$i]"
$t->{"name"}
Truth table100%2/2
A
A= $t->{"name"}
| |||||||||||||||||||||||||||||||||
| 47 | 84 | ▶ | subtest $tn => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=21.8
| |||||||||||||||||||||||||||||||||
| 48 | 84 | ▶ | if ($t->{skip}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 1 | my $msg = $t->{skip}->(); | |||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | plan skip_all => $msg if $msg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | # test func | ||||||||||||||||||||||||||||||||
| 54 | 83 | ▶ | if ($t->{skip_func}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | 0 | diag "func test skipped"; | |||||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||||||
| 57 | 83 | ▶ | subtest "func" => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=25.5
| |||||||||||||||||||||||||||||||||
| 58 | 83 | my $in = $t->{in}; | |||||||||||||||||||||||||||||||
| 59 | 83 | my $out = $t->{out}; | |||||||||||||||||||||||||||||||
| 60 | 83 | my $rout = []; | |||||||||||||||||||||||||||||||
| 61 | 83 | my $res; | |||||||||||||||||||||||||||||||
| 62 | 83 | eval { $res = $f->(in=>$in,out=>$rout,%{$t->{args}}) }; | |||||||||||||||||||||||||||||||
| 63 | 83 | my $err = $@; | |||||||||||||||||||||||||||||||
| 64 | 83 | ▶ | if ($t->{func_dies} // $t->{dies} // 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
($t->{"func_dies"} // $t->{"dies"}) // 0
$t->{"func_dies"} // $t->{"dies"}
MC/DC50%1/2
($t->{"func_dies"} // $t->{"dies"}) // 0
$t->{"func_dies"}
$t->{"dies"}
Truth table66%2/3
A // B
A= $t->{"func_dies"}B= $t->{"dies"}
| |||||||||||||||||||||||||||||||||
| 65 | 3 | ok($err, "dies"); | |||||||||||||||||||||||||||||||
| 66 | 3 | return; | |||||||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||||||
| 68 | 80 | ▶ | ok(!$err, "doesn't die") or do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | 0 | diag "func dies: $err"; | |||||||||||||||||||||||||||||||
| 70 | 0 | return; | |||||||||||||||||||||||||||||||
| 71 | }; | ||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | 80 | is($res->[0], 200, "status"); | |||||||||||||||||||||||||||||||
| 74 | 80 | ▶ | if ($t->{test_out}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | 1 | $t->{test_out}->($rout); | |||||||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||||||
| 77 | 79 | ▶ | is_deeply($rout, $out, "out") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | or diag explain $rout; | ||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | # if itemfunc, test against each item | ||||||||||||||||||||||||||||||||
| 82 | 80 | ▶ | if ((grep {$_ eq 'itemfunc'} @{$meta->{tags}}) && | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
grep {$_ eq "itemfunc";} @{$$meta{"tags"};} and ref $in eq "ARRAY"
MC/DC50%1/2
grep {$_ eq "itemfunc";} @{$$meta{"tags"};} and ref $in eq "ARRAY"
grep {$_ eq "itemfunc";} @{$$meta{"tags"};}
ref $in eq "ARRAY"
Truth table66%2/3
A and B
A= grep {$_ eq "itemfunc";} @{$$meta{"tags"};}B= ref $in eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 83 | ref($in) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
| 84 | 54 | ▶ | if ($t->{skip_itemfunc}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 3 | diag "itemfunc test skipped"; | |||||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||||||
| 87 | 51 | my $rout; | |||||||||||||||||||||||||||||||
| 88 | 51 | $rout = aiduxa([$fn, $t->{args}], $in); | |||||||||||||||||||||||||||||||
| 89 | 51 | ▶ | if ($t->{test_out}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | 0 | $t->{test_out}->($rout); | |||||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||||||
| 92 | 51 | ▶ | is_deeply($rout, $out, "out (itemfunc)") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 93 | or diag explain $rout; | ||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | 83 | }; | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | # test running through cmdline | ||||||||||||||||||||||||||||||||
| 101 | 83 | ▶ | if ($t->{skip_cli} // 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$t->{"skip_cli"} // 1
MC/DC100%1/1
$t->{"skip_cli"} // 1
$t->{"skip_cli"}
Truth table100%2/2
A
A= $t->{"skip_cli"}
| |||||||||||||||||||||||||||||||||
| 102 | #diag "cli test skipped"; | ||||||||||||||||||||||||||||||||
| 103 | } else { | ||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | subtest cli => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=39.3
| |||||||||||||||||||||||||||||||||
| 105 | 3 | ▶ | if ($^O =~ /win/i) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | 0 | plan skip_all => "run_forked() not available ". | |||||||||||||||||||||||||||||||
| 107 | "on Windows"; | ||||||||||||||||||||||||||||||||
| 108 | 0 | return; | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | 3 | ▶ | unless (which("dux")) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | 3 | plan skip_all => "dux command-line not available, ". | |||||||||||||||||||||||||||||||
| 112 | "you might want to install App::dux first"; | ||||||||||||||||||||||||||||||||
| 113 | 0 | return; | |||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | my $cmd = "dux $fn ". | ||||||||||||||||||||||||||||||||
| 116 | join(" ", map { | ||||||||||||||||||||||||||||||||
| 117 | 0 | my $v = $t->{args}{$_}; | |||||||||||||||||||||||||||||||
| 118 | 0 | my $p = $_; $p =~ s/_/-/g; | |||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | ref($v) ? | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 120 | ("--$p-json", | ||||||||||||||||||||||||||||||||
| 121 | shell_quote($json->encode($v))) : | ||||||||||||||||||||||||||||||||
| 122 | ("--$p", shell_quote($v)) | ||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | 0 | keys %{ $t->{args} }); | |||||||||||||||||||||||||||||||
| 125 | #diag "cmd: $cmd"; | ||||||||||||||||||||||||||||||||
| 126 | my %runopts = ( | ||||||||||||||||||||||||||||||||
| 127 | 0 | child_stdin => join("", map {"$_\n"} @{ $t->{in} }), | |||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||
| 129 | 0 | my $res = run_forked($cmd, \%runopts); | |||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($t->{cli_dies} // $t->{dies} // 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
($t->{"cli_dies"} // $t->{"dies"}) // 0
$t->{"cli_dies"} // $t->{"dies"}
MC/DC0%0/2
($t->{"cli_dies"} // $t->{"dies"}) // 0
$t->{"cli_dies"}
$t->{"dies"}
Truth table0%0/3
A // B
A= $t->{"cli_dies"}B= $t->{"dies"}
| |||||||||||||||||||||||||||||||||
| 131 | 0 | ok($res->{exit_code}, "dies"); | |||||||||||||||||||||||||||||||
| 132 | 0 | return; | |||||||||||||||||||||||||||||||
| 133 | } else { | ||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | ok(!$res->{exit_code}, "doesn't die") or do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 135 | 0 | diag "dux dies ($res->{exit_code})"; | |||||||||||||||||||||||||||||||
| 136 | 0 | return; | |||||||||||||||||||||||||||||||
| 137 | }; | ||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | 0 | is_deeply(join("", map {"$_\n"} @{ $t->{out} }), | |||||||||||||||||||||||||||||||
| 140 | 0 | $res->{stdout}, "output"); | |||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | 3 | } | |||||||||||||||||||||||||||||||
| 143 | 84 | }; | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | 38 | }; | |||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 42 | 1; | |||||||||||||||||||||||||||||||
| 149 | # ABSTRACT: Routines to test Data::Unixish | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||||||||||||||