$ cat 691617.pl #!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $help; my $test; my $file; GetOptions( "help|?" => \$help, "t|test" => \$test, "f|file=s" => \$file ) or die "arg error"; die "No such file '$file'" if ($file && ! -f $file); 1; __END__ $ cat 691617.t use strict; use warnings; use Test::More; use Test::Cmd; plan tests => 7; my $test = Test::Cmd->new( prog => '691617.pl', interpreter => '/usr/bin/perl', workdir => '', ); # These tests are expected to pass $test->run(args => '-f 691617.pl'); ok($? == 0, "executing 691617.pl -f 691617.pl"); $test->run(args => '-t'); ok($? == 0, "executing 691617.pl -t"); $test->run(args => '--help'); ok($? == 0, "executing 691617.pl --help"); $test->run(args => '?'); ok($? == 0, "executing 691617.pl ?"); # These tests are expected to fail $test->run(args => '-g'); ok($? != 0, "executing 691617.pl -g - expected failure"); $test->run(args => '-f no_such_file'); ok($? != 0, "executing 691617.pl -f no_such_file - - expected failure"); $test->run(args => '-f'); ok($? != 0, "executing 691617.pl -f - expected failure"); __END__ $ prove 691617.t 691617....ok All tests successful. Files=1, Tests=7, 1 wallclock secs ( 0.37 cusr + 0.05 csys = 0.42 CPU) $ #### use strict; use warnings; sub do_this { return 2 + 2; } sub do_that { return 3 + 3; } sub main { my $i = do_this(); my $j = do_that(); } main() unless caller(); # make it testable 1; __END__ #### use strict; use warnings; use Test::More; plan tests => 3; require_ok('foo.pl'); cmp_ok(do_this(), '==', 4, 'expect do_this() to return 4)'); cmp_ok(do_that(), '==', 6, 'expect do_that() to return 6)'); __END__ #### $ prove foo.t foo....ok All tests successful. Files=1, Tests=3, 1 wallclock secs ( 0.04 cusr + 0.01 csys = 0.05 CPU)