Skip to content

Commit

Permalink
Allow test to consume stdout as well
Browse files Browse the repository at this point in the history
  • Loading branch information
9oelM committed Nov 30, 2019
1 parent d9fa4da commit 4064d87
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ under the licensing terms detailed in LICENSE:
* Emil Laine <laine.emil@gmail.com>
* Stephen Paul Weber <stephen.weber@shopify.com>
* Jay Phelps <hello@jayphelps.com>
* Joel Mun <hj923@hotmail.com>

Portions of this software are derived from third-party works licensed under
the following terms:
Expand Down
52 changes: 32 additions & 20 deletions tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,32 +156,44 @@ function runTest(basename) {
}, err => {
console.log();

// check expected stderr patterns in order
// check expected stderr and stdout patterns in order
let expectStderr = config.stderr;
if (expectStderr) {
const stderrString = stderr.toString();
if (typeof expectStderr === "string") expectStderr = [ expectStderr ];
let lastIndex = 0;
let failed = false;
expectStderr.forEach((substr, i) => {
var index = stderrString.indexOf(substr, lastIndex);
if (index < 0) {
console.log("Missing pattern #" + (i + 1) + " '" + substr + "' in stderr at " + lastIndex + "+.");
let expectStdout = config.stdout;
let hasExpected = false;
[
{ expected: expectStderr, text: 'stderr' },
{ expected: expectStdout, text: 'stdout' }
].forEach((stdPatterns) => {
let expected = stdPatterns.expected;
if (expected) {
hasExpected = true;
const stderrString = stderr.toString();
if (typeof expected === "string") expected = [ expected ];
let lastIndex = 0;
let failed = false;
expected.forEach((substr, i) => {
var index = stderrString.indexOf(substr, lastIndex);
if (index < 0) {
console.log("Missing pattern #" + (i + 1) + " '" + substr + "' in stderr at " + lastIndex + "+.");
failedTests.add(basename);
failed = true;
} else {
lastIndex = index + substr.length;
}
});
let text = stdPatterns.text;
if (failed) {
failedTests.add(basename);
failed = true;
failedMessages.set(basename, + text + " mismatch");
console.log("\n- " + colorsUtil.red(text + " MISMATCH") + "\n");
} else {
lastIndex = index + substr.length;
console.log("- " + colorsUtil.green(text + " MATCH") + "\n");
}
});
if (failed) {
failedTests.add(basename);
failedMessages.set(basename, "stderr mismatch");
console.log("\n- " + colorsUtil.red("stderr MISMATCH") + "\n");
} else {
console.log("- " + colorsUtil.green("stderr MATCH") + "\n");
return;
}
})
if (hasExpected)
return;
}

if (err)
stderr.write(err + os.EOL);
Expand Down

0 comments on commit 4064d87

Please sign in to comment.