Re: testing Parallel::Simple
Eric, I was just thinking of writing some tests for Getopt::Helpful and was wondering if something using IPC::Run might do the trick. The idea was to write a series of little programs that should behave in a given way (print something, die, or warn with a usage message) for some set of arguments and doing a string-match against their outputs. I just have a little function for things like this: sub test_subprogram { my ($mini_prog, $action) = @_; # make sure single quotes in our subprogram don't wack us out $mini_prog =~ s/'/'"'"'/g; # that looks funky, but that's because shell quoting rules are funky if (not defined $action or $action eq 'RETURN_EXIT_VALUE') { my $exit_val = system("perl -e '$mini_prog'"); return $exit_val == 0; } elsif ($action eq 'RETURN_STDOUT') { my $output = `perl -e '$mini_prog' 2>/dev/null`; return $output; } elsif ($action eq 'RETURN_STDERR') { my $output = `perl -e '$mini_prog' 2>&1 1>/dev/null`; return $output; } elsif ($action eq 'RETURN_STDOUT_AND_STDERR') { my $output = `perl -e '$mini_prog' 2>&1`; return $output; } else { die("TestFirst::test_subprogram: don't know what action $action means"); } } It might be possible to do this more simply with a module, but I never really went looking for one. -- Buddy
Re: testing Parallel::Simple
Eric Wilhelm wrote: This is really an ill-formed idea right now but: ($stdout, $stderr, $code) = run_prog($prog, '--arg' , 'val'); ok($stdout eq "arg -> val"); ($stdout, $stderr, $code) = run_prog($prog, '--nonarg' , 'val'); ok($code == 1); # error code (as expected) ($stdout, $stderr, $code) = run_prog($prog, '--help' , 'arg'); ok($stderr =~ m/arg/); # help messages on stderr I'm not sure if there's a test module that already does this or not. Any suggestions? (maybe Test::Cmd)) --Eric Check out Test::Output. That combined with system() might do what you need. David
Re: testing Parallel::Simple
# The following was supposedly scribed by # Ofer Nave # on Monday 28 February 2005 07:50 pm: >Incidentally, I sorta picked a tough module to start learning how to >write tests for. Does anyone have advice on how to write tests for my >Parallel::Simple module? I was just thinking of writing some tests for Getopt::Helpful and was wondering if something using IPC::Run might do the trick. The idea was to write a series of little programs that should behave in a given way (print something, die, or warn with a usage message) for some set of arguments and doing a string-match against their outputs. This is really an ill-formed idea right now but: ($stdout, $stderr, $code) = run_prog($prog, '--arg' , 'val'); ok($stdout eq "arg -> val"); ($stdout, $stderr, $code) = run_prog($prog, '--nonarg' , 'val'); ok($code == 1); # error code (as expected) ($stdout, $stderr, $code) = run_prog($prog, '--help' , 'arg'); ok($stderr =~ m/arg/); # help messages on stderr I'm not sure if there's a test module that already does this or not. Any suggestions? (maybe Test::Cmd)) --Eric -- "Politics is not a bad profession. If you succeed there are many rewards, if you disgrace yourself you can always write a book." -- Ronald Reagan - http://scratchcomputing.com -