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

Test block doesn't run defer statement. #15890

Closed
andrewCodeDev opened this issue May 29, 2023 · 2 comments
Closed

Test block doesn't run defer statement. #15890

andrewCodeDev opened this issue May 29, 2023 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@andrewCodeDev
Copy link

andrewCodeDev commented May 29, 2023

Zig Version

0.11.0-dev.3312+ab37ab33c

Steps to Reproduce and Observed Behavior

I was following the tutorials on the Zig documentation for the multiple defer statements and wrote the following:

const std = @import("std");

test "Defer Multiple" {

    std.debug.print("\n0...", .{ });
    
    defer {
        std.debug.print("\n3...", .{ });
    }
    defer {
        std.debug.print("\n2...", .{ });
    }
    defer {
        std.debug.print("\n1...", .{ });
    }
}

When running this block of code with zig test, the output was:

Test [1/1] test.Defer Multiple... 
0...
1...
2...
All 1 tests passed.

Expected Behavior

Test [1/1] test.Defer Multiple... 
0...
1...
2...
3...
All 1 tests passed.
@andrewCodeDev andrewCodeDev added the bug Observed behavior contradicts documented or intended behavior label May 29, 2023
@mlugg
Copy link
Member

mlugg commented May 29, 2023

Duplicate of #6856. In general, you shouldn't use stdio in tests

@andrewCodeDev
Copy link
Author

Thanks for the quick response - I'll go look at that other issue and familiarize myself with it.

I see now that the expect function signals a failure through error handling which inadvertently answers my more fundamental question.

Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants