PerlPowerTools

 view release on metacpan or  search on metacpan

t/rev/rev.t  view on Meta::CPAN

use strict;
use warnings;

use Test::More;
END { done_testing() }

use lib qw(t/lib);
use utils;

use File::Basename;
use File::Spec::Functions;
use IPC::Run3 qw(run3);

my $command = 'bin/rev';
my $basename = basename($command);

subtest script => sub {
	ok( -e $command, "$command exists" );
	compiles_ok( $command );
	};

subtest "from file" => sub {
	my $file = catfile( qw(t data rev reverse-this.txt) );
	ok( -e $file, "Test file <$file> exists" );
	ok( -r $file, "Test file <$file> is readable" );

	my $expected = join '',
		map { chomp; reverse($_) . "\n" }
		do { local @ARGV = $file; <> };

 	my( $input, $output, $error );
 	my @command = ( $^X, $command, $file );
  	run3 \@command, \$input, \$output, \$error;

	is $output, $expected, "output has the lines reversed";
	};

subtest "from stdin" => sub {
 	my( $output, $error );
 	my $input = "cat\ndog\nbird\n";
	my $expected = "tac\ngod\ndrib\n";

 	my @command = ( $^X, $command );
  	run3 \@command, \$input, \$output, \$error;

	is $output, $expected, "output has the lines reversed";
	};

subtest "version" => sub {
 	my( $output, $error );

 	my @command = ( $^X, $command, '--version' );
  	run3 \@command, undef, \$output, \$error;

	like $output, qr/\Q$basename\E version \d+\.\d+/, "shows version message";
	};

subtest "help" => sub {
	foreach my $arg ( '-h', '-v' ) {
		subtest $arg => sub {
			my( $output, $error );
			my @command = ( $^X, $command, $arg );
			run3 \@command, undef, \$output, \$error;
			like $output, qr/usage: \Q$basename/, "$arg shows help message";
			}
		}
	};



( run in 2.686 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )