Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix invalid output TAP if there newline in test name #45742

Merged
merged 6 commits into from
Dec 11, 2022

Conversation

pulkit-30
Copy link
Contributor

@pulkit-30 pulkit-30 commented Dec 5, 2022

fixes: #45396

fix test outputs invalid TAP if there is a newline in the test name

Fixed Changes

Test Case:

// test.mjs
import { it } from 'node:test'
it('Hello \n world \t hello \b hello \v hello \f hello \r hello', () => {});

Output

TAP version 13
# Subtest: Hello \n world \t hello \b hello \v hello \f hello \r hello
ok 1 - Hello \n world \t hello \b hello \v hello \f hello \r hello
  ---
  duration_ms: 1.117041
  ...
1..1
# tests 1
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 6.629375

@nodejs-github-bot nodejs-github-bot added dont-land-on-v14.x needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Dec 5, 2022
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a test.

StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#'
);
), '\n', '\\n');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about \r, \v, \b, and \f?

@pulkit-30
Copy link
Contributor Author

pulkit-30 commented Dec 7, 2022

This needs a test.

Hey @aduh95
I'm not sure where to write tests for this. 😞
Could you please assist me with this?

@aduh95
Copy link
Contributor

aduh95 commented Dec 7, 2022

I'm not sure where to write tests for this.

test/parallel/test-runner-tap-parser-stream.js seems an appropriate location.

@@ -4,6 +4,7 @@ const common = require('../common');
const assert = require('node:assert');
const { TapParser } = require('internal/test_runner/tap_parser');
const { TapChecker } = require('internal/test_runner/tap_checker');
const { tapEscape } = require('internal/test_runner/tap_stream');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I don't think this file is the best place for testing this. This file is more about the TAP parser.

I would test this by doing the following:

  • Undo the changes in this file.
  • Remove the tapEscape export that this PR adds to lib/internal/test_runner/tap_stream.js.
  • Add a test to test/message/test_runner_output.js that uses \n, \r, etc (# and \ are already tested IIRC).
  • Update test/message/test_runner_output.out to reflect the changes in the test output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating this 👍🏽 🚀

return StringPrototypeReplaceAll(
StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#'
);
[{ escapeChar: '\\', tappedEscape: '\\\\' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the resulting code will not look as nice as this, I'm inclined to use a series of StringPrototypeReplaceAll() calls here instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjihrig like this... right?

return StringPrototypeReplaceAll(StringPrototypeReplaceAll(
    StringPrototypeReplaceAll(StringPrototypeReplaceAll(
      StringPrototypeReplaceAll(StringPrototypeReplaceAll(
        StringPrototypeReplaceAll(StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#'),
        '\b', '\\b'), '\f', '\\f'), '\t', '\\t'), '\n', '\\n'), '\r', '\\r'), '\v', '\\v');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do it that way. You could also do something like this to maintain more readability:

let result = StringPrototypeReplaceAll(...);
result = StringPrototypeReplaceAll(...);
result = StringPrototypeReplaceAll(...);
return result;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it 👍🏽
Thanks

);
let result = StringPrototypeReplaceAll(input, '\\', '\\\\');
result = StringPrototypeReplaceAll(result, '#', '\\#');
result = StringPrototypeReplaceAll(result,'\b', '\\b');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same change on the following lines. Other than that, I think this looks good.

Suggested change
result = StringPrototypeReplaceAll(result,'\b', '\\b');
result = StringPrototypeReplaceAll(result, '\b', '\\b');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't notice that 😞
fixed 🚀

@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 10, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 10, 2022
@nodejs-github-bot
Copy link
Collaborator

@cjihrig cjihrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed needs-ci PRs that need a full CI run. labels Dec 11, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 11, 2022
@nodejs-github-bot nodejs-github-bot merged commit 22dc987 into nodejs:main Dec 11, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 22dc987

ErickWendel pushed a commit to ErickWendel/node that referenced this pull request Dec 12, 2022
targos pushed a commit that referenced this pull request Dec 12, 2022
PR-URL: #45742
Fixes: #45396
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
targos pushed a commit that referenced this pull request Dec 13, 2022
PR-URL: #45742
Fixes: #45396
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
danielleadams pushed a commit that referenced this pull request Dec 30, 2022
PR-URL: #45742
Fixes: #45396
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
danielleadams pushed a commit that referenced this pull request Dec 30, 2022
PR-URL: #45742
Fixes: #45396
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
danielleadams pushed a commit that referenced this pull request Jan 3, 2023
PR-URL: #45742
Fixes: #45396
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
danielleadams pushed a commit that referenced this pull request Jan 4, 2023
PR-URL: #45742
Fixes: #45396
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
danielleadams pushed a commit that referenced this pull request Jan 5, 2023
PR-URL: #45742
Fixes: #45396
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
MoLow pushed a commit to MoLow/node-core-test that referenced this pull request Feb 2, 2023
PR-URL: nodejs/node#45742
Fixes: nodejs/node#45396
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
(cherry picked from commit 22dc987fde29734c5bcbb7c33da20d184ff61627)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

node:test outputs invalid TAP if there is a newline in the test name
5 participants