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

docs: improve assert docs #20313

Closed
wants to merge 4 commits into from
Closed

Conversation

BridgeAR
Copy link
Member

This improves the error example output by reflecting the current
state. It also makes sure the examples are up to date in general.
assert.throws clarified the ERR_AMBIGUOUS_ARGUMENT error.

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

This improves the error example output by reflecting the current
state. It also makes sure the examples are up to date in general.
`assert.throws` clarified the `ERR_AMBIGUOUS_ARGUMENT` error.
@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. doc Issues and PRs related to the documentations. labels Apr 26, 2018
assert.deepStrictEqual({ a: 1 }, { a: '1' });
// AssertionError: { a: 1 } deepStrictEqual { a: '1' }
// because 1 !== '1' using SameValue comparison
// AssertionError: Input A expected to strictly deep-equal input B:
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 removed the ERR_ASSERTION part in some cases because the line length would otherwise be above 80 characters.

@BridgeAR
Copy link
Member Author

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 26, 2018

I have some deviations from the the very first example or even strange issues on Windows 7 x64 (Node.js v10.0.0) concerning overall color handling and line breaks in the legend:

Outputs + screenshots for 4 cases with the same code:
  1. cmd.exe, REPL;
> require('assert').strict.deepEqual([1, 2, 3, 4, 5], [1, 2, 3, 4, '5']);
AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
+ expected - actual ... Lines skipped

  [
    1,
...
    4,
-   5
+   '5'
  ]
>

cr

  1. cmd.exe, script;
> node.10.0.0.v8-6.6.exe e:\DOC\prg\js\node\-test\test.js
assert.js:77
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
 [32m+ expected [39m  [31m- actual [39m ... Lines skipped

  [
    1,
...
    4,
 [31m- [39m   5
 [32m+ [39m   '5'
  ]
    at Object.<anonymous> (e:\DOC\prg\js\node\-test\test.js:3:26)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3)

cs

  1. git-bash.exe, REPL;
> require('assert').strict.deepEqual([1, 2, 3, 4, 5], [1, 2, 3, 4, '5']);
AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
+ expected - actual ... Lines skipped

  [
    1,
...
    4,
-   5
+   '5'
  ]
>

br

  1. git-bash.exe, script;
winpty ./node.10.0.0.v8-6.6.exe e:/DOC/prg/js/node/-test/test.js
assert.js:77
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
[32m+ expected[39m [31m- actual[39m ... Lines skipped

  [
    1,
...
    4,
[31m-[39m   5
[32m+[39m   '5'
  ]
    at Object.<anonymous> (e:\DOC\prg\js\node\-test\test.js:3:26)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3)

bs


Should we ignore this?

@BridgeAR
Copy link
Member Author

@vsemozhetbyt I removed the extra line break in here to make it clear to the reader that it is still the same error message. Besides that I do not see any differences concerning the line breaks. The color handling is indeed weird though and that is a separate concern from this PR. I am going to try to look into it, but I sadly do not have a Windows to debug this at the moment.

@vsemozhetbyt

This comment has been minimized.

@BridgeAR
Copy link
Member Author

@vsemozhetbyt oh, I cite: Example error diff (the expected, actual, and Lines skipped will be on a single row):. I did that to make sure the - and + entries are colored when looked at as assert.md. I guess that could be changed as it is mainly about the website anyway.

@vsemozhetbyt
Copy link
Contributor

@BridgeAR
Copy link
Member Author

Copy link
Contributor

@vsemozhetbyt vsemozhetbyt left a comment

Choose a reason for hiding this comment

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

With some possible nits)

@@ -364,8 +388,16 @@ weakMap3.unequal = true;

assert.deepStrictEqual(weakMap1, weakMap2);
// OK, because it is impossible to compare the entries

// Fail because weakMap3 has a property that weakMap1 does not contain:
Copy link
Contributor

Choose a reason for hiding this comment

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

Fail -> Fails? (Ignore if this is a noun)

@@ -639,7 +665,9 @@ changes:
* `value` {any}

Throws `value` if `value` is not `undefined` or `null`. This is useful when
testing the `error` argument in callbacks.
testing the `error` argument in callbacks. The stack trace contains all frames
from the error passed to `ifError` including the potential new frames for
Copy link
Contributor

Choose a reason for hiding this comment

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

`ifError` -> `ifError()`?

testing the `error` argument in callbacks.
testing the `error` argument in callbacks. The stack trace contains all frames
from the error passed to `ifError` including the potential new frames for
`ifError` itself. See below for an example.
Copy link
Contributor

Choose a reason for hiding this comment

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

`ifError` -> `ifError()`?

@@ -880,40 +921,34 @@ assert.ok(1);
// OK

assert.ok();
// throws:
// "AssertionError: No value argument passed to `assert.ok`.
// AssertionError: No value argument passed to `assert.ok`.
Copy link
Contributor

Choose a reason for hiding this comment

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

`assert.ok()` ?

Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Apr 26, 2018

Choose a reason for hiding this comment

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

TODO for another PR: unify parentheses in notStrictEqual above and check other cases?

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.

LGTM with nits from @vsemozhetbyt addressed

@BridgeAR
Copy link
Member Author

Comments addressed.

New CI https://ci.nodejs.org/job/node-test-pull-request-lite/602/


assert.ok(false, 'it\'s false');
// throws "AssertionError: it's false"
// AssertionError: it's false"
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove "

@@ -921,7 +921,7 @@ assert.ok(1);
// OK

assert.ok();
// AssertionError: No value argument passed to `assert.ok`.
// AssertionError: No value argument passed to `assert.ok()`.
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, there's no period at the end of the error message:

> assert.ok()
AssertionError [ERR_ASSERTION]: No value argument passed to `assert.ok()`
> 

@BridgeAR
Copy link
Member Author

Comments addressed. I also moved an example higher up, so it is more prominent.

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

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 27, 2018
@BridgeAR
Copy link
Member Author

Landed in 6554301

BridgeAR added a commit to BridgeAR/node that referenced this pull request Apr 29, 2018
This improves the error example output by reflecting the current
state. It also makes sure the examples are up to date in general.
`assert.throws` clarified the `ERR_AMBIGUOUS_ARGUMENT` error.

PR-URL: nodejs#20313
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
@BridgeAR BridgeAR closed this Apr 29, 2018
MylesBorins pushed a commit that referenced this pull request May 4, 2018
This improves the error example output by reflecting the current
state. It also makes sure the examples are up to date in general.
`assert.throws` clarified the `ERR_AMBIGUOUS_ARGUMENT` error.

PR-URL: #20313
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
@MylesBorins MylesBorins mentioned this pull request May 8, 2018
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. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants