winglang/wing

When `assert` fails it should hint to use `expect` instead

Open

#2859 aperta il 8 giu 2023

Vedi su GitHub
 (7 commenti) (2 reazioni) (0 assegnatari)TypeScript (214 fork)github user discovery
good first issue⌨️ cli✨ enhancement🛠️ compiler

Metriche repository

Star
 (5385 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Decided:

Note: This section was added after some discussion. The rest of the issue description was not changed. The requirement here is when assert fails and that cumbersome error message appears, the CLI should also emit a hint instructing the user to utilize expect instead of assert.

Feature Spec

It's easy to identify what the problem for the failed test assertion could be, without having to reach for additional logging statements.

Use Cases

Given the following test case

test "one plus one" {
    let one = 1;
    let other = 1;
    assert(one + other == 3);
}

Rather than seeing that that the assertion failed like we do at the moment:

fail ┌ main.wsim » root/env1/test:one plus one
Error: assertion failed: '((one + other) === 3)'
    at /var/folders/zl/z8nc41qs7010qsfngfc_z1zc0000gn/T/wing-bundles-T4JNhr/index.js:24:23
    at $Closure6.handle (/var/folders/zl/z8nc41qs7010qsfngfc_z1zc0000gn/T/wing-bundles-T4JNhr/index.js:25:15)...

It would be nice to see what the problem is. In this case something along the lines of "expected: 3, actual 2". Could and probably should be inspired by other test frameworks.

Implementation Notes

This depends on https://github.com/winglang/wing/issues/1977

Component

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.

Guida contributor