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

[9.x backport] assert & util PRs #19230

Closed
wants to merge 21 commits into from

Commits on Mar 8, 2018

  1. doc: improve assert documentation

    1) Separate all loose and strict functions.
    2) Stronger outline the used comparison rules in (not)deepStrictEqual
    3) Fix SameValue comparison info
    
    PR-URL: nodejs#17002
    Reviewed-By: Refael Ackermann <refack@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    c6aa5ff View commit details
    Browse the repository at this point in the history
  2. assert: add strict functionality export

    Requireing the strict version will allow to use `assert.equal`,
    `assert.deepEqual` and there negated counterparts to be used with
    strict comparison instead of using e.g. `assert.strictEqual`.
    
    The API is identical to the regular assert export and only differs
    in the way that all functions use strict compairson.
    
    PR-URL: nodejs#17002
    Reviewed-By: Refael Ackermann <refack@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    b3e4476 View commit details
    Browse the repository at this point in the history
  3. assert: use object argument in innerFail

    Right now it is difficult to know what argument stands for what
    property. By refactoring the arguments into a object it is clear
    what stands for what.
    
    PR-URL: nodejs#17582
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Jon Moss <me@jonathanmoss.me>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    da78022 View commit details
    Browse the repository at this point in the history
  4. assert: fix throws and doesNotThrow stack frames

    The stack frames from .throws and .doesNotThrow got included
    even though that was not intended.
    
    PR-URL: nodejs#17703
    Reviewed-By: Timothy Gu <timothygu99@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    9664cc8 View commit details
    Browse the repository at this point in the history
  5. test: refactor common.expectsError

    A combination of try catch and common.expectsError is not necessary
    as the latter already does everything on its own.
    
    PR-URL: nodejs#17703
    Reviewed-By: Timothy Gu <timothygu99@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    0ed963b View commit details
    Browse the repository at this point in the history
  6. assert: improve assert.throws

    Throw a TypeError in case a error message is provided in the second
    argument and a third argument is present as well.
    This is clearly a mistake and should not be done.
    
    PR-URL: nodejs#17585
    Reviewed-By: Rich Trott <rtrott@gmail.com>
    Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
    Reviewed-By: Evan Lucas <evanlucas@me.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    cc52dec View commit details
    Browse the repository at this point in the history
  7. doc: improve .throws RegExp info

    It was not clear why the error name is actually also tested for when
    using a regular expression. This is now clarified.
    
    PR-URL: nodejs#17585
    Reviewed-By: Rich Trott <rtrott@gmail.com>
    Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
    Reviewed-By: Evan Lucas <evanlucas@me.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    f38be41 View commit details
    Browse the repository at this point in the history
  8. assert: .throws accept objects

    From now on it is possible to use a validation object in throws
    instead of the other possibilites.
    
    PR-URL: nodejs#17584
    Refs: nodejs#17557
    Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
    Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: Ron Korving <ron@ronkorving.nl>
    Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    7f558d5 View commit details
    Browse the repository at this point in the history
  9. assert: fix strict regression

    Using `assert()` or `assert.ok()` resulted in a error since a
    refactoring.
    
    Refs: nodejs#17582
    
    PR-URL: nodejs#17903
    Refs: nodejs#17582
    Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
    Reviewed-By: Tobias Nießen <tniessen@tnie.de>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    fe9f098 View commit details
    Browse the repository at this point in the history
  10. lib: handle throw undefined in assert.throws()

    And make `assert.doesNotThrow()` handle it as well.
    
    PR-URL: nodejs#18029
    Fixes: nodejs#18027
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
    Reviewed-By: Khaidi Chu <i@2333.moe>
    Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
    Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    bnoordhuis authored and BridgeAR committed Mar 8, 2018
    Copy the full SHA
    49dc778 View commit details
    Browse the repository at this point in the history
  11. util: fix custom inspect description

    Using a custom inspect function on the inspected object is
    deprecated. Remove the reference from the option description
    to make sure the user will read about the deprecation in the
    more detailed description.
    
    PR-URL: nodejs#17576
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    5d88557 View commit details
    Browse the repository at this point in the history
  12. util: rename util.inspect argument

    util.inspect can actually receive any property and the description
    was wrong so far. This fixes it by renaming the argument to
    value and also updating the description.
    
    PR-URL: nodejs#17576
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    f77f91d View commit details
    Browse the repository at this point in the history
  13. util: add util.inspect compact option

    The current default formatting is not ideal and this improves
    the situation by formatting the output more intuitiv.
    
    1) All object keys are now indented by 2 characters instead of
       sometimes 2 and sometimes 3 characters.
    2) Each object key will now use an individual line instead of
       sharing a line potentially with multiple object keys.
    3) Long strings will now be split into multiple lines in case
       they exceed the "lineBreak" option length (including the
       current indentation).
    4) Opening braces are now directly behind a object property
       instead of using a new line.
    5) Switch inspect "base" order. In case the compact option is set
       to `false`, inspect will now print
         "[Function: foo] {\n  property: 'data'\n}"
       instead of
         "{ [Function: foo]\n  property: 'data'\n}".
    
    PR-URL: nodejs#17576
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    fb85597 View commit details
    Browse the repository at this point in the history
  14. assert: improve error messages

    From now on all error messages produced by `assert` in strict mode
    will produce a error diff.
    
    PR-URL: nodejs#17615
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    70ac318 View commit details
    Browse the repository at this point in the history
  15. tty: add getColorDepth function

    Right now it is very difficult to determine if a terminal supports
    colors or not. This function adds this functionality by detecting
    environment variables and checking process.
    
    PR-URL: nodejs#17615
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    fae00e3 View commit details
    Browse the repository at this point in the history
  16. tty: refactor to es6

    PR-URL: nodejs#17615
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    073cf69 View commit details
    Browse the repository at this point in the history
  17. assert: use destructuring for errors

    Destructure the necessary Error classes from internal/errors.
    This improves the readability of the error creation.
    
    PR-URL: nodejs#18247
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    4fbed71 View commit details
    Browse the repository at this point in the history
  18. assert: fix throws trace

    The current stack trace thrown in case `assert.throws(fn, object)`
    is used did not filter the stack trace. This fixes it.
    
    PR-URL: nodejs#18595
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    6694f48 View commit details
    Browse the repository at this point in the history
  19. doc: document asserts Weak(Map|Set) behavior

    Right now it is not documentated that WeakMap entries are not
    compared. This might result in some confusion. This adds a note
    about the behavior in `assert.deepStrictEqual`. This documentation
    is also references in `util.isDeepStrictEqual`, so we do not have
    to document it again for that function as the underlying algorithm
    is the same.
    
    PR-URL: nodejs#18248
    Fixes: nodejs#18228
    Refs: nodejs#18228
    Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    1ce2898 View commit details
    Browse the repository at this point in the history
  20. assert: fix infinite loop

    In rare cirumstances it is possible to get a identical error diff.
    In such a case the advances diffing runs into a infinite loop.
    This fixes it by properly checking for extra entries.
    
    PR-URL: nodejs#18611
    Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    ca8a591 View commit details
    Browse the repository at this point in the history
  21. assert: show proper differences

    Right now it is possible to get an AssertionError from input that has
    the customInspect function set to always return the same value.
    
    That way the error message is actually misleading because the output
    is going to look the same. This fixes it by deactivating the custom
    inspect function.
    
    PR-URL: nodejs#18611
    Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    BridgeAR committed Mar 8, 2018
    Copy the full SHA
    254f888 View commit details
    Browse the repository at this point in the history