Test2-Tools-Command-0.20000755001750001750 014354574337 15056 5ustar00jmatesjmates000000000000Test2-Tools-Command-0.20/Build.PL000444001750001750 303514354574336 16507 0ustar00jmatesjmates000000000000#!perl # # see the README file for how to build this module use 5.10.0; use strict; use warnings; use Module::Build; Module::Build->VERSION('0.4004'); # there is also Devel::CheckOS but the use-devel-assertos script seems a # bit too complicated every time I look at it. so... if ( $^O =~ /MSWin32/ ) { say "no automated install on Windows due to test failures."; exit 0; } my $builder = Module::Build->new( module_name => 'Test2::Tools::Command', license => 'bsd', dist_author => q{Jeremy Mates }, dist_version_from => 'lib/Test2/Tools/Command.pm', release_status => 'stable', create_license => 0, create_readme => 0, dynamic_config => 0, configure_requires => { 'Module::Build' => '0.4004', }, test_requires => { 'File::Spec' => '0', 'Test2::V0' => '0.000060', }, requires => { 'perl' => '5.10.0', 'File::chdir' => '0', 'IPC::Open3' => '0', 'Symbol' => '0', 'Test2::V0' => '0', }, sign => 1, add_to_cleanup => ['Test2-Tools-Command-*'], auto_features => { dist_authoring => { description => "Create new distributions", requires => { 'Archive::Tar' => 1.09, 'Module::Signature' => 0.21, }, }, }, meta_merge => { resources => { repository => 'https://thrig.me/src/Test2-Tools-Command.git' } }, ); $builder->create_build_script(); Test2-Tools-Command-0.20/Changes000444001750001750 160614354574336 16510 0ustar00jmatesjmates000000000000Revision history for Test2-Tools-Command 0.20 2023-01-02 Add is_exit() so that Test::UnixExit can be replaced by this module. And, prevent installation on Windows due to test failures. 0.11 2023-01-01 Make better use of Test2. Fix tests such that stdout and stderr tests are actually called, maybe. Remove needless dependency on Cwd. 0.10 2022-12-31 Breaking interface changes and other such work. * Change the return values of command(). * qr// or exact string tests on stdout, stderr. * Add munge_signal for when the signal type varies. * Remove want_fh as that interacts poorly with timeout. * Improved test names for when tests fail, or the ability to specify a custom name associated with the tests. 0.01 2022-12-29 First version, released on an unsuspecting world. Test2-Tools-Command-0.20/LICENSE000444001750001750 266614354574336 16231 0ustar00jmatesjmates000000000000The BSD License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Jeremy Mates nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Test2-Tools-Command-0.20/MANIFEST000444001750001750 33214354574336 16321 0ustar00jmatesjmates000000000000Build.PL Changes LICENSE MANIFEST META.json META.yml README lib/Test2/Tools/Command.pm t/00-load.t t/10-command.t t/20-isexit.t t/pod-coverage.t t/pod.t t/unsupercilious/README SIGNATURE Added here by Module::Build Test2-Tools-Command-0.20/META.json000444001750001750 243214354574336 16634 0ustar00jmatesjmates000000000000{ "abstract" : "test simple unix commands", "author" : [ "Jeremy Mates " ], "dynamic_config" : 0, "generated_by" : "Module::Build version 0.4232", "license" : [ "bsd" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test2-Tools-Command", "prereqs" : { "configure" : { "requires" : { "Module::Build" : "0.4004" } }, "runtime" : { "requires" : { "File::chdir" : "0", "IPC::Open3" : "0", "Symbol" : "0", "Test2::V0" : "0", "perl" : "v5.10.0" } }, "test" : { "requires" : { "File::Spec" : "0", "Test2::V0" : "0.000060" } } }, "provides" : { "Test2::Tools::Command" : { "file" : "lib/Test2/Tools/Command.pm", "version" : "0.20" } }, "release_status" : "stable", "resources" : { "license" : [ "http://opensource.org/licenses/BSD-3-Clause" ], "repository" : { "url" : "https://thrig.me/src/Test2-Tools-Command.git" } }, "version" : "0.20", "x_serialization_backend" : "JSON::PP version 4.16" } Test2-Tools-Command-0.20/META.yml000444001750001750 146014354574336 16464 0ustar00jmatesjmates000000000000--- abstract: 'test simple unix commands' author: - 'Jeremy Mates ' build_requires: File::Spec: '0' Test2::V0: '0.000060' configure_requires: Module::Build: '0.4004' dynamic_config: 0 generated_by: 'Module::Build version 0.4232, CPAN::Meta::Converter version 2.150010' license: bsd meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test2-Tools-Command provides: Test2::Tools::Command: file: lib/Test2/Tools/Command.pm version: '0.20' requires: File::chdir: '0' IPC::Open3: '0' Symbol: '0' Test2::V0: '0' perl: v5.10.0 resources: license: http://opensource.org/licenses/BSD-3-Clause repository: https://thrig.me/src/Test2-Tools-Command.git version: '0.20' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Test2-Tools-Command-0.20/README000444001750001750 75514354574336 16061 0ustar00jmatesjmates000000000000Test2-Tools-Command - test simple unix commands this module can be installed using cpanm: cpanm Test2::Tools::Command run perldoc(1) on Test2::Tools::Command for documentation to author a new release: perl Build.PL RELEASE_TESTING=1 ./Build test # the CORE::dump test is not portable to CPAN Tester systems # (nor maybe beyond OpenBSD) AUTHOR_TEST_JMATES=1 ./Build testcover ./Build disttest git tag -u ... -s v... ./Build dist cpan-upload ... git push ... ./Build realclean Test2-Tools-Command-0.20/SIGNATURE000644001750001750 451714354574337 16510 0ustar00jmatesjmates000000000000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.88. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 SHA256 f46012567dae1390aad85b9106abce489aa47e1d6f224120d0c4b3e06dcb5c0a Build.PL SHA256 10f7bf2e1a9dbeecc26839c02225026f3eeb88a3dc618e092e557f39ba944209 Changes SHA256 db739608563af2d9f1763883315451cc38032cb67bdd42a443bfcc7eef1a49b2 LICENSE SHA256 b288e150e793ab4c60d8f284a6626f7069f82ed73f35f0fae7bb9a5cebb1057d MANIFEST SHA256 88ee445d9b1f7e31652671732a5121b04a2933ed365dbe7066948d483ced5c29 META.json SHA256 432e1773bb69b17df10714454959d8a6a28adb639620601a45ae1ac5c6c45b17 META.yml SHA256 5c304aa20e754fd3d25859e290a1ccc60a1d468f7cae119c0ef5982b6e22b393 README SHA256 fc846198c94fdd235b49725320a76a7e77728405c097ee0dc1caf7b548f44e60 lib/Test2/Tools/Command.pm SHA256 66a071df66b2ac7e4d280dd694c5c6b213b4fd8ea6058ea41693aa78f6b351b0 t/00-load.t SHA256 5b77457353c99f0963848c91f3e58b07f0f45e81787cda5a347626cfde574d51 t/10-command.t SHA256 551270e2c361d79ca4bf08877edd628f3425f84bb7382501c1e92b90a669192f t/20-isexit.t SHA256 b778c206d1750a566c4dc82161a7b65cd6e646a21f21bf3e438c5f770964fe1b t/pod-coverage.t SHA256 26e8eef165b3efeb88516cf0e98ea5ac2455f53e57eabc1259f9cfa6937a51a8 t/pod.t SHA256 6272a66749001b6794133357862ff2e8f1ab80fdef1eb944c22dc2e4176be2e6 t/unsupercilious/README -----BEGIN PGP SIGNATURE----- iQGzBAEBAwAdFiEElPO2YAAs9b/plKLEs1lvXE/ryKcFAmOy+N4ACgkQs1lvXE/r yKerLQwAmC9LOE1yIyTljLmOcDUzmI9TNejy55zcULZzZPPGCTWSYKaQBp6acutz kwBYd6p+9l5cyTev+pK8311217XRaRIpJh4yRryRsMC3j/YmbSm2ipgUiLxgzN9T A5UGRDDNH2Vm8NZbghk+i0RBTz+NTamy2Ih9/dGi1N9HV4CQnLpAlqxoT8hcn96/ ige5tXjadbR2MIZOfHaX3ogG0nEFjtyebPBzR74cDaKjuPkAHlNmF1JQAzaZbiCA k1E/m+6glAG1Ytod7hWRf29j8FmEtZCT6gc62idtznYGGAI4raRtrf5Q1Fo08LHE Ohg1TXOvPrY/h1npiSjx15+7QQOFh3t48j1QvJI+l197JiUgFsXaAoMNGqynplKr 6xONlSEEYNFHhlTmlAECItOG8Jv3nH7/tJcjO19Js45wrTccnNbX7RHcNfCr6V05 JzsgJHmsjkiGqD/vbU5R+xIIlMiDHaPt3zdH9SY8Z82oap2AI3CbIc68u1+CgJ3y EqxQDDi/ =mv/Y -----END PGP SIGNATURE----- Test2-Tools-Command-0.20/lib000755001750001750 014354574336 15623 5ustar00jmatesjmates000000000000Test2-Tools-Command-0.20/lib/Test2000755001750001750 014354574336 16624 5ustar00jmatesjmates000000000000Test2-Tools-Command-0.20/lib/Test2/Tools000755001750001750 014354574336 17724 5ustar00jmatesjmates000000000000Test2-Tools-Command-0.20/lib/Test2/Tools/Command.pm000444001750001750 3066414354574336 22026 0ustar00jmatesjmates000000000000# -*- Perl -*- # # run simple unix commands for expected results given particular inputs package Test2::Tools::Command; our $VERSION = '0.20'; use 5.10.0; use strict; use warnings; use File::chdir; # $CWD use IPC::Open3 'open3'; use Symbol 'gensym'; use Test2::API 'context'; use base 'Exporter'; our @EXPORT = qw(command is_exit); our @command; # prefixed on each run, followed by any ->{args} our $timeout = 30; # seconds, for alarm() sub command ($) { local $CWD = $_[0]->{chdir} if defined $_[0]->{chdir}; local @ENV{ keys %{ $_[0]->{env} } } = values %{ $_[0]->{env} }; # what to run, and possibly also a string to include in the test name my @cmd = ( @command, exists $_[0]->{args} ? @{ $_[0]->{args} } : () ); my ( $stdout, $stderr ); eval { local $SIG{ALRM} = sub { die "timeout\n" }; alarm( $_[0]->{timeout} || $timeout ); my $pid = open3( my $in, my $out, my $err = gensym, @cmd ); if ( defined $_[0]->{binmode} ) { for my $fh ( $in, $out, $err ) { binmode $fh, $_[0]->{binmode} } } if ( exists $_[0]->{stdin} ) { print $in $_[0]->{stdin}; close $in; } # this may be bad if the utility produces too much output $stdout = do { local $/; readline $out }; $stderr = do { local $/; readline $err }; waitpid $pid, 0; alarm 0; 1; } or die $@; my $orig_status = $?; # the exit status is broken out into a hashref for exact tests on # the various components of the 16-bit word (an alternative might be # to mangle it into a number like the shell does) my $status = { code => $? >> 8, signal => $? & 127, iscore => $? & 128 ? 1 : 0 }; # the munge are for when the code or signal vary (for portability or # for reasons out of your control) and you only want to know if the # value was 0 or not. lots of CPAN Tester systems did not set the # iscore flag following a CORE::dump by a test program... $status->{code} = $status->{code} ? 1 : 0 if $_[0]->{munge_status}; $status->{signal} = $status->{signal} ? 1 : 0 if $_[0]->{munge_signal}; # default exit status word is 0, but need it in hashref form if ( exists $_[0]->{status} ) { if ( !defined $_[0]->{status} ) { $_[0]->{status} = { code => 0, signal => 0, iscore => 0 }; } elsif ( ref $_[0]->{status} eq '' ) { $_[0]->{status} = { code => $_[0]->{status}, signal => 0, iscore => 0 }; } # assume that ->{status} is a hashref } else { $_[0]->{status} = { code => 0, signal => 0, iscore => 0 }; } my ( $ctx, $name, $result ) = ( context(), $_[0]->{name} // "@cmd", 1 ); if ( $_[0]->{status}{code} == $status->{code} and $_[0]->{status}{signal} == $status->{signal} and $_[0]->{status}{iscore} == $status->{iscore} ) { $ctx->pass("exit - $name"); } else { $ctx->fail( "exit - $name", sprintf( "code\t%d\tsignal\t%d\tiscore\t%d want", $_[0]->{status}{code}, $_[0]->{status}{signal}, $_[0]->{status}{iscore} ), sprintf( "code\t%d\tsignal\t%d\tiscore\t%d got", $status->{code}, $status->{signal}, $status->{iscore} ) ); $result = 0; } # qr// or assume it's a string if ( defined $_[0]->{stdout} and ref $_[0]->{stdout} eq 'Regexp' ) { if ( $stdout =~ m/$_[0]->{stdout}/ ) { $ctx->pass("stdout - $name"); } else { $ctx->fail( "stdout - $name", "expected match on $_[0]->{stdout}" ); $result = 0; } } else { my $want = $_[0]->{stdout} // ''; if ( $stdout eq $want ) { $ctx->pass("stdout - $name"); } else { $ctx->fail( "stdout - $name", "expected equality with q{$want}" ); $result = 0; } } if ( defined $_[0]->{stderr} and ref $_[0]->{stderr} eq 'Regexp' ) { if ( $stderr =~ m/$_[0]->{stderr}/ ) { $ctx->pass("stderr - $name"); } else { $ctx->fail( "stderr - $name", "expected match on $_[0]->{stderr}" ); $result = 0; } } else { my $want = $_[0]->{stderr} // ''; if ( $stderr eq $want ) { $ctx->pass("stderr - $name"); } else { $ctx->fail( "stderr - $name", "expected equality with q{$want}" ); $result = 0; } } $ctx->release; return $result, $orig_status, \$stdout, \$stderr; } sub is_exit ($;$$) { my ( $exit, $expect, $name ) = @_; $name //= 'exit status'; if ( !defined $expect ) { $expect = { code => 0, signal => 0, iscore => 0 }; } elsif ( ref $expect eq '' ) { $expect = { code => $expect, signal => 0, iscore => 0 }; } my $status = { code => $exit >> 8, signal => $exit & 127, iscore => $exit & 128 ? 1 : 0 }; $status->{code} = $status->{code} ? 1 : 0 if $expect->{munge_status}; $status->{signal} = $status->{signal} ? 1 : 0 if $expect->{munge_signal}; my ( $ctx, $result ) = ( context(), 1 ); if ( $expect->{code} == $status->{code} and $expect->{signal} == $status->{signal} and $expect->{iscore} == $status->{iscore} ) { $ctx->pass($name); } else { $ctx->fail( $name, sprintf( "code\t%d\tsignal\t%d\tiscore\t%d want", $expect->{code}, $expect->{signal}, $expect->{iscore} ), sprintf( "code\t%d\tsignal\t%d\tiscore\t%d got", $status->{code}, $status->{signal}, $status->{iscore} ) ); $result = 0; } $ctx->release; return $result; } 1; __END__ =head1 NAME Test2::Tools::Command - test simple unix commands =head1 SYNOPSIS use Test2::Tools::Command; # test some typical unix tools; implicit checks are that status # is 0, and that stdout and stderr are the empty string, unless # otherwise specified command { args => [ 'true' ] }; command { args => [ 'false' ], status => 1 }; command { args => [ 'echo', 'foo' ], stdout => "foo\n" }; # subsequent args are prefixed with this local @Test2::Tools::Command::command = ( 'perl', '-E' ); # return values and a variety of the options available my ($result, $exit_status, $stdout_ref, $stderr_ref) = command { args => [ q{say "out";warn "err";kill TERM => $$} ], chdir => '/some/dir', env => { API_KEY => 42 }, stdin => "printed to program\n", stdout => qr/out/, stderr => qr/err/, status => { code => 0, signal => 15, iscore => 0 }, timeout => 7 }; # check on a $? exit status word from somewhere is_exit $?, 42; is_exit $?, { code => 0, signal => 9, iscore => 0 }; =head1 DESCRIPTION This module tests that commands given particular arguments result in particular outputs by way of the exit status word, standard output, and standard error. Various parameters to the B function alter exactly how this is done, in addition to variables that can be set. The commands are expected to be simple, for example filters that maybe accept standard input and respond with some but not too much output. Interactive or otherwise complicated commands will need some other module such as L to test them, as will programs that generate too much output. Also, B is provided to check on the 16-bit exit status word from other code. =head1 VARIABLES These are not exported. =over 4 =item B<@command> Custom command to prefix any commands run by B with, for example to specify a test program that will be used in many subsequent tests local @Test2::Tools::Command::command = ($^X, '--', 'bin/foo'); command { args => [ 'bar', '-c', 'baz' ] }; will result in C being run. If I is used, a command that uses a relative path may need to be fully qualified, e.g. with C of L. =item B<$timeout> Seconds after which commands will be timed out via C if a I is not given to B. 30 by default. =back =head1 FUNCTIONS B is exported by default; this can be disabled by using this module with an empty import list. The test keys are I, I, and I. The other keys influence how the command is run or change test metadata. =over 4 =item B I Runs a command and executes one or more tests on the results, depending on the contents of I, which may contain: =over 4 =item I => I List of arguments to run the command with. The argument list will be prefixed by the B<@command> variable, if that is set. =item I => I If set, I will be set on the filehandles wired to the command via the C function. See also L. =item I => I Attempt to C into I or failing that will throw an exception, by way of L. A command that uses a relative path may need to be fully qualified, e.g. with C of L. =item I => I Set the environment for the command to include the keys and values present in I. This is additive only; environment variables that must not be set must be deleted from C<%ENV>, or the command wrapped with a command that can reset the environment, such as L. =item I => I Custom name for the tests. Otherwise, the full command executed is used in the test name, which may not be ideal. =item I => I If the signal number of the 16-bit exit status word is not zero, the signal will be munged to have the value C<1>. =item I => I If the exit code of the 16-bit exit status word is not zero, the code will be munged to have the value C<1>. Use this where the program being tested is unpredictable as to what non-zero exit code it will use. =item I => I Expect the given value as the 16-bit exit status word. By default C<0> for the exit code is assumed. This can be specified in two different forms; the following two are equivalent: status => 42 status => { code => 42, iscore => 0, signal => 0 } Obviously the 16-bit exit status word is decomposed into a hash reference. If the program is instead expected to exit by a SIGPIPE, one might use: status => { code => 0, iscore => 0, signal => 13 } See also I and I. =item I => I If present, I will be printed to the command and then standard input will be closed. Otherwise, nothing is done with standard input. =item I => I Expect that the standard output of the command exactly matches the given string, or if the string is a C regular expression, that the output matches that expression. =item I => I Expect that the standard err of the command exactly matches the given string, or if the string is a C regular expression, that the stderr matches that expression. =item I => I Set a custom timeout for the C call that wraps the command. The variable B<$timeout> will be used if this is unset. =back B returns a list consisting of the result of the tests, the original 16-bit exit status word, and scalar references to strings that contain the standard output and standard error of the test program, if any. my ($result, $status, $out_ref, $err_ref) = command { ... =item B I [ I [ I ] ] This routine checks that a 16-bit exit status word (usually by way of the C<$?> variable) conforms to some code or hash reference. The hash reference may contain I and I that will turn non-zero signal or codes into C<1>. is_exit $?, 42; is_exit $?, { code => 0, signal => 9, iscore => 0 }; =back =head1 BUGS None known. There are probably portability problems if you stray from the unix path. =head1 SEE ALSO L L may be necessary to test complicated programs. L is used to run programs; this may run into portability problems on systems that stray from the way of unix? =head1 COPYRIGHT AND LICENSE Copyright 2022 Jeremy Mates This program is distributed under the (Revised) BSD License: L =cut Test2-Tools-Command-0.20/t000755001750001750 014354574336 15320 5ustar00jmatesjmates000000000000Test2-Tools-Command-0.20/t/00-load.t000444001750001750 56714354574336 16766 0ustar00jmatesjmates000000000000#!perl use Test2::V0; my @modules = <<'EOM' =~ m/([A-Z][A-Za-z0-9:]+)/g; Test2::Tools::Command EOM my $loaded = 0; for my $m (@modules) { local $@; eval "require $m"; if ($@) { bail_out "require failed '$m': $@" } $loaded++; } diag "Testing Test2::Tools::Command $Test2::Tools::Command::VERSION, Perl $], $^X"; is $loaded, scalar @modules; done_testing; Test2-Tools-Command-0.20/t/10-command.t000444001750001750 1042214354574336 17515 0ustar00jmatesjmates000000000000#!perl # # test that command() is less horribly buggy than it has been # # NOTE with chdir a relative command (e.g. "./bin/foo") may need to be # fully qualified with something like rel2abs of File::Spec::Functions. # perl scripts may need to be called via $^X, '--', './bin/foo' to use # the correct perl and to turn off perl's command line switches use File::Spec::Functions qw(catdir splitdir); # srand produces noise on test failure and isn't really relevant to any # of the tests here use Test2::V0 -no_srand => 1; use Test2::Tools::Command; use Test2::API 'intercept'; # an exact plan is annoying, but will catch the case where some of the # tests are unexpectedly not running, as was the case in version 0.10 of # this module plan 29; # including the PID is not necessary but helps avoid the program being # tested cheating on the test by simply regurgitating a static input $ENV{FOO} = "bar$$"; my $barout = "bar$$\n"; my ( $ok, $status, $out, $err ) = command { args => [ $^X, '-E', 'say $ENV{FOO};warn "err\n"' ], stdout => $barout, stderr => "err\n", }; # do not waste CPU if we cannot run the first program (opinions # vary here; another school of thought is to keep going for as long # as possible) bail_out "cannot even run perl??" unless $ok; is $status, 0; is $$out, $barout; is $$err, "err\n"; # prefix the subsequent {args} with ... @Test2::Tools::Command::command = ( $^X, '-E' ); # sometimes extra tests will need to be made on the output if it does # not fit neatly into a qr// or exact string match $out = ( command { args => ['use Cwd; print getcwd, "\0"; say $ENV{FOO}; warn readline'], binmode => ':encoding(UTF-8)', chdir => catdir(qw{t unsupercilious}), env => { FOO => "ZZZ$$" }, stdin => "baz$$\n", # emits via stderr stdout => qr/ZZZ$$/, # custom ENV, hopefully stderr => qr/baz$$/, } )[2]; if ( $$out =~ m/^([^\0]+)/ ) { my @dirs = splitdir $1; is $dirs[-1], 'unsupercilious'; } else { diag sprintf "%vx", $$out; bail_out 'did not match getcwd??'; } # this also tests the case that {args} is unset for coverage { local @Test2::Tools::Command::command = ( $^X, '-e', 'sleep 99' ); like dies { command { timeout => 1 } }, qr/timeout/; } command { args => ['kill TERM => $$'], status => { code => 0, iscore => 0, signal => 1 }, munge_signal => 1, }; my $rand_status = 42 + int rand 42; command { args => ["say q{out$$}; warn qq{err\n}; exit $rand_status"], munge_status => 1, status => 1, stdout => "out$$\n", stderr => "err\n" }; # PORTABILITY the signal may vary here, this is for OpenBSD 7.2. because # lots of CPAN Tester systems fail here, this has been made author-only SKIP: { skip( "no author tests", 3 ) unless $ENV{AUTHOR_TEST_JMATES}; command { args => ['CORE::dump'], status => { code => 0, iscore => 1, signal => 6 }, }; unlink 'perl.core'; } command { args => ['exit 0'], munge_status => 1, munge_signal => 1, status => undef, timeout => 0, }; # PORTABILITY the error message depends on File::chdir like dies { command { args => ['exit 0'], chdir => "no/such/dir/$$/unless/someone/mkdir/this", } }, qr/Failed to change directory/; # TODO failing on chdir back to $orig_dir that no longer exists might be # tricky, and anyways that's a problem for File::chdir to handle # failure is an option: what do test errors look like? (they were not # very good in version 0.01) #command { args => [q(say "out";warn "err\n"; exit 1)] }; # who tests the tests? coverage for failed test branches (which exposed # a bug or two...) my $events = intercept { command { args => ['say "out";warn "err\n";exit 23'], name => "stringy" }; command { name => "regexy", args => ['say "out";warn "err\n";exit 51'], stdout => qr/doesnotmatch/, stderr => qr/doesnotmatch/ }; }; my $state = $events->state; is $state->{failed}, 6; for my $e ( $events->event_list ) { if ( $e->name =~ m/^std.*stringy/ ) { is $e->info->[0]->details, 'expected equality with q{}'; } elsif ( $e->name =~ m/^std.*regexy/ ) { like $e->info->[0]->details, qr/expected match.*doesnotmatch/; } } Test2-Tools-Command-0.20/t/20-isexit.t000444001750001750 130314354574336 17363 0ustar00jmatesjmates000000000000#!perl # # tests for is_exit use Test2::V0 -no_srand => 1; use Test2::Tools::Command; use Test2::API 'intercept'; plan 9; is_exit 0; is_exit 24 << 8, 24; is_exit 42 << 8, { code => 42, signal => 0, iscore => 0 }, "exit 42"; is_exit 42 << 8, { code => 1, signal => 0, iscore => 0, munge_status => 1 }; is_exit 0, { code => 0, signal => 0, iscore => 0, munge_status => 1 }; is_exit 6 | 128, { code => 0, signal => 6, iscore => 1 }; is_exit 6 | 128, { code => 0, signal => 1, iscore => 1, munge_signal => 1 }; is_exit 0, { code => 0, signal => 0, iscore => 0, munge_signal => 1 }; my $events = intercept { is_exit 0, { code => 0, signal => 0, iscore => 1 } }; is $events->state->{failed}, 1; Test2-Tools-Command-0.20/t/pod-coverage.t000444001750001750 123114354574336 20212 0ustar00jmatesjmates000000000000#!perl use Test2::V0; unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } # Ensure a recent version of Test::Pod::Coverage my $min_tpc = 1.08; eval "use Test::Pod::Coverage $min_tpc"; plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" if $@; # Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, # but older versions don't recognize some common documentation styles my $min_pc = 0.18; eval "use Pod::Coverage $min_pc"; plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" if $@; all_pod_coverage_ok( { trustme => [qr/BUILD/] } ); Test2-Tools-Command-0.20/t/pod.t000444001750001750 46514354574336 16411 0ustar00jmatesjmates000000000000#!perl use Test2::V0; unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } # Ensure a recent version of Test::Pod my $min_tp = 1.22; eval "use Test::Pod $min_tp"; plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; all_pod_files_ok(); Test2-Tools-Command-0.20/t/unsupercilious000755001750001750 014354574336 20411 5ustar00jmatesjmates000000000000Test2-Tools-Command-0.20/t/unsupercilious/README000444001750001750 3014354574336 21357 0ustar00jmatesjmates000000000000mostly for a chdir test