std.Progress inside of a test?

Hi,

Is there a way to create a std.Progress node during tests? I saw an issue about exposing the test’s progress node to code inside the test (which would be great), but I get a error when I try to call std.Progress.start() from inside of a test - is there a way to do that?

test "progress"
{
    _ = std.Progress.start(.{});
}

Thanks!

I think (although I don’t know and I only glanced through the source) that this is currently not possible. std.Progress.start uses a global Progress node and asserts that it is the only one, but the usual test runner (lib/compiler/test_runner.zig, for instance) takes it and only has a local handle to it.

2 Likes

Ok, so I had some functions that took a parent progress node as an argument - I can make those optional nodes.

That means that parent_node.start(…); becomes if (maybe_parent_node) |pn| pn.start(…);

Is there another pattern that folks have used to handle that?

And thanks for confirming!

1 Like

Calling start on Progress.Node.none is a no-op so you can just pass that instead of an optional

1 Like

I think another option would be to run those tests with a custom test runner, that either doesn’t use the std.Progress api or passes the parent node information to the test in some way.

I haven’t tried something like that yet (passing parent node info), but writing your own test runner is simpler than it sounds (especially if you don’t care about some of the features of the default test runner) and you can incrementally refine it until it suits your use case.