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

assert: deprecate assert.fail partially #18418

Closed
wants to merge 1 commit into from

Conversation

BridgeAR
Copy link
Member

Using assert.fail() with more than one argument is not intuitive
to use and has no benefit over using a message on its own.

Therefore this introduces a runtime deprecation in case it is used
in that way.

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

assert

@nodejs-github-bot nodejs-github-bot added the assert Issues and PRs related to the assert subsystem. label Jan 28, 2018
@ChALkeR ChALkeR added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jan 28, 2018
[`Error.captureStackTrace`]). If no arguments are given, the default message
`Failed` will be used.
* `actual` {any} _Deprecated if not used as message (see below)_
* `expected` {any}_Deprecated (see below)_
Copy link
Member

Choose a reason for hiding this comment

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

Nit: space after first _.

lib/assert.js Outdated
warned = true;
process.emitWarning(
'assert.fail() with more than one argument is deprecated. ' +
'Please use assert.strictEqual instead or only pass a message.',
Copy link
Member

Choose a reason for hiding this comment

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

Nit: assert.strictEqual() for consistency.


Type: Runtime

Using `assert.fail()` with more than one argument has no benefit over writing a
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: a individual -> an individual.

@BridgeAR
Copy link
Member Author

Comments addressed.

CI https://ci.nodejs.org/job/node-test-pull-request/12786/

@@ -406,27 +406,52 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
## assert.fail(actual, expected[, message[, operator[, stackStartFunction]]])
Copy link
Member

Choose a reason for hiding this comment

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

The signature here looks rather confusing, since actual and expected looks required here...maybe create another section with assert.fail(message), and deprecate this signature while referencing the new one?

Copy link
Member

@joyeecheung joyeecheung Jan 29, 2018

Choose a reason for hiding this comment

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

Also, that way we can put a deprecated entry in the YAML so the whole signature would be labeled with deprecated in the TOC.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that it looks confusing. We just never had such a case before but I agree that this is probably the best way to solve this. I will change it shortly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@BridgeAR
Copy link
Member Author

* `actual` {any}
* `expected` {any}
* `message` {any} **Default:** `'Failed'`
* `operator` {string} **Default:** '!='
* `operator` {string} **Default:** '!='_
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary underscore?

@@ -440,21 +465,11 @@ assert.fail(1, 2, new TypeError('need array'));
// TypeError: need array
```

*Note*: In the last two cases `actual`, `expected`, and `operator` have no
*Note*: In the last three cases `actual`, `expected`, and `operator` have no
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps drop the *:Note*: part of this now? It's not super necessary.

@@ -818,6 +818,15 @@ a future version at which point only authentication tag lengths of 128, 120,
is not included in this list will be considered invalid in compliance with
[NIST SP 800-38D][].

<a id="DEP0XXX"></a>
### DEP0XXX: Using `assert.fail()` with more than one argument.
Copy link
Member

Choose a reason for hiding this comment

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

s/DEP0XXX/DEP00XX

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.

LGTM with one suggestion

@@ -5,6 +5,12 @@
const common = require('../common');
const assert = require('assert');

common.expectWarning(
Copy link
Member

Choose a reason for hiding this comment

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

Can you put the tests with the valid signatures to another file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@BridgeAR
Copy link
Member Author

BridgeAR commented Feb 2, 2018

Rebased due to conflicts and while doing so I also rewrote common.expectsError to assert.throws and found a mistake in one of the old tests because of that and fixed it. I also addressed @joyeecheung comment to split the tests into two files.

@BridgeAR
Copy link
Member Author

BridgeAR commented Feb 2, 2018

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM but needs a rebase

Using `assert.fail()` with more than one argument is not intuitive
to use and has no benefit over using a message on its own.

Therefore this introduces a runtime deprecation in case it is used
in that way.
@BridgeAR
Copy link
Member Author

BridgeAR commented Feb 2, 2018

Landed in 70dcacd

@BridgeAR BridgeAR closed this Feb 2, 2018
BridgeAR added a commit to BridgeAR/node that referenced this pull request Feb 2, 2018
Using `assert.fail()` with more than one argument is not intuitive
to use and has no benefit over using a message on its own.

Therefore this introduces a runtime deprecation in case it is used
in that way.

PR-URL: nodejs#18418
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Using `assert.fail()` with more than one argument is not intuitive
to use and has no benefit over using a message on its own.

Therefore this introduces a runtime deprecation in case it is used
in that way.

PR-URL: nodejs#18418
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@tniessen tniessen added the deprecations Issues and PRs related to deprecations. label Sep 7, 2018
@BridgeAR BridgeAR deleted the deprecate-assert-fail branch April 1, 2019 23:38
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. deprecations Issues and PRs related to deprecations. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants