Skip to content

Commit

Permalink
add line number to TestParseException exception message (#4446)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaainf authored and DavertMik committed Aug 24, 2017
1 parent c59f541 commit 215bab0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Codeception/Exception/TestParseException.php
Expand Up @@ -3,9 +3,13 @@

class TestParseException extends \Exception
{
public function __construct($fileName, $errors = null)
public function __construct($fileName, $errors = null, $line = null)
{
$this->message = "Couldn't parse test '$fileName'";
if ($line) {
$this->message = "Couldn't parse test '$fileName' on line $line";
} else {
$this->message = "Couldn't parse test '$fileName'";
}
if ($errors) {
$this->message .= "\n$errors";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Parser.php
Expand Up @@ -125,7 +125,7 @@ public static function load($file)
try {
self::includeFile($file);
} catch (\ParseError $e) {
throw new TestParseException($file, $e->getMessage());
throw new TestParseException($file, $e->getMessage(), $e->getLine());
} catch (\Exception $e) {
// file is valid otherwise
}
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Test/Cept.php
Expand Up @@ -41,7 +41,7 @@ public function test()
try {
require $testFile;
} catch (\ParseError $e) {
throw new TestParseException($testFile, $e->getMessage());
throw new TestParseException($testFile, $e->getMessage(), $e->getLine());
}
}

Expand Down

0 comments on commit 215bab0

Please sign in to comment.