Skip to content

Commit

Permalink
Exit with non-zero if input is empty or junk
Browse files Browse the repository at this point in the history
  • Loading branch information
aghassemi committed Dec 13, 2017
1 parent 268cbee commit ebe8283
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
10 changes: 8 additions & 2 deletions lib/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ function converter(options) {
});
});

var xmlString = serialize(testSuites);
outStream.push(xmlString + '\n');
if (tapParser.sawValidTap) {
var xmlString = serialize(testSuites);
outStream.push(xmlString + '\n');
} else {
// Fail no valid tap found (normally means no plan line present)
// Note that is a less strict check than TapParser's strict mode.
exitCode = 1;
}
result.exitCode = exitCode;
outStream.emit('end');
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tap-xunit",
"version": "2.0.0",
"version": "2.1.0",
"description": "TAP to xUnit XML converter.",
"main": "lib/converter.js",
"bin": {
Expand Down
Empty file added test/bad/blank
Empty file.
13 changes: 4 additions & 9 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ var FILE_READ_OPTS = {
encoding: 'utf-8'
};

runGoodInputTests('pass', 0); // input.pipe(xUnitConverter) == expected output
runGoodInputTests('fail', 1);
runBadInputTests(); // input.pipe(xUnitConverter) == parse error
runGoodInputTests('pass', 0); // input.pipe(xUnitConverter) == expected output
runGoodInputTests('fail', 1);
runBadInputTests(); // input.pipe(xUnitConverter) == parse error

function runGoodInputTests(subdir, exitCode) {
var INPUT_DIR = 'test/input/' + subdir;
Expand Down Expand Up @@ -74,15 +74,10 @@ function runBadInputTests() {
test('parse error: ' + filename, function(assert) {
var badInputFilePath = path.join(BAD_INPUT_DIR, filename);
var inputStream = fs.createReadStream(badInputFilePath, FILE_READ_OPTS);
var tapToxUnitConverter = converter({strict:true});
var tapToxUnitConverter = converter();
var xUnitStream = inputStream.pipe(tapToxUnitConverter);
var numParseErrors = 0;
xUnitStream.on('error', function(err) {
assert.ok(err, err.message);
numParseErrors++;
});
xUnitStream.on('end', function() {
assert.ok(numParseErrors > 0, 'had ' + numParseErrors + ' parse errors');
assert.equals(tapToxUnitConverter.exitCode, 1, 'exitCode match');
assert.end();
});
Expand Down

0 comments on commit ebe8283

Please sign in to comment.