| ... | ... | @@ -0,0 +1,89 @@ |
| 1 | ## `test` command |
| 2 | |
| 3 | ``` |
| 4 | zigmod test |
| 5 | ``` |
| 6 | |
| 7 | Use this command to easily run your Zigmod-enabled module tests in a debugger. |
| 8 | `zig build test` is designed as a task runner and so it does not do the full-process replacement necessary for debuggers like GDB and LLDB to follow when an error occurs. |
| 9 | |
| 10 | Below is an example of the UX you can get using my https://github.com/nektro/zig-whatwg-url package in a simulated example. |
| 11 | |
| 12 | ``` |
| 13 | $ gdb --args zigmod test |
| 14 | GNU gdb (GDB) 16.3 |
| 15 | Copyright (C) 2024 Free Software Foundation, Inc. |
| 16 | License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> |
| 17 | This is free software: you are free to change and redistribute it. |
| 18 | There is NO WARRANTY, to the extent permitted by law. |
| 19 | Type "show copying" and "show warranty" for details. |
| 20 | This GDB was configured as "x86_64-unknown-linux-gnu". |
| 21 | Type "show configuration" for configuration details. |
| 22 | For bug reporting instructions, please see: |
| 23 | <https://www.gnu.org/software/gdb/bugs/>. |
| 24 | Find the GDB manual and other documentation resources online at: |
| 25 | <http://www.gnu.org/software/gdb/documentation/>. |
| 26 | |
| 27 | For help, type "help". |
| 28 | Type "apropos word" to search for commands related to "word"... |
| 29 | Reading symbols from zigmod... |
| 30 | (gdb) r |
| 31 | Starting program: /home/me/dev/zigmod/zig-out/bin/zigmod test |
| 32 | [Thread debugging using libthread_db enabled] |
| 33 | Using host libthread_db library "/nix/store/km4g87jxsqxvcq344ncyb8h1i6f3cqxh-glibc-2.40-218/lib/libthread_db.so.1". |
| 34 | process 1570642 is executing new program: /home/me/.local/share/zig/0.16.0/zig |
| 35 | [Detaching after fork from child process 1570645] |
| 36 | [New LWP 1570646] |
| 37 | [LWP 1570646 exited] |
| 38 | process 1570642 is executing new program: /home/me/zig-cache/o/82896c6cdefce8104394f5e8ce6a5138/test |
| 39 | [Thread debugging using libthread_db enabled] |
| 40 | Using host libthread_db library "/nix/store/km4g87jxsqxvcq344ncyb8h1i6f3cqxh-glibc-2.40-218/lib/libthread_db.so.1". |
| 41 | thread 1570642 panic: reached unreachable code |
| 42 | /home/me/dev/zig-whatwg-url/url.zig:372:25: 0x1294c44 in parseBasic (url.zig) |
| 43 | unreachable; |
| 44 | ^ |
| 45 | /home/me/dev/zig-whatwg-url/url.zig:42:26: 0x1274b1e in parse (url.zig) |
| 46 | return parseBasic(alloc, input, null, null); |
| 47 | ^ |
| 48 | /home/me/dev/zig-whatwg-url/test.zig:15:32: 0x1275c61 in test_2 (test.zig) |
| 49 | const u = try url.URL.parse(allocator, "https://en.wikipedia.org/w/index.php?title=URL", null); |
| 50 | ^ |
| 51 | /home/me/.local/share/zig/0.16.0/lib/compiler/test_runner.zig:291:25: 0x122fde6 in mainTerminal (test_runner.zig) |
| 52 | if (test_fn.func()) |_| { |
| 53 | ^ |
| 54 | /home/me/.local/share/zig/0.16.0/lib/compiler/test_runner.zig:73:28: 0x122f1e2 in main (test_runner.zig) |
| 55 | return mainTerminal(init); |
| 56 | ^ |
| 57 | /home/me/.local/share/zig/0.16.0/lib/std/start.zig:699:88: 0x122be0c in callMain (std.zig) |
| 58 | if (fn_info.params[0].type.? == std.process.Init.Minimal) return wrapMain(root.main(.{ |
| 59 | ^ |
| 60 | /home/me/.local/share/zig/0.16.0/lib/std/start.zig:638:20: 0x122bbe6 in callMainWithArgs (std.zig) |
| 61 | return callMain(argv[0..argc], env_block); |
| 62 | ^ |
| 63 | ???:?:?: 0x7ffff7c2a4d7 in __libc_start_call_main (/nix/store/km4g87jxsqxvcq344ncyb8h1i6f3cqxh-glibc-2.40-218/lib/libc.so.6) |
| 64 | ???:?:?: 0x7ffff7c2a59a in __libc_start_main_alias_2 (/nix/store/km4g87jxsqxvcq344ncyb8h1i6f3cqxh-glibc-2.40-218/lib/libc.so.6) |
| 65 | /home/me/.local/share/zig/0.16.0/lib/libc/glibc/sysdeps/x86_64/start.S:115: 0x164b0f0 in ??? (/home/me/.local/share/zig/0.16.0/lib/libc/glibc/sysdeps/x86_64/start.S) |
| 66 | call *__libc_start_main@GOTPCREL(%rip) |
| 67 | |
| 68 | |
| 69 | Thread 1 "test" received signal SIGABRT, Aborted. |
| 70 | __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44 |
| 71 | warning: 44 pthread_kill.c: No such file or directory |
| 72 | (gdb) bt |
| 73 | #0 __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44 |
| 74 | #1 0x00007ffff7c9cb13 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:78 |
| 75 | #2 0x00007ffff7c4190e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26 |
| 76 | #3 0x00007ffff7c28942 in __GI_abort () at abort.c:79 |
| 77 | #4 0x00000000010857c3 in process.abort () |
| 78 | #5 0x0000000001085481 in debug.defaultPanic (msg=..., first_trace_addr=...) |
| 79 | #6 0x000000000108bb44 in debug.FullPanic((function 'defaultPanic')).reachedUnreachable () |
| 80 | #7 0x0000000001294c45 in url.URL.parseBasic (alloc=..., input=..., base=..., state_override=...) |
| 81 | #8 0x0000000001274b1f in url.URL.parse (alloc=..., input=..., base=...) at url.zig:42 |
| 82 | #9 0x0000000001275c62 in test.test_2 () at test.zig:15 |
| 83 | #10 0x000000000122fde7 in test_runner.mainTerminal (init=...) |
| 84 | #11 0x000000000122f1e3 in test_runner.main (init=...) |
| 85 | #12 0x000000000122be0d in start.callMain (args=..., environ=...) |
| 86 | #13 0x000000000122bbe7 in start.main (c_argc=2, c_argv=0x7fffffffc408, c_envp=0x7fffffffc420) |
| 87 | ``` |
| 88 | |
| 89 | You can also use this with GUI debuggers such as [VS Code](https://code.visualstudio.com/docs/debugtest/debugging-configuration) and [Zed](https://zed.dev/docs/debugger). |