Skip to content

Commit

Permalink
Update parser to only acknowledge logs on known channels
Browse files Browse the repository at this point in the history
Fixes backwards compatibility for users who happened to have comments
that look like log lines. Since these users do not supply any
--log-function parameters, their code won't break when they update.
  • Loading branch information
Avaq committed Jun 16, 2020
1 parent b0234ae commit 73ee48e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
23 changes: 13 additions & 10 deletions lib/doctest.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ function normalizeTest($test) {
function processLine(
options, // :: { prefix :: String
// , openingDelimiter :: Nullable String
// , closingDelimiter :: Nullable String }
// , closingDelimiter :: Nullable String
// , logFunctionNames :: Array String }
accum, // :: { state :: State, tests :: Array Test }
line, // :: String
input, // :: Test -> Undefined
Expand Down Expand Up @@ -237,15 +238,17 @@ function processLine(
(last ($test[OUTPUT])).value += '\n'
+ value;
appendToOutput ($test);
} else if ((match = /^\[([A-Za-z]+)\]:(.*)$/.exec (trimmedLine)) != null) {
accum.state = LOG;
value = stripLeading (1, ' ', match[2]);
$test = last (accum.tests);
$test[OUTPUT].push ({
channel: match[1],
value: value
});
output ($test);
} else if ((match = /^\[(.+?)\]:(.*)$/.exec (trimmedLine)) != null) {
if (options.logFunctionNames.includes (match[1])) {
accum.state = LOG;
value = stripLeading (1, ' ', match[2]);
$test = last (accum.tests);
$test[OUTPUT].push ({
channel: match[1],
value: value
});
output ($test);
}
} else if (accum.state === INPUT || accum.state === LOG) {
$test = last (accum.tests);
if (!$test[OUTPUT].some (isStandardOutput)) {
Expand Down
25 changes: 11 additions & 14 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@ testCommand ('bin/doctest --log-function stdout --log-function stderr test/share
stderr: ''
});

testCommand ('bin/doctest --log-function stdout test/shared/logging.js', {
testCommand ('bin/doctest --log-function stdout --log-function stderr test/shared/logging.js', {
status: 1,
stdout: unlines ([
'running doctests in test/shared/logging.js...',
'.........xx.xxxx..x..x..',
'FAIL: expected [stdout]: 2 on line 33 (got 3)',
'FAIL: expected 3 on line 34 (got no output)',
'FAIL: expected 3 on line 40 (got [stdout]: 2)',
'...........xx.xxxx..x..x..',
'FAIL: expected [stdout]: 2 on line 42 (got 3)',
'FAIL: expected 3 on line 43 (got no output)',
'FAIL: expected 3 on line 49 (got [stdout]: 2)',
'FAIL: expected no output on line - (got 3)',
'FAIL: expected [stdout]: 2 on line 45 (got [stdout]: 1)',
'FAIL: expected [stdout]: 1 on line 46 (got [stdout]: 2)',
'FAIL: expected [stderr]: 2 on line 53 (got [stdout]: 2)',
'FAIL: expected [stdout]: 1 on line 60 (got no output fast enough)'
'FAIL: expected [stdout]: 2 on line 54 (got [stdout]: 1)',
'FAIL: expected [stdout]: 1 on line 55 (got [stdout]: 2)',
'FAIL: expected [stderr]: 2 on line 62 (got [stdout]: 2)',
'FAIL: expected [stdout]: 1 on line 69 (got no output fast enough)'
]),
stderr: ''
});
Expand Down Expand Up @@ -293,11 +293,8 @@ if (esmSupported) {
status: 1,
stdout: unlines ([
'running doctests in test/esm/async.mjs...',
'xxxx',
'FAIL: expected [stdout]: 1 on line 4 (got ! ReferenceError: stdout is not defined)',
'FAIL: expected [stderr]: 3 on line 5 (got no output fast enough)',
'FAIL: expected undefined on line 6 (got no output)',
'FAIL: expected [stdout]: 2 on line 7 (got no output fast enough)'
'x',
'FAIL: expected undefined on line 6 (got ! ReferenceError: stdout is not defined)'
]),
stderr: ''
});
Expand Down
9 changes: 9 additions & 0 deletions test/shared/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ function crash(){
// ! Error
// [stdout]: 1

// Output on non-existent channels is ignored
//
// > (stdout (1), 2)
// [spam]: "hi"
// [stdout]: 1
// [spam]: "lalala"
// 2
// [spam]: "whatever"

// Failure due to not enough output
//
// > (stdout (1), 3)
Expand Down

0 comments on commit 73ee48e

Please sign in to comment.