Skip to content

Show outputs captured by test cases #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
33 changes: 17 additions & 16 deletions src/CodewarsResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,37 @@ class CodewarsResultPrinter extends DefaultResultPrinter
* @var TestSuite
*/
private $wrapperSuite = null;
/**
* @var bool
*/
protected $lastTestFailed = false;

// Temporarily store failure messages so that the outputs can be written before them.
private $failures = array();

/**
* An error occurred.
*/
public function addError(Test $test, \Throwable $t, float $time): void
{
$this->lastTestFailed = true;
$this->write(sprintf("\n<ERROR::>%s\n", self::getMessage($t)));
$this->write(sprintf("\n<LOG::-Details>%s\n", self::escapeLF(self::getDetails($t))));
$this->failures[] = sprintf("\n<ERROR::>%s\n", self::getMessage($t));
$this->failures[] = sprintf("\n<LOG::-Stacktrace>%s\n", self::escapeLF(self::getDetails($t)));
}

/**
* A warning occurred.
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
$this->lastTestFailed = true;
$this->write(sprintf("\n<ERROR::>%s\n", self::getMessage($e)));
$this->write(sprintf("\n<LOG::-Details>%s\n", self::escapeLF(self::getDetails($e))));
$this->failures[] = sprintf("\n<ERROR::>%s\n", self::getMessage($e));
$this->failures[] = sprintf("\n<LOG::-Stacktrace>%s\n", self::escapeLF(self::getDetails($e)));
}

/**
* A failure occurred.
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$this->lastTestFailed = true;
$msg = self::getMessage($e);
if ($e instanceof ExpectationFailedException) {
$msg .= self::getAssertionDetails($e);
}
$this->write(sprintf("\n<FAILED::>%s\n", self::escapeLF($msg)));
$this->write(sprintf("\n<LOG::-Details>%s\n", self::escapeLF(self::getDetails($e))));
$this->failures[] = sprintf("\n<FAILED::>%s\n", self::escapeLF($msg));
}

/**
Expand Down Expand Up @@ -130,16 +123,24 @@ public function endTestSuite(TestSuite $suite): void
public function startTest(Test $test): void
{
$this->write(sprintf("\n<IT::>%s\n", $test->getName()));
$this->failures = array();
}

/**
* A test ended.
*/
public function endTest(Test $test, float $time): void
{
if (!$this->lastTestFailed) {
if (\method_exists($test, 'hasOutput') && \method_exists($test, 'getActualOutput')) {
if ($test->hasOutput()) {
$this->write($test->getActualOutput());
}
}

if (empty($this->failures)) {
$this->write("\n<PASSED::>Test Passed\n");
$this->lastTestFailed = false;
} else {
$this->write(join("\n", $this->failures));
}
$this->write(sprintf("\n<COMPLETEDIN::>%.4f\n", $time * 1000));
}
Expand Down