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: validate arguments to mustCall(), fix incorrect tests #10692

Closed

Conversation

nfriedly
Copy link
Contributor

@nfriedly nfriedly commented Jan 8, 2017

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

tests

Notes: this is a subset of the changes in #9031 as requested by @mscdex and @targos.

This fixes a misplaced parenthesis in each of the tests in
test/parallel/test-http-response-statuscodes.js, causing the tests to
pass as long as any error was thrown, without validating the error
message.
@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Jan 8, 2017
@@ -423,8 +423,10 @@ function runCallChecks(exitCode) {
}


exports.mustCall = function(fn, expected) {
if (typeof expected !== 'number') expected = 1;
exports.mustCall = function(fn, expected = 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this syntax is supported on v4. This will need to be changed now or during backport.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I didn't realize this would be backported. Which is the preferred method - older syntax everywhere, or change during the backport?

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 simplest thing to do would be to update this PR. If expected === undefined, set it to 1. Otherwise, throw a TypeError if typeof expected !== 'number'. I don't think we need to worry about negative numbers slipping through, because they should blow up during development.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I tried running the test under v4 just to see it, but there are other bits of modern elsewhere in common.js :/

@nfriedly nfriedly changed the title Validate arguments to mustCall(), fix incorrect tests test: alidate arguments to mustCall(), fix incorrect tests Jan 8, 2017
@nfriedly nfriedly changed the title test: alidate arguments to mustCall(), fix incorrect tests test: validate arguments to mustCall(), fix incorrect tests Jan 8, 2017
@@ -424,7 +424,12 @@ function runCallChecks(exitCode) {


exports.mustCall = function(fn, expected) {
if (typeof expected !== 'number') expected = 1;
if (expected === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you drop the curly braces on both if statements.

if (expected === undefined) {
expected = 1;
}
if (typeof expected !== 'number' || expected < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this an else if, and drop the expected < 0 check.

expected = 1;
}
if (typeof expected !== 'number' || expected < 0) {
throw new RangeError(`Invalid expected value: ${expected}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to a TypeError.



assert.throws(function() {
common.mustCall(function() {}, 'foo')();
Copy link
Contributor

Choose a reason for hiding this comment

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

The trailing () shouldn't be necessary here.

}, /invalid expected value: foo/i);

assert.throws(function() {
common.mustCall(function() {}, /foo/)();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.


assert.throws(function() {
common.mustCall(function() {}, 'foo')();
}, /invalid expected value: foo/i);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do /^TypeError: Invalid expected value: foo$/. Also, drop the insensitive check.


assert.throws(function() {
common.mustCall(function() {}, /foo/)();
}, /invalid expected value: \/foo\//i);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here.

@nfriedly nfriedly force-pushed the fix-test-http-response-statuscode branch from 3dac8a1 to c5ba0c3 Compare January 8, 2017 22:46
@nfriedly
Copy link
Contributor Author

nfriedly commented Jan 8, 2017

@cjihrig I made several improvements that I believe address everything you pointed out, and then rebased it back to two commits because the log was getting a bit hairy.

@@ -424,7 +424,9 @@ function runCallChecks(exitCode) {


exports.mustCall = function(fn, expected) {
if (typeof expected !== 'number') expected = 1;
if (expected === undefined) expected = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Move expected = 1; to its own line please.

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@nfriedly nfriedly force-pushed the fix-test-http-response-statuscode branch from c5ba0c3 to f3c1855 Compare January 8, 2017 23:03
@@ -5,3 +5,12 @@ const assert = require('assert');
common.globalCheck = false;
global.gc = 42; // Not a valid global unless --expose_gc is set.
assert.deepStrictEqual(common.leakedGlobals(), ['gc']);


Copy link
Member

Choose a reason for hiding this comment

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

Nit: can you please remove one of these 2 blank lines?

@targos
Copy link
Member

targos commented Jan 9, 2017

instead of silently overwriting invalid values with the default
@nfriedly nfriedly force-pushed the fix-test-http-response-statuscode branch from f3c1855 to cd7ce11 Compare January 9, 2017 14:39
@Trott
Copy link
Member

Trott commented Jan 10, 2017

LGTM and thanks! 🎉

jasnell pushed a commit that referenced this pull request Jan 10, 2017
This fixes a misplaced parenthesis in each of the tests in
test/parallel/test-http-response-statuscodes.js, causing the tests to
pass as long as any error was thrown, without validating the error
message.

PR-URL: #10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
jasnell pushed a commit that referenced this pull request Jan 10, 2017
instead of silently overwriting invalid values with the default

PR-URL: #10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@jasnell
Copy link
Member

jasnell commented Jan 10, 2017

Landed in 762a303

@jasnell jasnell closed this Jan 10, 2017
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 18, 2017
This fixes a misplaced parenthesis in each of the tests in
test/parallel/test-http-response-statuscodes.js, causing the tests to
pass as long as any error was thrown, without validating the error
message.

PR-URL: nodejs#10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 18, 2017
instead of silently overwriting invalid values with the default

PR-URL: nodejs#10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 23, 2017
This fixes a misplaced parenthesis in each of the tests in
test/parallel/test-http-response-statuscodes.js, causing the tests to
pass as long as any error was thrown, without validating the error
message.

PR-URL: nodejs#10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 23, 2017
instead of silently overwriting invalid values with the default

PR-URL: nodejs#10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 25, 2017
This fixes a misplaced parenthesis in each of the tests in
test/parallel/test-http-response-statuscodes.js, causing the tests to
pass as long as any error was thrown, without validating the error
message.

PR-URL: nodejs#10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 25, 2017
instead of silently overwriting invalid values with the default

PR-URL: nodejs#10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 27, 2017
This fixes a misplaced parenthesis in each of the tests in
test/parallel/test-http-response-statuscodes.js, causing the tests to
pass as long as any error was thrown, without validating the error
message.

PR-URL: nodejs#10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 27, 2017
instead of silently overwriting invalid values with the default

PR-URL: nodejs#10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@italoacasas italoacasas mentioned this pull request Jan 29, 2017
@MylesBorins
Copy link
Contributor

MylesBorins commented Mar 8, 2017

This is causing failures on v6.x. Can someone dig in?

Missed a commit in the backport... nvm

MylesBorins pushed a commit that referenced this pull request Mar 8, 2017
This fixes a misplaced parenthesis in each of the tests in
test/parallel/test-http-response-statuscodes.js, causing the tests to
pass as long as any error was thrown, without validating the error
message.

PR-URL: #10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 8, 2017
instead of silently overwriting invalid values with the default

PR-URL: #10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
This fixes a misplaced parenthesis in each of the tests in
test/parallel/test-http-response-statuscodes.js, causing the tests to
pass as long as any error was thrown, without validating the error
message.

PR-URL: #10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
instead of silently overwriting invalid values with the default

PR-URL: #10692
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@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
test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants