3 # Execute a command and check:
4 # - the exit status is as specified
5 # - the output (stdout) matches a given regex
9 --let $include_filename= assert_command_output.inc
10 --source include/begin_include_file.inc
14 --echo # debug: assert_command=
'$assert_command' assert_regex=
'$assert_regex' assert_negated=
'$assert_negated' assert_status=
'$assert_status'
17 --let _ASSERT_COMMAND= $assert_command
18 --let _ASSERT_REGEX= $assert_regex
19 --let _ASSERT_NEGATED= $assert_negated
20 --let _ASSERT_STATUS= $assert_status
21 --let $_assert_suffix= `SELECT UUID()`
22 --let _ASSERT_ERROR_FILE= $MYSQLTEST_VARDIR/tmp/_assert_$_assert_suffix.inc
23 --let _ASSERT_DEBUG= $rpl_debug
27 --echo # debug: assert_error_file=
'$_ASSERT_ERROR_FILE'
31 my $cmd= $ENV{
'_ASSERT_COMMAND'};
32 my $positive= $ENV{
'_ASSERT_NEGATED'} ? 0 : 1;
33 my $regex= $ENV{
'_ASSERT_REGEX'};
34 my $status= $ENV{
'_ASSERT_STATUS'};
35 my $debug= $ENV{
'_ASSERT_DEBUG'};
38 $status= 0
if $status eq
'';
39 if ($status ne
'*' and ($status ? $? >> 8 != $status : $? != 0))
41 print
"ERROR: Command returned wrong exit status! " .
42 "Expected '$status', got '".($?>>8).
"'\n";
45 if ((($output =~ m{$regex}ms) ? 1 : 0) != $positive)
47 print
"ERROR: Command produced wrong output!\n";
48 print
"ERROR: Command: '$cmd'\n";
49 print
"ERROR: Output expected to " . ($positive?
'':
'not ').
"match " .
50 "perl regex: '$regex'\n";
55 my $file= $ENV{_ASSERT_ERROR_FILE};
56 open FILE,
"> $file" or die
"Error opening $file: $!";
57 print FILE
"X" or die
"Error writing to $file: $!";
58 close FILE or die
"Error closing $file: $!";
62 print
"======== BEGIN output ========\n$output\n" .
63 "======== END OUTPUT ========\n";
67 --file_exists $_ASSERT_ERROR_FILE
68 --remove_file $_ASSERT_ERROR_FILE
70 --let $include_filename= assert_command_output.inc
71 --source include/end_include_file.inc