1# Copyright 1999-2001 Steven Knight. All rights reserved. This program 2# is free software; you can redistribute it and/or modify it under the 3# same terms as Perl itself. 4 5######################### We start with some black magic to print on failure. 6 7use Test; 8BEGIN { $| = 1; plan tests => 12, onfail => sub { $? = 1 if $ENV{AEGIS_TEST} } } 9END {print "not ok 1\n" unless $loaded;} 10use Test::Cmd; 11$loaded = 1; 12ok(1); 13 14######################### End of black magic. 15 16my($run_env, $ret, $wdir, $test); 17 18$run_env = Test::Cmd->new(workdir => ''); 19ok($run_env); 20$ret = $run_env->write('run1', <<EOF); 21print STDOUT "run1 STDOUT \@ARGV\\n"; 22print STDOUT "run1 STDOUT second line\\n"; 23print STDERR "run1 STDERR \@ARGV\\n"; 24print STDERR "run1 STDERR second line\\n"; 25exit 0; 26EOF 27ok($ret); 28$ret = $run_env->write('run2', <<EOF); 29print STDOUT "run2 STDOUT \@ARGV\\n"; 30print STDOUT "run2 STDOUT second line\\n"; 31print STDERR "run2 STDERR \@ARGV\\n"; 32print STDERR "run2 STDERR second line\\n"; 33exit 0; 34EOF 35ok($ret); 36$wdir = $run_env->workdir; 37ok($wdir); 38$ret = chdir($wdir); 39ok($ret); 40 41# Everything before this was merely preparation of our "source 42# directory." Now we do some real tests. 43$test = Test::Cmd->new(interpreter => "$^X", workdir => ''); 44ok($test); 45 46ok(! defined $test->stdout); 47 48$test->prog('run1'); 49$test->run('args' => 'foo bar'); 50ok($? == 0); 51$test->prog('run2'); 52$test->run('args' => 'snafu'); 53ok($? == 0); 54 55ok($test->stdout eq "run2 STDOUT snafu\nrun2 STDOUT second line\n"); 56ok($test->stdout(1) eq "run1 STDOUT foo bar\nrun1 STDOUT second line\n"); 57