Repository navigation
Best-effort automatic reporting of the location of Alcotest.check - #366
Conversation
6334e8a to
6d0a854
Compare
|
Reworked the code a bit thanks to @TheLortex review. |
e5134fc to
31b74ce
Compare
|
Thanks for this PR. It's a free improvement of the location reporting feature of alcotest. The drawback is that it's not simple to predict when it works (backtrace enabled and call to - Alcotest.check ...
+ Alcotest.check ... ;
+ ()I wonder what other alcotest users think about it. |
31b74ce to
0b1589b
Compare
|
I've changed the code to use the latest |
|
Thanks! Could you show an example of what this changes in the output? Also, for the new files, could you keep the same license as the rest of the project? |
This uses the new Printexc API introduced in OCaml 4.12, and is thus disabled before.
6b76037 to
7fad5b2
Compare
|
This just shows the position of the call to An output with the location reported: one with disabled:
Done. |
|
That looks like a great feature! However, it doesn't seem very stable across OCaml versions 😁 https://ci.ocamllabs.io/github/mirage/alcotest/commit/7fad5b2e3cb68e8c3d2f29128850f16b166bbd4b/variant/alpine-3.15-4.14_opam-2.1#L507-507 Do we care? Should we just disable it for older OCaml versions? |
It's already the case, I just forgot to promote the tests when I added the copyright notice… |
7fad5b2 to
84127b6
Compare
|
Looks great, thanks for the patch! |
…d alcotest-async (1.7.0) CHANGES: - compile with MSVC (mirage/alcotest#369, @jonahbeckfordm review by @TheLortex and @MisterDA) - Allow skipping a test case from inside the test case (mirage/alcotest#368, @apeschar) - Fix compilation on bytecode architectures (mirage/alcotest#335, @glondu) - Get `alcotest_stubs.c` to compile with MSVC (mirage/alcotest#369, @jonahbeckford) - Try automatically reporting the location of calls to Alcotest.check. (mirage/alcotest#366, @MisterDA, review by @TheLortex) - Detect that Alcotest is running in CI and change output accordingly. (mirage/alcotest#364, @MisterDA) - Upgrade to `dune >= 3.0`. (mirage/alcotest#360, @MisterDA)
This is an attempt of automatically discover the location of calls to
Alcotest.check, in order to not force the user to pass~hereor~posarguments. It usesPrintexc.get_callstack. It's an early attempt that is fragile and requires OCaml 4.11.The test need to end with the unit value in order to prevent the compiler from optimizing the last call to a tail-call, erasing the location in the process. Is there a way to change Alcotest' code so that this optimization doesn't happen?
A more advanced attempt should probably walk the call stack to find recognizable enclosing functions calls, add regression testing, and make it work (or default to no-op) on pre-4.11. I don't know whether the code is efficient enough.
Try it out with
dune exec --display=quiet -- examples/bad/bad.exe -ecc @TheLortex