$ 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) $