Skip to content

Commit 47d63c1

Browse files
author
Nicolas Hart
committed
assert binary exit code
1 parent e5d226f commit 47d63c1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/LoxTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class LoxTest extends TestCase
2121

2222
private ?string $expectedRuntimeError = null;
2323

24+
private int $expectedExitCode = 0;
25+
2426
public const string FIXTURES_DIR = __DIR__ . '/lox';
2527

2628
#[DataProvider('provideFiles')]
@@ -51,6 +53,7 @@ public function test_lox(\SplFileInfo $file): void
5153
$this->assertExpectedErrors($errorLines);
5254
}
5355

56+
$this->assertExitCode((int) $process->getExitCode());
5457
$this->assertExpectedOutputs($process->getOutput());
5558
}
5659

@@ -95,6 +98,7 @@ private function collectExpectedErrors(string $line): void
9598

9699
if (!empty($matches)) {
97100
$this->expectedErrors[] = sprintf('[%s] %s', $matches['line'], $matches['message']);
101+
$this->expectedExitCode = 65;
98102
}
99103
}
100104

@@ -105,6 +109,7 @@ private function collectExpectedRuntimeError(string $line, int $lineNum): void
105109

106110
if (!empty($matches)) {
107111
$this->expectedRuntimeError = sprintf('%s [line %s]', $matches['message'], $lineNum);
112+
$this->expectedExitCode = 70;
108113
}
109114
}
110115

@@ -167,6 +172,11 @@ private function assertRuntimeError(array $errorLines): void
167172
$this->assertSame($this->expectedRuntimeError, reset($errorLines), sprintf('Expected runtime error "%s" and got: %s', $this->expectedRuntimeError, reset($errorLines)));
168173
}
169174

175+
private function assertExitCode(int $exitCode): void
176+
{
177+
$this->assertSame($this->expectedExitCode, $exitCode, sprintf('Expected return code %s and got %s', $this->expectedExitCode, $exitCode));
178+
}
179+
170180
/**
171181
* @return list<string>
172182
*/

0 commit comments

Comments
 (0)