Zig Debugging with LLDB

Yes, there are ways to debug tests.

zig build test actually produces an executable and then runs the executable.

Calling addTest, without calling addRunArtifact the test executable is produced but it is not run.

You can run lldb using the addSystemCommand:

    const unit_tests = b.addTest({
        // TODO add here the test options
    });

    const lldb = b.addSystemCommand(&.{
        "lldb",
        // add lldb flags before --
        "--",
    });
    // appends the unit_tests executable path to the lldb command line
    lldb.addArtifactArg(unit_tests);
    // lldb.addArg can add arguments after the executable path

    const lldb_step = b.step("debug", "run the tests under lldb");
    lldb_step.dependOn(&lldb.step);
7 Likes