#How to handle tests in modules

1 messages · Page 1 of 1 (latest)

ancient forge
#

I have recently learned about 'flattening' structs in files - removing the pub const <name> = struct { bit - and then giving it a name via const <name> = @This();
I like this a lot. However, I have tests at the bottom of the file that are now also imported, and are run when I call Zig test on the importing file.

To clarify, a simplified case:```// file_1 imports file_2
// file_1 has 1 test; file_2 has 2 tests

zig test file_1
All 3 tests pass```

What is the proper way to handle this? Should I move the tests for file_2 into a separate file, or is it generally fine to run both files' tests together? How do you all handle this situation?

Your advice is appreciated 🙂

tranquil cypress
#

it's normal for zig test root.zig to run all of the tests in the module, by doing

test {
    _ = @import("other.zig");
}

to reference other files with tests from the root file

ancient forge
#

Ok, that's good to know. I haven't quite gotten around to using root.zig but I'll look into it asap.

#

For now, while developing file_1, is there any benefit to isolating the tests from distinct files? Is there a way to do that?