Skip to content

zig test should offer more flexible inputs #8234

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

Closed
finleyjb opened this issue Mar 13, 2021 · 6 comments
Closed

zig test should offer more flexible inputs #8234

finleyjb opened this issue Mar 13, 2021 · 6 comments
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs
Milestone

Comments

@finleyjb
Copy link

It would really be helpful if I could run a command like below to run all tests within the src directory:

zig test src

I'm sure I can come up with the correct grep/find command to do something equivalent to this, but it would really be a lot easier if I could run a command like above.

@LemonBoy
Copy link
Contributor

LemonBoy commented Mar 13, 2021

This problem is already solved by using a nameless test block

test {
    _ = @import("src/test_file_1.zig");
    // ...
    _ = @import("src/test_file_N.zig");
}

@kenaryn
Copy link

kenaryn commented Mar 13, 2021

This hint shall be added to the Frequently Asked Questions in a "Testing" sub-section or even demonstrated as a example at ziglearn.org before being closed.

@finleyjb
Copy link
Author

I guess #8221 is worth noting here as well if it's a documentation issue.

Though I do still feel it would be nice to have a way to do something like this without having a list of files to maintain. Maybe some kind of comptime function could work? Then I could do something like:

test {
  testSuite("src");
}

This would import every source file within that directory. Maybe some sort of glob syntax so you could do something like:

test {
  testSuite("src/prefix_*.zig");
}

@g-w1
Copy link
Contributor

g-w1 commented Mar 13, 2021

you can do std.meta.refAllDecls(@This()); to reference all constants (basically all imported files).

@finleyjb
Copy link
Author

finleyjb commented Mar 13, 2021

you can do std.meta.refAllDecls(@This()); to reference all constants (basically all imported files).

I see that there's that method in std.meta, but there appears to also be one in std.testing. Is the latter what should be used?

EDIT: It looks like that got moved to testing:

pub const refAllDecls = @compileError("refAllDecls has been moved from std.meta to std.testing");

finleyjb added a commit to finleyjb/zig that referenced this issue Mar 13, 2021
This is so that it shows up in the generated documentation, as it came
up in ziglang#8234.
finleyjb added a commit to finleyjb/zig that referenced this issue Mar 13, 2021
This is so that it shows up in the generated documentation, as it came
up in ziglang#8234.
finleyjb added a commit to finleyjb/zig that referenced this issue Mar 13, 2021
This is so that it shows up in the generated documentation, as it came
up in ziglang#8234.
@SpexGuy SpexGuy added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs labels Mar 16, 2021
@Mouvedia
Copy link

Mouvedia commented Mar 25, 2021

This hint shall be added to the Frequently Asked Questions in a "Testing" sub-section or even demonstrated as a example at ziglearn.org before being closed.

https://github.com/ziglang/zig/wiki/Zig-Newcomer-Programming-FAQs
https://github.com/ziglang/zig/wiki/FAQ

@andrewrk andrewrk added this to the 0.8.0 milestone Jun 4, 2021
paulespinosa added a commit to paulespinosa/zig that referenced this issue Sep 29, 2021
Updates the Language Reference sections: Comments, Values, and Zig Test.

Zig Test section moved down with the goal "make sure it can be read top to
bottom sensibly" in mind (issue ziglang#1524).

Comments and Values section examples changed test declarations to a main
function and expect statement to print statments.

A print statement was added to the "String Literals and Unicode Code Point"
section's example to demonstrate the "u" format specifier.

Zig Test Section:
* Addresses the question: "How does the syntax work?".
* Partially answers the question: "What can I do with the zig test tool?" but
should be sufficient to understand the examples in all of this document.
* Addresses the question: "How does a top-level test block differ from a function definition?"
* Provides a example to run multiple test.

Lacks clear definitions of containers, top-level, order independence, lazy
analysis, resolve, and reference.

GitHub Issues: ziglang#8221, ziglang#8234
paulespinosa added a commit to paulespinosa/zig that referenced this issue Sep 29, 2021
Updates the Language Reference sections: Comments, Values, and Zig Test.

Zig Test section moved down with the goal "make sure it can be read top to
bottom sensibly" in mind (issue ziglang#1524).

Comments and Values section examples changed test declarations to a main
function and expect statement to print statements.

A print statement was added to the "String Literals and Unicode Code Point"
section's example to demonstrate the "u" format specifier.

Zig Test Section:
* Addresses the question: "How does the syntax work?".
* Partially answers the question: "What can I do with the zig test tool?" but
should be sufficient to understand the examples in all of this document.
* Addresses the question: "How does a top-level test block differ from a function definition?"
* Provides a example to run multiple test.

Lacks clear definitions of containers, top-level, order independence, lazy
analysis, resolve, reference.

GitHub Issues: ziglang#8221, ziglang#8234
paulespinosa added a commit to paulespinosa/zig that referenced this issue Sep 29, 2021
Updates the Language Reference sections: Comments, Values, and Zig Test.

Zig Test section moved down with the goal "make sure it can be read top to
bottom sensibly" in mind (issue ziglang#1524).

Comments and Values section examples changed test declarations to a main
function and expect statement to print statements.

A print statement was added to the "String Literals and Unicode Code Point"
section's example to demonstrate the "u" format specifier.

Zig Test Section:
* Addresses the question: "How does the syntax work?".
* Partially answers the question: "What can I do with the zig test tool?" but
should be sufficient to understand the examples in all of this document.
* Addresses the question: "How does a top-level test block differ from a function definition?"
* Provides a example to run multiple test.

Lacks clear definitions of containers, top-level, order independence, lazy
analysis, resolve, reference.

GitHub Issues: ziglang#8221, ziglang#8234
paulespinosa added a commit to paulespinosa/zig that referenced this issue Sep 30, 2021
Updates the Language Reference sections: Comments, Values, and Zig Test.

Zig Test section moved down with the goal "make sure it can be read top to
bottom sensibly" in mind (issue ziglang#1524).

Comments and Values section examples changed test declarations to a main
function and expect statement to print statements.

A print statement was added to the "String Literals and Unicode Code Point"
section's example to demonstrate the "u" format specifier.

Zig Test Section:
* Addresses the question: "How does the syntax work?".
* Partially answers the question: "What can I do with the zig test tool?" but
should be sufficient to understand the examples in all of this document.
* Addresses the question: "How does a top-level test block differ from a function definition?"
* Provides a example to run multiple test.

Lacks clear definitions of containers, top-level, order independence, lazy
analysis, resolve, reference.

GitHub Issues: ziglang#8221, ziglang#8234
paulespinosa added a commit to paulespinosa/zig that referenced this issue Sep 30, 2021
Updates the Language Reference sections: Comments, Values, and Zig Test.

Zig Test section moved down with the goal "make sure it can be read top to
bottom sensibly" in mind (issue ziglang#1524).

Comments and Values section examples changed test declarations to a main
function and expect statement to print statements.

A print statement was added to the "String Literals and Unicode Code Point"
section's example to demonstrate the "u" format specifier.

Zig Test Section:
* Addresses the question: "How does the syntax work?".
* Partially answers the question: "What can I do with the zig test tool?" but
should be sufficient to understand the examples in all of this document.
* Addresses the question: "How does a top-level test block differ from a function definition?"
* Provides a example to run multiple test.

Lacks clear definitions of containers, top-level, order independence, lazy
analysis, resolve, reference.

GitHub Issues: ziglang#8221, ziglang#8234
andrewrk pushed a commit that referenced this issue Oct 4, 2021
Updates the Language Reference sections: Comments, Values, and Zig Test.

Zig Test section moved down with the goal "make sure it can be read top to
bottom sensibly" in mind (issue #1524).

Comments and Values section examples changed test declarations to a main
function and expect statement to print statements.

A print statement was added to the "String Literals and Unicode Code Point"
section's example to demonstrate the "u" format specifier.

Zig Test Section:
* Addresses the question: "How does the syntax work?".
* Partially answers the question: "What can I do with the zig test tool?" but
should be sufficient to understand the examples in all of this document.
* Addresses the question: "How does a top-level test block differ from a function definition?"
* Provides a example to run multiple test.

Lacks clear definitions of containers, top-level, order independence, lazy
analysis, resolve, reference.

GitHub Issues: #8221, #8234
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. docs
Projects
None yet
Development

No branches or pull requests

7 participants