Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test-runner std.testing output settings #14245

Open
k0tran opened this issue Jan 8, 2023 · 1 comment · May be fixed by #22358
Open

Add test-runner std.testing output settings #14245

k0tran opened this issue Jan 8, 2023 · 1 comment · May be fixed by #22358
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@k0tran
Copy link

k0tran commented Jan 8, 2023

All std.testing uses std.debug.print.

I've tried implementing custom test-runner, but I couldn't manage the output of the testing library.
For example we have test:

test "sample" {
    @import("std").testing.expectEqual(test_func(), 3);
}

When cycling over builtin.test_functions and running failing test - error message prints immideatly. But I need to print it with special prefix <ERROR::>, which is currently seems impossible.

I think supplying test runner with pointer to error message would be quite useful.

@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Jan 8, 2023
@andrewrk andrewrk added this to the 0.11.0 milestone Jan 8, 2023
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels Jan 8, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
@Arnau478
Copy link
Contributor

Arnau478 commented Mar 29, 2024

Maybe we should make std.testing.print a variable function pointer that is set by the test runner, much like allocator_instance. I would default to std.testing.defaultPrint, which would be the current std.testing.print.

EDIT: Looking deeper into this, the approach I described before is not possible. This is because, taking a comptime argument and the anytype args, it cannot be set to a non-comptime variable. Having a writer instead of a print function would probably be a better approach.

Arnau478 added a commit to Arnau478/zig that referenced this issue Mar 29, 2024
Test runners can modify `std.testing.output` to have the `std.testing` functions output somewhere else, in a similar manner to `allocator_instance`.

Fixes ziglang#14245
@sfiedler0 sfiedler0 linked a pull request Dec 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants