Skip to content

Commit 8526b5d

Browse files
authored
Write unexpected input to stderr to ease debugging (#31)
* Write unexpected input to stderr to ease debugging * draft: Added expected error output * adjusted expectations * Update tests.php * Update tests.php * Update tests.php * Update tests.php * Update cs2pr * Update tests.php * Update cs2pr * Update cs2pr
1 parent 2dd4cf1 commit 8526b5d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

cs2pr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ $root = @simplexml_load_string($xml);
3737
if ($root === false) {
3838
$errors = libxml_get_errors();
3939
if ($errors) {
40-
fwrite(STDERR, $errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column);
40+
fwrite(STDERR, 'Error: '. rtrim($errors[0]->message).' on line '.$errors[0]->line.', column '.$errors[0]->column ."\n\n");
4141
} elseif (stripos($xml, '<?xml') !== 0) {
42-
fwrite(STDERR, 'expecting xml stream starting with a xml opening tag.');
42+
fwrite(STDERR, 'Error: Expecting xml stream starting with a xml opening tag.' ."\n\n");
4343
} else {
44-
fwrite(STDERR, 'unknown error. expecting checkstyle formatted xml input.');
44+
fwrite(STDERR, 'Error: Unknown error. Expecting checkstyle formatted xml input.' ."\n\n");
4545
}
46+
fwrite(STDERR, $xml);
47+
4648
exit(2);
4749
}
4850

tests/tests.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ function testXml($xmlPath, $expectedExit, $expectedOutput = null)
3636
}
3737

3838

39-
testXml(__DIR__.'/fail/empty.xml', 2);
40-
testXml(__DIR__.'/fail/invalid.xml', 2);
39+
testXml(__DIR__.'/fail/empty.xml', 2, "Error: Expecting xml stream starting with a xml opening tag.\n");
40+
testXml(__DIR__.'/fail/invalid.xml', 2, "Error: Start tag expected, '<' not found on line 1, column 1\n\n" .file_get_contents(__DIR__.'/fail/invalid.xml'));
4141

42-
testXml(__DIR__.'/fail/multiple-suites.xml', 2);
42+
testXml(__DIR__.'/fail/multiple-suites.xml', 2, "Error: Extra content at the end of the document on line 8, column 1\n\n" .file_get_contents(__DIR__.'/fail/multiple-suites.xml'));
4343

4444
testXml(__DIR__.'/errors/minimal.xml', 1, file_get_contents(__DIR__.'/errors/minimal.expect'));
4545

0 commit comments

Comments
 (0)