Commit Graph

16 Commits

Author SHA1 Message Date
Jacek Sieka 11f7cff928
Allow `openArray` to be captured in `check` (#47)
Uses a trick found in
https://github.com/status-im/nim-stew/blob/master/stew/templateutils.nim
2024-09-23 08:46:26 +00:00
Etan Kissling 36c714fb3d
Ensure test is marked as failed when check is inside `proc` (#45)
* Ensure test is marked as failed when check is inside `proc`

The `testStatusIMPL` injection does not go into nested `proc`,
so the `testStatusIMPL = TestStatus.FAILED` line was not called
leading to test failures being incorrectly suppressed.

* inject old name

* Add test

* set program result in test
2024-08-25 08:49:40 +00:00
andri lim e98a1ed79f
Fix allow break in test body regression (#38)
* Fix allow break in test body regression

* Silence UnnamedBreak warning

* Use push/pop pragma to silence UnnamedBreak warning
2024-01-22 18:59:23 +07:00
Etan Kissling 0fe665e509
only run `teardown` if `setup` completed (#36)
* only run `teardown` if `setup` completed

With #35, it is no longer possible in `teardown` to refer to variables
introduced in `setup`. To avoid having to rewrite tests, address the
issue in #35 by wrapping `body` with an additional exception catching
layer. This then allows to re-use the previous `teardown` semantics
where `teardown` only ran if `setup` fully completed and also has access
to the variables introduced in `setup`.

* workaround shadowing bug

* Add test

---------

Co-authored-by: jangko <jangko128@gmail.com>
2024-01-22 13:27:34 +07:00
andri lim 13bf4d444d
Add test for PR #35 (#37)
* Add test for PR #35
2024-01-22 10:45:02 +07:00
Jacek Sieka 333e74fa2d
compile-time test support (#34)
This change brings 3 new items to `unittest2`:

* `-d:unittest2Static` compile-time flag that enables `test` to run both
at compile time and runtime
* `staticTest` that only run at compilet ime no matter the flag
* `runtimeTest` that only run at run time no matter the flag
2023-11-10 13:49:41 +01:00
Jacek Sieka 2300fa9924
Revamped output handling, cleanup and removal of thread mode (#31)
This PR introduces a facelift for `unittest2` bringing its UX into the 21st
century!

By default, a compact dot-based format is used to avoid spamming the console
on success - successes are normal and only minimal information is needed in
the vast majority of runs:

```
[  20/25] HTTP client testing suite                               ................s..... (14.2s)
[  21/25] Asynchronous process management test suite              ....................F. (14.5s)
===========================
  /home/arnetheduck/status/nimbus-eth2/vendor/nim-chronos/build/testall 'Asynchronous process management test suite::File descriptors leaks test'
---------------------------
    /home/arnetheduck/status/nimbus-eth2/vendor/nim-chronos/tests/testproc.nim(465, 27): Check failed: getCurrentFD() == markFD
    getCurrentFD() was 3
    markFD was 5

  [FAILED ] (  0.00s) File descriptors leaks test
```

For each line, we see a suite followed by single-character status markers -
mostly successes but also a skipped and a failed test.

Failures are printed verbosely after the suite is done so they don't get
lost in the success spam along with a simple copy-pasteable line showing
how to reproduce the failure.

The verbose mode has also received an upgrade:

```
  [  20/22]           terminateAndWaitForExit() timeout test
  [OK     ] (  2.00s) terminateAndWaitForExit() timeout test
  [  21/22]           File descriptors leaks test
===========================
  /home/arnetheduck/status/nimbus-eth2/vendor/nim-chronos/tests/testall 'Asynchronous process management test suite::File descriptors leaks test'
---------------------------
    /home/arnetheduck/status/nimbus-eth2/vendor/nim-chronos/tests/testproc.nim(465, 27): Check failed: getCurrentFD() == markFD
    getCurrentFD() was 3
    markFD was 5

  [FAILED ] (  0.00s) File descriptors leaks test
  [  22/22]           Leaks test
```

Here, we can see a "test started" marker so that it becomes clear which test
is currently running and so that any output the test itself prints has the
proper name attached to it.

At the end, there's a summary as well that reiterates the tests that failed so
they can be found in the success spam that the verbose mode generates:

```
[Summary ] 22 tests run: 21 OK, 1 FAILED, 0 SKIPPED
  [FAILED ] (  0.00s) File descriptors leaks test
```

As seen above, the new mode knows how many tests will run: this is thanks
to a new two-phase mode of test running: "collect" and "run"!

The "collection" phase is responsible for collecting test metadata which is
later used to run tests in smarter ways, for example in isolated processes.

Unfortunately, it is not fully backwards-compatible because the global setup
might expose order-dependency problems in test suites that previously would
not be visible - for this, we have acompile-time setting for a compatibilty
mode that runs things roughly in the same order as before but disables
some of the fancy functionality.

The changes also come with a bag of mixed stuff:

* the parallel mode is removed entirely - it was broken beyond fixing and
  needs to be rewritten from zero - deadlocks, GC violations and everything
  in between rendered it practically unusable and a source of CI failures
  above all
* an experimental process isolation mode where tests are run in a separate
  process - this is allows many features such as timeouts, output
  verification etc but it also breaks for similar reasons as above:
  "global" code gets executed out of order and repeatedly.
* random UX fixes and cleanups of things like env var reading and command
  line options
2023-09-01 12:23:01 +02:00
jangko 21ed62449d
remove nim 1.2 and 1.4 support 2023-07-28 10:53:13 +07:00
Tanguy 883c7a50ad
Fix `expect` & nim 1.6 regressions (#24) 2023-02-17 15:23:16 +01:00
jangko 0e18d15d3e
reduce compiler warnings about cannot raise defect 2023-02-14 13:13:26 +07:00
jangko bed1d50a45
workaround for nim devel in ci 2023-02-14 10:32:06 +07:00
Ștefan Talpalaru 72a6ae5ce6
fix stand-alone "check" for <Nim-1.4.0
and prevent a theoretical integer overflow
2021-03-22 20:01:37 +01:00
Jacek Sieka 4241a66ff4
updates (#2)
* update to latest upstream
* fix exception tracking
* update readme
2021-03-19 18:27:25 +01:00
Ștefan Talpalaru d01ed926d7
add suiteTeardown() template 2019-05-28 23:58:13 +02:00
Ștefan Talpalaru c8297e6f69
change a couple of threadvars into global vars 2019-05-28 21:41:04 +02:00
Ștefan Talpalaru ae4d471d38
initial commit - from https://github.com/nim-lang/Nim/pull/9724 2019-05-19 23:11:17 +02:00