Skip to content

Cannot capture UpdateExpression like ++foo #32

Closed

Description

@falsandtru
class C {
  count_ = {};
  count() {
    return this.count_;
  }
}
var counter = new C();
assert(++counter.count_ === counter.count());

expected:

          assert(++counter.count_ === counter.count())
                 | |       |      |   |       |
                 | |       |      |   |       Object{}
                 | |       |      |   C{count_:#Object#}
                 | |       |      false
                 | |       Object{}
                 | C{count_:#Object#}
                 NaN

actual:

          assert(++counter.count_ === counter.count())
                 |                |   |       |
                 |                |   |       NaN
                 |                |   C{count_:NaN}
                 NaN              false

other:

          assert(+counter.count_ === counter.count())
                 ||       |      |   |       |
                 ||       |      |   |       Object{}
                 ||       |      |   C{count_:#Object#}
                 ||       |      false
                 ||       Object{}
                 |C{count_:#Object#}
                 NaN

Activity

  1. changed the title [-]Incorrect increment/decrement assertion messages[/-] [+]Incomplete increment/decrement assertion messages[/+] on Nov 9, 2015
  2. twada commented on Nov 9, 2015

    @twada
    Member

    Hi, thank you for reporting.

    Unfortunately, it's a limitation of power-assert. I cannot support UpdateExpression since it causes ReferenceError.

    Let me explain. Given example.js,

    'use strict';
    
    function capt (val) {
        return val;
    }
    
    var counter = {
        count: 0
    };
    
    console.log(++counter.count); // => 1
    console.log(capt(++capt(capt(counter).count)));  // => ReferenceError

    results in ReferenceError when executed.

    $ node example.js
    1
    ~/src/github.com/power-assert-js/power-assert/example.js:12
    console.log(capt(++capt(capt(counter).count)));
                       ^
    ReferenceError: Invalid left-hand side expression in prefix operation
        at Object.<anonymous> (~/src/github.com/power-assert-js/power-assert/example.js:12:20)
        at Module._compile (module.js:460:26)
        at Object.Module._extensions..js (module.js:478:10)
        at Module.load (module.js:355:32)
        at Function.Module._load (module.js:310:12)
        at Function.Module.runMain (module.js:501:10)
        at startup (node.js:129:16)
        at node.js:814:3
    $
    

    capt function is what power-assert is doing internally, so when I tried to capture UpdateExpression like ++foo, it always result in ReferenceError.

    Since test tool should not change behavior of SUT (System Under Test), I gave up supporting UpdateExpression.

    Sorry for inconvenience. I'll write about this limitation to FAQ section in REAME. Thanks!

  3. falsandtru commented on Nov 9, 2015

    @falsandtru
    ContributorAuthor

    I understand, thanks!

  4. changed the title [-]Incomplete increment/decrement assertion messages[/-] [+]Cannot capture UpdateExpression like ++foo[/+] on May 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions