FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test: add regex by jobala · Pull Request #11193 · nodejs/node · GitHub

/ node Public

test: add regex - #11193

Closed
jobala wants to merge 8 commits into
nodejs:masterfrom
jobala:fix-test
Closed

test: add regex#11193
jobala wants to merge 8 commits into
nodejs:masterfrom
jobala:fix-test

Conversation

jobala commented Feb 6, 2017
edited
Loading

Copy link
Copy Markdown
Description of task to be completed

Add a regular expression for assert.throws to validate the error message thrown.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

nodejs-github-bot added the test Issues and PRs related to the tests. label Feb 6, 2017
hiroppy added the assert Issues and PRs related to the assert subsystem. label Feb 6, 2017

joyeecheung left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you change the commit message to be more informative, for example, test: verify error message from assert.ifError? Thanks!

Comment thread test/parallel/test-assert.js Outdated
'a.doesNotThrow is not catching type matching errors');

assert.throws(function() { assert.ifError(new Error('test error')); });
assert.throws(function() { assert.ifError(new Error('test error')), /^([A-Za-z])\w+$/});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This regexp is probably too general. Since the error being thrown here is known, can you change that to /^Error: test error$/?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@joyeecheung I do not understand your request, can you please expound.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In this repo we try to make the validation of the error message to be as concrete as possible. For example:

assert.throws(
  () => {
    throw new Error('Wrong value');
  },
  /^Error: Wrong value$/ // Instead of something like /Wrong value/
);

There is an ongoing PR to update our guide on this: #11150

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In this line, since according to the documentation of assert.ifError(value):

Throws value if value is truthy.

We are checking that the truthy new Error('test error') passed to assert.ifError() should be rethrown, hence the error message from the block should be /^Error: test error$/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@joyeecheung thanks for taking your time, I now get your point.

Comment thread test/parallel/test-assert.js Outdated
'a.doesNotThrow is not catching type matching errors');

assert.throws(function() { assert.ifError(new Error('test error')); });
assert.throws(function() { assert.ifError(new Error('test error')), /^Error: test error/});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think the regular expression should come after the }. Also, please add a $ to the end of the regex.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@cjihrig thanks for pointing that out, I had missed the part that the regex is the optional argument to assert.throws()

Comment thread test/parallel/test-assert.js Outdated
'a.doesNotThrow is not catching type matching errors');

assert.throws(function() { assert.ifError(new Error('test error')); });
assert.throws(function() { assert.ifError(new Error('test error'))}, /^Error: test error$/);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You're going to need to add the semicolon back in.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Also, please add a space before the closing curly brace for symmetry.

hiroppy commented Feb 7, 2017

Copy link
Copy Markdown
Member

jobala commented Feb 7, 2017

Copy link
Copy Markdown
Author

@abouthiroppy could you know why the tests are failing?

hiroppy commented Feb 7, 2017

Copy link
Copy Markdown
Member

Please fix this lint error.
381:1 error Line 381 exceeds the maximum line length of 80 max-len

Trott commented Feb 7, 2017

Copy link
Copy Markdown
Member

The long line has been fixed, but this is still returning a lint error due to indentation problems introduced in the fix for the log line.

@jobala Please run make jslint or vcbuild lint before pushing commits. (If you run make test or vcbuild test, the linting should occur as part of that already.)

thefourtheye commented Feb 8, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

@Trott Did you mean make lint or vcbuild jslint? :D

thefourtheye left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM if CI is green.

Trott commented Feb 8, 2017
edited by thefourtheye
Loading

Copy link
Copy Markdown
Member

@Trott Did you mean make lint or vcbuild jslint? :D

Argh! Yeah, vcbuild jslint. Sorry.

jobala commented Feb 8, 2017

Copy link
Copy Markdown
Author

@Trott thanks for the pointer.

Trott commented Feb 8, 2017

Copy link
Copy Markdown
Member

jasnell pushed a commit that referenced this pull request Feb 11, 2017
Verify error message thrown from assert.ifError

PR-URL: #11193
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

jasnell commented Feb 11, 2017

Copy link
Copy Markdown
Member

landed in 5f20d62

jasnell closed this Feb 11, 2017
italoacasas pushed a commit that referenced this pull request Feb 13, 2017
Verify error message thrown from assert.ifError

PR-URL: #11193
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Feb 14, 2017
Verify error message thrown from assert.ifError

PR-URL: nodejs#11193
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
krydos pushed a commit to krydos/node that referenced this pull request Feb 25, 2017
Verify error message thrown from assert.ifError

PR-URL: nodejs#11193
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
jasnell pushed a commit that referenced this pull request Mar 7, 2017
Verify error message thrown from assert.ifError

PR-URL: #11193
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

jasnell commented Mar 7, 2017

Copy link
Copy Markdown
Member

Needs a backport PR to land in v4

MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
Verify error message thrown from assert.ifError

PR-URL: #11193
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
MylesBorins mentioned this pull request Mar 9, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assert Issues and PRs related to the assert subsystem. test Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL