Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Context/Support.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ protected function check_string( $output, $expected, $action, $message = false,
$message = $output;
}

$action_message = '';
switch ( $action ) {
case 'be':
$action_message = 'Output does not exactly match expected string:';
break;
case 'contain':
$action_message = 'Output does not contain expected string:';
break;
case 'not contain':
$action_message = 'Output unexpectedly contains string:';
break;
}
Comment thread
swissspidy marked this conversation as resolved.

if ( ! empty( $action_message ) ) {
$message .= "\n\n" . $action_message . "\n" . $expected;
}

$diff = $this->generate_diff( $expected, rtrim( $output, "\n" ) );
if ( ! empty( $diff ) ) {
$message .= "\n\n" . $diff;
Expand Down
22 changes: 21 additions & 1 deletion src/Context/WhenStepDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,27 @@ public function wpcli_tests_invoke_proc( $proc, $mode ) {
);
$method = $map[ $mode ];

return $proc->$method();
try {
return $proc->$method();
} catch ( \RuntimeException $e ) {
if ( 'run' === $mode ) {
$message = $e->getMessage();
$status = 'unknown';
if ( preg_match( '/exit status: (\d+)$/', $message, $matches ) ) {
$status = $matches[1];
}
Comment thread
swissspidy marked this conversation as resolved.
Outdated

if ( '0' === $status ) {
$message .= "\n\nThe command unexpectedly produced STDERR output. If you expect a non-zero exit status or STDERR output, use `When I try [...]`. Else, this may be a bug in your code or test.";
Comment thread
swissspidy marked this conversation as resolved.
Outdated
} else {
$message .= "\n\nThe command unexpectedly exited with status {$status}. If you expect a non-zero exit status, use `When I try [...]`. Else, this may be a bug in your code or test.";
}

throw new \RuntimeException( $message, $e->getCode(), $e );
}

throw $e;
}
}

/**
Expand Down
Loading