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: add regex #11193

Closed
wants to merge 8 commits into from
Closed

test: add regex #11193

wants to merge 8 commits into from

Conversation

jobala
Copy link

@jobala jobala commented Feb 6, 2017

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 nodejs-github-bot added the test Issues and PRs related to the tests. label Feb 6, 2017
@hiroppy hiroppy added the assert Issues and PRs related to the assert subsystem. label Feb 6, 2017
Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

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

@@ -378,7 +378,7 @@ try {
assert.strictEqual(true, threw,
'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
Member

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

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
Author

Choose a reason for hiding this comment

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

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

@@ -378,7 +378,7 @@ try {
assert.strictEqual(true, threw,
'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
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

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

@@ -378,7 +378,7 @@ try {
assert.strictEqual(true, threw,
'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
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

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

@hiroppy
Copy link
Member

hiroppy commented Feb 7, 2017

@jobala
Copy link
Author

jobala commented Feb 7, 2017

@abouthiroppy could you know why the tests are failing?

@hiroppy
Copy link
Member

hiroppy commented Feb 7, 2017

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

@Trott
Copy link
Member

Trott commented Feb 7, 2017

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
Copy link
Contributor

thefourtheye commented Feb 8, 2017

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

Copy link
Contributor

@thefourtheye thefourtheye left a comment

Choose a reason for hiding this comment

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

LGTM if CI is green.

@Trott
Copy link
Member

Trott commented Feb 8, 2017

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

Argh! Yeah, vcbuild jslint. Sorry.

@jobala
Copy link
Author

jobala commented Feb 8, 2017

@Trott thanks for the pointer.

@Trott
Copy link
Member

Trott commented Feb 8, 2017

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
Copy link
Member

jasnell commented Feb 11, 2017

landed in 5f20d62

@jasnell 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
Copy link
Member

jasnell commented Mar 7, 2017

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 MylesBorins mentioned this pull request Mar 9, 2017
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