test_each/lib.rs
1#![deny(missing_docs)]
2#![doc = include_str!("../README.md")]
3
4#[doc(inline)]
5/// Generate a series of tests that receive file contents as strings,
6/// based on the result of a glob pattern.
7///
8/// This excludes any matched directories.
9///
10/// # Usage
11/// ```rust
12/// #[test_each::file(glob = "data/*.txt")]
13/// fn test_file(content: &str) {
14/// // test contents
15/// }
16/// ```
17///
18/// Add a second parameter that implements [`AsRef`](std::convert::AsRef)
19/// for [`Path`](std::path::Path) to receive the path of the file.
20/// ```rust
21/// #[test_each::file("data/*.txt")]
22/// fn test_file(content: &str, path: &Path) {
23/// // test contents
24/// }
25/// ```
26///
27/// ## Customizing the function name
28///
29/// Use `name(segments = <n>)` to use up to `n` path segments in the generated function name.
30///
31/// Use `name(extension)` to include the file extension in the generated function name.
32///
33/// Use `name(index)` to include a unique index in the generated function name.
34///
35/// ```rust
36/// #[test_each::file("data/*.txt", name(segments = 2, extension, index))]
37/// fn test_file(_: &str) { }
38/// ```
39pub use test_each_codegen::test_each_file as file;
40
41#[doc(inline)]
42/// Generate a series of tests that receive file contents as byte slices,
43/// based on the result of a glob pattern.
44///
45/// This excludes any matched directories.
46///
47/// # Usage
48/// ```rust
49/// #[test_each::blob("data/*.bin")]
50/// fn test_bytes(content: &[u8]) {
51/// // test contents
52/// }
53/// ```
54///
55/// Add a second parameter that implements [`AsRef`](std::convert::AsRef)
56/// for [`Path`](std::path::Path) to receive the path of the file.
57/// ```rust
58/// #[test_each::blob("data/*.bin")]
59/// fn test_bytes(content: &[u8], path: &Path) {
60/// // test contents
61/// }
62/// ```
63///
64/// ## Customizing the function name
65///
66/// Use `name(segments = <n>)` to use up to `n` path segments in the generated function name.
67///
68/// Use `name(extension)` to include the file extension in the generated function name.
69///
70/// Use `name(index)` to include a unique index in the generated function name.
71///
72/// ```rust
73/// #[test_each::blob("data/*.txt", name(segments = 2, extension, index))]
74/// fn test_file(_: &[u8]) { }
75/// ```
76pub use test_each_codegen::test_each_blob as blob;
77
78#[doc(inline)]
79/// Generate a series of tests that receive file paths,
80/// based on the result of a glob pattern.
81///
82/// This includes any matched directories.
83///
84/// # Usage
85/// ```rust
86/// #[test_each::path("data/*")]
87/// fn test_paths(path: &Path) {
88/// // test contents
89/// }
90/// ```
91///
92/// ## Customizing the function name
93///
94/// Use `name(segments = <n>)` to use up to `n` path segments in the generated function name.
95///
96/// Use `name(extension)` to include the file extension in the generated function name.
97///
98/// Use `name(index)` to include a unique index in the generated function name.
99///
100/// ```rust
101/// #[test_each::path("data/*.txt", name(segments = 2, extension, index))]
102/// fn test_file(_: &Path) { }
103/// ```
104pub use test_each_codegen::test_each_path as path;