Test-Command-Simple-0.05000755020535020535 012535213630 15671 5ustar00dmcbridedmcbride000000000000Test-Command-Simple-0.05/Makefile.PL000444020535020535 54012535213630 17757 0ustar00dmcbridedmcbride000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.4204 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'Test::Command::Simple', 'VERSION_FROM' => 'lib/Test/Command/Simple.pm', 'PREREQ_PM' => { 'Test::More' => 0 }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; Test-Command-Simple-0.05/MANIFEST.SKIP000444020535020535 7012535213630 17661 0ustar00dmcbridedmcbride000000000000^MYMETA.yml$ ^_build/ ~$ \.bak$ ^blib/ tar\.gz$ ^Build$ Test-Command-Simple-0.05/Build.PL000444020535020535 102712535213630 17322 0ustar00dmcbridedmcbride000000000000use strict; use warnings; use Module::Build; die("No support for OS\n") if $^O =~ /^mswin/i; my $builder = Module::Build->new( module_name => 'Test::Command::Simple', license => 'perl', dist_author => q{Darin McBride }, dist_version_from => 'lib/Test/Command/Simple.pm', build_requires => { 'Test::More' => 0, }, add_to_cleanup => [ 'Test-Command-Simple-*' ], create_makefile_pl => 'traditional', ); $builder->create_build_script(); Test-Command-Simple-0.05/META.json000444020535020535 162612535213630 17454 0ustar00dmcbridedmcbride000000000000{ "abstract" : "Test external commands (nearly) as easily as loaded modules.", "author" : [ "Darin McBride " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4204", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Test-Command-Simple", "prereqs" : { "build" : { "requires" : { "Test::More" : "0" } }, "configure" : { "requires" : { "Module::Build" : "0.42" } } }, "provides" : { "Test::Command::Simple" : { "file" : "lib/Test/Command/Simple.pm", "version" : "0.05" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.05" } Test-Command-Simple-0.05/ignore.txt000444020535020535 17212535213630 20032 0ustar00dmcbridedmcbride000000000000blib* Makefile Makefile.old Build Build.bat _build* pm_to_blib* *.tar.gz .lwpcookies cover_db pod2htm*.tmp Test-Command-* Test-Command-Simple-0.05/Changes000444020535020535 115512535213630 17323 0ustar00dmcbridedmcbride000000000000Revision history for Test-Command-Simple 0.05 2015-Jun-07 ! It does work on darwin, though. ! Fix the NAME of the module in the POD. ! Fix export of exit_status. 0.04 2012-Nov-29 ! This method of running subcommands doesn't work hot on Windows (except cygwin). Instead of hanging the cpantesters, we'll instead drop the platform altogether. 0.03 2010-Nov-23 + Add stdin for run function. 0.02 2010-Nov-17 ! Unfortunately clobbered existing module, renamed. 0.01 2010-Nov-17 First version, released on an unsuspecting world. Test-Command-Simple-0.05/META.yml000444020535020535 111312535213630 17273 0ustar00dmcbridedmcbride000000000000--- abstract: 'Test external commands (nearly) as easily as loaded modules.' author: - 'Darin McBride ' build_requires: Test::More: 0 configure_requires: Module::Build: 0.42 dynamic_config: 1 generated_by: 'Module::Build version 0.4204, CPAN::Meta::Converter version 2.133380' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Test-Command-Simple provides: Test::Command::Simple: file: lib/Test/Command/Simple.pm version: 0.05 resources: license: http://dev.perl.org/licenses/ version: 0.05 Test-Command-Simple-0.05/README000444020535020535 265112535213630 16712 0ustar00dmcbridedmcbride000000000000Test-Command-Simple This test module is intended to simplify testing of external commands. It does so by running the command under IPC::Open3, closing the stdin immediately, and reading everything from the command's stdout and stderr. It then makes the output available to be tested. It is not (yet?) as feature-rich as Test::Cmd, but I think the interface to this is much simpler. Tests also plug directly into the Test::Builder framework, which plays nice with Test::More. INSTALLATION To install this module, run the following commands: perl Build.PL ./Build ./Build test ./Build install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc Test::Command You can also look for information at: RT, CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Command-Simple AnnoCPAN, Annotated CPAN documentation http://annocpan.org/dist/Test-Command-Simple CPAN Ratings http://cpanratings.perl.org/d/Test-Command-Simple Search CPAN http://search.cpan.org/dist/Test-Command-Simple/ LICENSE AND COPYRIGHT Copyright (C) 2010 Darin McBride This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. Test-Command-Simple-0.05/MANIFEST000444020535020535 30612535213630 17136 0ustar00dmcbridedmcbride000000000000Build.PL Changes ignore.txt lib/Test/Command/Simple.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml README t/00-load.t t/01-run.t t/manifest.t t/pod-coverage.t t/pod.t META.json Test-Command-Simple-0.05/lib000755020535020535 012535213630 16437 5ustar00dmcbridedmcbride000000000000Test-Command-Simple-0.05/lib/Test000755020535020535 012535213630 17356 5ustar00dmcbridedmcbride000000000000Test-Command-Simple-0.05/lib/Test/Command000755020535020535 012535213630 20734 5ustar00dmcbridedmcbride000000000000Test-Command-Simple-0.05/lib/Test/Command/Simple.pm000444020535020535 1522112535213630 22701 0ustar00dmcbridedmcbride000000000000package Test::Command::Simple; use warnings; use strict; =head1 NAME Test::Command::Simple - Test external commands (nearly) as easily as loaded modules. =head1 VERSION Version 0.05 =cut our $VERSION = '0.05'; use base 'Test::Builder::Module'; use IPC::Open3; use IO::Select; use Symbol qw(gensym); use Scalar::Util qw(looks_like_number); our @EXPORT = qw( run stdout stderr rc run_ok exit_status ); =head1 SYNOPSIS use Test::Command::Simple; run('echo', 'has this output'); # only tests that the command can be started, not checking rc is(rc,0,'Returned successfully') like(stdout,qr/has this output/,'Testing stdout'); is(length stderr, 0,'No stderr'); =head1 PURPOSE This test module is intended to simplify testing of external commands. It does so by running the command under L, closing the stdin immediately, and reading everything from the command's stdout and stderr. It then makes the output available to be tested. It is not (yet?) as feature-rich as L, but I think the interface to this is much simpler. Tests also plug directly into the L framework, which plays nice with L. As compared to L, this module is simpler, relying on the user to feed rc, stdout, and stderr to the appropriate other tests, presumably in L, but not necessarily. This makes it possible, for example, to test line 3 of the output: my (undef, undef, $line) = split /\r?\n/, stdout; is($line, 'This is the third line', 'Test the third line'); While this is possible to do with Test::Command's stdout_like, some regex's can get very awkward, and it becomes better to do this in multiple steps. Also, Test::Command saves stdout and stderr to files. That has an advantage when you're saving a lot of text. However, this module prefers to slurp everything in using IPC::Open3, IO::Select, and sysread. Most of the time, commands being tested do not produce significant amounts of output, so there becomes no reason to use temporary files and involve the disk at all. =head1 EXPORTS =head2 run Runs the given command. It will return when the command is done. This will also reinitialise all of the states for stdout, stderr, and rc. If you need to keep the values of a previous run() after a later one, you will need to store it. This should be mostly pretty rare. Counts as one test: whether the IPC::Open3 call to open3 succeeded. That is not returned in a meaningful way to the user, though. To check if that's the case for purposes of SKIPping, rc will be set to -1. =cut my ($stdout, $stderr, $rc); sub run { my $opts = @_ && ref $_[0] eq 'HASH' ? shift : {}; my @cmd = @_; # initialise everything each run. $rc = -1; $stdout = ''; $stderr = ''; my ($wtr, $rdr, $err) = map { gensym() } 1..3; my $pid = open3($wtr, $rdr, $err, @cmd) or do { return __PACKAGE__->builder->ok(0, "Can run '@cmd'"); }; __PACKAGE__->builder->ok(1, "Can run '@cmd'"); my $s = IO::Select->new(); if ($opts->{stdin}) { print $wtr $opts->{stdin}; } close $wtr; $s->add($rdr); $s->add($err); my %map = ( fileno($rdr) => \$stdout, fileno($err) => \$stderr, ); while ($s->count()) { if (my @ready = $s->can_read()) { for my $fh (@ready) { my $buffer; my $fileno = fileno($fh); my $read = sysread($fh, $buffer, 1024); if ($read && $map{$fileno}) { ${$map{$fileno}} .= $buffer; } else { # done. $s->remove($fh); close $fh; } } } elsif (my @err = $s->has_exception()) { warn "Exception on ", fileno($_) for @err; } } waitpid $pid, 0; $rc = $?; $rc; } =head2 stdout Returns the last run's stdout =cut sub stdout() { $stdout } =head2 stderr Returns the last run's stderr =cut sub stderr() { $stderr } =head2 rc Returns the last run's full $?, suitable for passing to L's :sys_wait_h macros (WIFEXITED, WEXITSTATUS, etc.) =cut sub rc() { $rc } =head2 exit_status Returns the exit status of the last run =cut sub exit_status() { #WEXITSTATUS($rc); $rc >> 8; } =head2 run_ok Shortcut for checking that the return from a command is 0. Will still set stdout and stderr for further testing. If the first parameter is an integer 0-255, then that is the expected return code instead. Remember: $? has both a return code (0-255) and a reason for exit embedded. This function must make the assumption that you want a "normal" exit only. If any signal is given, this will treat that as a failure. Note that this becomes B tests: one that IPC::Open3 could create the subprocess with the command, the next is the test that the process exited normally, and the last is the test of the rc. =cut sub run_ok { my $wanted_rc = 0; if (looks_like_number($_[0]) && 0 <= $_[0] && $_[0] <= 255 && int($_[0]) == $_[0]) { $wanted_rc = shift(); } run(@_); __PACKAGE__->builder->is_eq(rc & 0xFF, 0, "Process terminated without a signal"); __PACKAGE__->builder->is_eq(exit_status, $wanted_rc, "Check return from '@_' is $wanted_rc"); } =head1 AUTHOR Darin McBride, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Test::Command::Simple You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 ACKNOWLEDGEMENTS =head1 LICENSE AND COPYRIGHT Copyright 2010 Darin McBride. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 1; # End of Test::Command::Simple Test-Command-Simple-0.05/t000755020535020535 012535213630 16134 5ustar00dmcbridedmcbride000000000000Test-Command-Simple-0.05/t/pod-coverage.t000444020535020535 104712535213630 21033 0ustar00dmcbridedmcbride000000000000use strict; use warnings; use Test::More; # 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(); Test-Command-Simple-0.05/t/01-run.t000444020535020535 65512535213630 17466 0ustar00dmcbridedmcbride000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; BEGIN { use_ok('Test::Command::Simple'); } run($^X, qw(-le), 'print q[this is here in the output]'); like(stdout, qr/here in the/, "Output looks ok"); is(length stderr, 0, "No stderr"); is(rc, 0, "Returns ok"); run_ok('echo', 'something else'); like(stdout, qr/mething/); # check that the return code is tested run_ok(3, $^X, -le => 'exit 3'); done_testing(); Test-Command-Simple-0.05/t/00-load.t000444020535020535 30612535213630 17571 0ustar00dmcbridedmcbride000000000000#!perl -T use Test::More tests => 1; BEGIN { use_ok( 'Test::Command::Simple' ) || print "Bail out! "; } diag( "Testing Test::Command::Simple $Test::Command::Simple::VERSION, Perl $], $^X" ); Test-Command-Simple-0.05/t/manifest.t000444020535020535 53112535213630 20243 0ustar00dmcbridedmcbride000000000000#!perl -T use strict; use warnings; use Test::More; BAIL_OUT("No support for OS") if $^O =~ /win/i && $^O !~ /cygwin/i; unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } eval "use Test::CheckManifest 0.9"; plan skip_all => "Test::CheckManifest 0.9 required" if $@; ok_manifest(); Test-Command-Simple-0.05/t/pod.t000444020535020535 35012535213630 17216 0ustar00dmcbridedmcbride000000000000#!perl -T use strict; use warnings; use Test::More; # 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();