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 common.mustNotCall() #11152

Merged
merged 1 commit into from
Feb 6, 2017
Merged

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Feb 3, 2017

This commit adds a mustNotCall() helper for testing. This provides an alternative to using common.fail() as a callback, or creating a callback function for the sole purpose of calling common.fail().

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)

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Feb 3, 2017
Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

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

Somewhat rubber-stamp-y LGTM if CI is green.

test/common.js Outdated
fail(msg || 'function should not have been called');
};
};

Copy link
Member

Choose a reason for hiding this comment

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

hmm.. the same basic thing can be accomplished using:

common.mustCall(fn, 0);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could. The whole point is to get beautiful assertion messages though. Using common.mustCall() would yield:

Mismatched <anonymous> function calls. Expected 0, actual 1.

Copy link
Member

@Trott Trott Feb 3, 2017

Choose a reason for hiding this comment

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

Additionally, common.mustCall(fn, 0) will only fail when the exit event is emitted on process. The version in this PR fails immediately. That could be very helpful for a test that otherwise will mysteriously time out because something is holding the event loop open indefinitely.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, works for me

Copy link
Member

Choose a reason for hiding this comment

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

Just to add my 2 cents I also think common.mustNotCall() makes it immediately obvious what you want to happen without needing the context to know that 0 will imply it should not be called.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

test/common.js Outdated
fail(msg || 'function should not have been called');
};
};

Copy link
Member

Choose a reason for hiding this comment

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

Just to add my 2 cents I also think common.mustNotCall() makes it immediately obvious what you want to happen without needing the context to know that 0 will imply it should not be called.

test/common.js Outdated
@@ -497,6 +497,12 @@ function fail(msg) {
}
exports.fail = fail;

exports.mustNotCall = function(msg) {
return function dontCall() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it help to keep this function's name also as mustNotCall? Stacktrace would be better I guess.

test/common.js Outdated
@@ -497,6 +497,12 @@ function fail(msg) {
}
exports.fail = fail;

exports.mustNotCall = function(msg) {
return function dontCall() {
fail(msg || 'function should not have been called');
Copy link
Member

Choose a reason for hiding this comment

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

Can we do something to prevent this from printing stuff like

AssertionError: [object Object]

when msg is not a string?

Copy link
Member

Choose a reason for hiding this comment

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

util.format ?

Copy link
Member

@lpinca lpinca Feb 4, 2017

Choose a reason for hiding this comment

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

On second thought I think this is not needed as the function (common.mustNotCall()) must be invoked explicitly and using a non-string argument probably doesn't make sense.

@cjihrig
Copy link
Contributor Author

cjihrig commented Feb 5, 2017

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 the CI is happy

@jasnell
Copy link
Member

jasnell commented Feb 6, 2017

@nodejs/build @jbergstroem ... something is happening with the OSX build bot. Failing to start on every CI run

This commit adds a mustNotCall() helper for testing. This provides
an alternative to using common.fail() as a callback, or creating
a callback function for the sole purpose of calling common.fail().

PR-URL: nodejs#11152
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
@cjihrig
Copy link
Contributor Author

cjihrig commented Feb 6, 2017

Landing this since the only problem is the macOS CI, which I can verify locally.

@cjihrig cjihrig merged commit 7dd82dd into nodejs:master Feb 6, 2017
@cjihrig cjihrig deleted the must-not-call branch February 6, 2017 19:15
@italoacasas
Copy link
Contributor

@cjihrig do you have time to backport this to v7.x ?

italoacasas pushed a commit that referenced this pull request Feb 13, 2017
This commit adds a mustNotCall() helper for testing. This provides
an alternative to using common.fail() as a callback, or creating
a callback function for the sole purpose of calling common.fail().

PR-URL: #11152
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Feb 14, 2017
This commit adds a mustNotCall() helper for testing. This provides
an alternative to using common.fail() as a callback, or creating
a callback function for the sole purpose of calling common.fail().

PR-URL: nodejs#11152
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
krydos pushed a commit to krydos/node that referenced this pull request Feb 25, 2017
This commit adds a mustNotCall() helper for testing. This provides
an alternative to using common.fail() as a callback, or creating
a callback function for the sole purpose of calling common.fail().

PR-URL: nodejs#11152
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
@jasnell
Copy link
Member

jasnell commented Mar 7, 2017

This would need backport PRs to land in v6 and v4 ... there are several recent test changes that depend on this so a backport would be preferrable.

MylesBorins pushed a commit that referenced this pull request May 15, 2017
This commit adds a mustNotCall() helper for testing. This provides
an alternative to using common.fail() as a callback, or creating
a callback function for the sole purpose of calling common.fail().

PR-URL: #11152
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
@MylesBorins
Copy link
Contributor

backported to v6.x in bea0a6e

@MylesBorins MylesBorins mentioned this pull request May 23, 2017
andrew749 pushed a commit to michielbaird/node that referenced this pull request Jul 19, 2017
This commit adds a mustNotCall() helper for testing. This provides
an alternative to using common.fail() as a callback, or creating
a callback function for the sole purpose of calling common.fail().

PR-URL: nodejs/node#11152
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
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.