Commit ad14280
authored
Added better filesystem layout testing harness (#15874)
### What does this PR try to resolve?
The goal is to make filesystem layout tests easier to understand and
review.
The `build-dir` test's have a [helper
fns](https://github.com/rust-lang/cargo/blob/master/tests/testsuite/build_dir.rs#L720)
that have imperative checks. While this works, its not easy to see what
its validating at a glance.
My thought is to reuse the snapbox infrastructure we already have for
the cargo ui tests.
The prototype in this PR generates a file tree (like the unix tree
command) and uses snapbox to compare against a snapshot. This makes the
layout tests much easier to read and failures are much more obvious what
what went wrong.
### Implementation Details
* The `LayoutTree` struct handles comparison logic (as opposed to using
snapbox directly)
* This avoids the issues initial implementation (ordering and platform
specific files, see full details below)
* If the comparison fails, 2 human readable tree's are generated and
snapbox is used to display the diffs.
* Note: These diffs are in-memory thus, do not support
`SNAPSHOTS=overwrite`. This is arguably good as often the overwrite
would be incorrect as the snapshots are platform specific.
* Snapshots would support conditional files based on the target os /
platform env
* Files/directories may be suffixed with
`[target_platform=<target-platform>]`
* Multiple platforms may be specified separated by comma
<details><summary>initial implementation issues</summary>
However there are some problems with the current implementation that
limit the usefulness of it.
1. Different platforms have different files which cause some tests to
fail
* Examples
* lib prefix/suffixes based on platform
* `dSYM` on macos
* One idea I have would be to have a cfg suffix after file name in the
tree like so
* `└── foo-[HASH].dSYM [cfg(target_os = "macos")]`
* This would also require rethinking the "tree lines" (`└`, `├`, `│`) to
handle optional files.
2. When dealing with build scripts there are multiple
`target/<profile>/build/pkg-[HASH]` directories. The hash changes the
order of the directories when generating the tree making snapshots
inconsistent.
* We have redactions to handle replacing the hash with a placeholder
`[HASH]`, but this does not help with the order.
</details>
---
Fun fact: These changes were written and tested at [Rust Forge
2025](https://rustforgeconf.com/) in New Zealand. 🇳🇿
🥳File tree
7 files changed
+429
-149
lines changed- crates/cargo-test-support
- src
- src/doc/contrib/src/tests
- tests/testsuite
7 files changed
+429
-149
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
232 | 238 | | |
233 | 239 | | |
234 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| |||
152 | 157 | | |
153 | 158 | | |
154 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
155 | 164 | | |
156 | 165 | | |
157 | 166 | | |
| |||
236 | 245 | | |
237 | 246 | | |
238 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
239 | 285 | | |
240 | 286 | | |
241 | 287 | | |
| |||
260 | 306 | | |
261 | 307 | | |
262 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
263 | 324 | | |
264 | 325 | | |
265 | 326 | | |
| |||
290 | 351 | | |
291 | 352 | | |
292 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
293 | 368 | | |
294 | 369 | | |
295 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
67 | 77 | | |
68 | 78 | | |
69 | 79 | | |
| |||
0 commit comments