Skip to content

Commit d3e6c69

Browse files
committed
change macro format
This is both a better way to express multiple tests, and a signal to users that something has changed.
1 parent 631c248 commit d3e6c69

File tree

9 files changed

+298
-68
lines changed

9 files changed

+298
-68
lines changed

Cargo.lock

Lines changed: 159 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ include_dir = { version = "0.7.4", optional = true }
3535
libtest-mimic = "0.8.1"
3636
walkdir = "2.5.0"
3737

38+
[dev-dependencies]
39+
trybuild = "1.0.101"
40+
3841
[target.'cfg(unix)'.dev-dependencies]
3942
camino-tempfile = "1.1.1"
4043
fs_extra = "1.3.0"
@@ -44,7 +47,7 @@ name = "example"
4447
harness = false
4548

4649
[[test]]
47-
name = "run_example"
50+
name = "integration"
4851
harness = true
4952

5053
[features]

README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ name = "<test target name>"
3636
harness = false
3737
````
3838

39-
2. Call the `datatest_stable::harness!(testfn, root, pattern)` macro with the following
40-
parameters:
39+
2. Call the `datatest_stable::harness!` macro as:
4140

42-
* `testfn` - The test function to be executed on each matching input. This function can be one
41+
````rust,ignore
42+
datatest_stable::harness! {
43+
{ test = my_test, root = "path/to/fixtures", pattern = r"^.*/*" },
44+
}
45+
````
46+
47+
* `test` - The test function to be executed on each matching input. This function can be one
4348
of:
4449

4550
* `fn(&Path) -> datatest_stable::Result<()>`
@@ -67,7 +72,13 @@ harness = false
6772
`&str`, or a function call that returns a `String`.
6873

6974
The three parameters can be repeated if you have multiple sets of data-driven tests to be run:
70-
`datatest_stable::harness!(testfn1, root1, pattern1, testfn2, root2, pattern2)`.
75+
76+
````rust,ignore
77+
datatest_stable::harness! {
78+
{ test = testfn1, root = root1, pattern = pattern1 },
79+
{ test = testfn2, root = root2, pattern = pattern2 },
80+
}
81+
````
7182

7283
### Relative paths
7384

@@ -101,10 +112,10 @@ fn my_test_utf8(path: &Utf8Path, contents: String) -> datatest_stable::Result<()
101112
Ok(())
102113
}
103114

104-
datatest_stable::harness!(
105-
my_test, "path/to/fixtures", r"^.*/*",
106-
my_test_utf8, "path/to/fixtures", r"^.*/*",
107-
);
115+
datatest_stable::harness! {
116+
{ test = my_test, root = "path/to/fixtures", pattern = r"^.*/*" },
117+
{ test = my_test_utf8, root = "path/to/fixtures", pattern = r"^.*/*" },
118+
}
108119
````
109120

110121
If `path/to/fixtures` contains a file `foo/bar.txt`, then:
@@ -134,9 +145,9 @@ fn my_test(path: &Path, contents: Vec<u8>) -> datatest_stable::Result<()> {
134145
Ok(())
135146
}
136147

137-
datatest_stable::harness!(
138-
my_test, include_dir!("tests/files"), r"^.*/*",
139-
);
148+
datatest_stable::harness! {
149+
{ test = my_test, root = include_dir!("tests/files"), pattern = r"^.*/*" },
150+
}
140151
````
141152

142153
You can also use directories published as `static` items in upstream crates:
@@ -153,9 +164,9 @@ fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
153164
Ok(())
154165
}
155166

156-
datatest_stable::harness!(
157-
my_test, &FIXTURES, r"^.*/*",
158-
);
167+
datatest_stable::harness! {
168+
{ test = my_test, root = &FIXTURES, pattern = r"^.*/*" },
169+
}
159170
````
160171

161172
In this case, the passed-in `Path` and `Utf8Path` are **relative** to the
@@ -186,9 +197,9 @@ fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
186197
Ok(())
187198
}
188199

189-
datatest_stable::harness!(
190-
my_test, &FIXTURES, r"^.*/*",
191-
);
200+
datatest_stable::harness! {
201+
{ test = my_test, root = &FIXTURES, pattern = r"^.*/*" },
202+
}
192203
````
193204

194205
In this case, note that `path` will be relative to the **crate directory**

0 commit comments

Comments
 (0)