Greetings,

I'm sure I've made a logic mistake somewhere, but I can't see where. I'm testing a command, sending it invalid inputs that will cause it to exit none zero. My test does not seem to work. Here's a snippet to reproduce the effect.

subtest 'Invalid CLI input' => sub { my @args; for my $key ( keys %{ $query_params } ) { next if ( $key eq 'report_title' ); push @args, '--'.$key, "\'$query_params->{$key}\'"; } my $stdout = '/tmp/'.$$.'_stdout'; my $command = './script/query '. join( ' ', @args ) ." &>$stdout"; ok ( system( $command ), 'CLI should return none zero status' ) or warn "not ok CLI query command [$command] did NOT return false [$?] +"; } The output: not ok 1 - CLI should return none zero status # Failed test 'CLI should return none zero status' # at ./test.pl line 62. not ok CLI query command [./script/query --delta_minutes '; DROP TABLES' --latest_record '0' --hostname 'ettin;' --policy_server '; DELETE FROM' --class 'any;' --gmt_offset '\;400; EXIT' --ip_address '10.com' --timestamp '$400;' &>/tmp/32531_stdout] did NOT return false [0] at ./test.pl line 62. 1..1 # Looks like you failed 1 test of 1. not ok 1 - Invalid CLI input # Failed test 'Invalid CLI input' # at ./test.pl line 84. # Tests were run but no plan was declared and done_testing() was not # seen.

$command should return 1, an error, and thus the ok test should be true. Yet it seems to fail and the return value, $?, is zero. If I run the command by hand, in the shell. What have I missed?

$ ./script/query --delta_minutes '; DROP TABLES' --latest_record '0' --hostname 'ettin;' --policy_server '; DELETE FROM' --class 'any;' --gmt_offset '\;400; EXIT' --ip_address '10.com' --timestamp '$400;' &>/tmp/32531_stdout; echo $? 1

Update

Two fixes. First &> did not redirect. I had to use the longer 2>&1 1>. Second, the return status was due to a wrapper around the query command. Once is fixed the wrapper to capture and return the exit status, the test passed.

Neil Watson
watson-wilson.ca


In reply to Testing and system return status by neilwatson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.