# Objective
- Follow-up of #13184 :)
- We use `ui_test` to test compiler errors for our custom macros.
- There are four crates related to compile fail tests
- `bevy_ecs_compile_fail_tests`, `bevy_macros_compile_fail_tests`, and
`bevy_reflect_compile_fail_tests`, which actually test the macros.
-
[`bevy_compile_test_utils`](64c1c65783/crates/bevy_compile_test_utils),
which provides helpers and common patterns for these tests.
- All of these crates reside within the `crates` directory.
- This can be confusing, especially for newcomers. All of the other
folders in `crates` are actual published libraries, except for these 4.
## Solution
- Move all compile fail tests to a `compile_fail` folder under their
corresponding crate.
- E.g. `crates/bevy_ecs_compile_fail_tests` would be moved to
`crates/bevy_ecs/compile_fail`.
- Move `bevy_compile_test_utils` to `tools/compile_fail_utils`.
There are a few benefits to this approach:
1. An internal testing detail is less intrusive (and confusing) for
those who just want to browse the public Bevy interface.
2. Follows a pre-existing approach of organizing related crates inside a
larger crate's folder.
- See `bevy_gizmos/macros` for an example.
4. Makes consistent the terms `compile_test`, `compile_fail`, and
`compile_fail_test` in code. It's all just `compile_fail` now, because
we are specifically testing the error messages on compiler failures.
- To be clear it can still be referred to by these terms in comments and
speech, just the names of the crates and the CI command are now
consistent.
## Testing
Run the compile fail CI command:
```shell
cargo run -p ci -- compile-fail
```
If it still passes, then my refactor was successful.
55 lines
2.2 KiB
Rust
55 lines
2.2 KiB
Rust
use crate::{Flag, Prepare, PreparedCommand};
|
|
use argh::FromArgs;
|
|
use xshell::cmd;
|
|
|
|
/// Runs the compile-fail tests.
|
|
#[derive(FromArgs, Default)]
|
|
#[argh(subcommand, name = "compile-fail")]
|
|
pub struct CompileFailCommand {}
|
|
|
|
impl Prepare for CompileFailCommand {
|
|
fn prepare<'a>(&self, sh: &'a xshell::Shell, flags: Flag) -> Vec<PreparedCommand<'a>> {
|
|
let no_fail_fast = flags
|
|
.contains(Flag::KEEP_GOING)
|
|
.then_some("--no-fail-fast")
|
|
.unwrap_or_default();
|
|
|
|
let mut commands = vec![];
|
|
|
|
// Macro Compile Fail Tests
|
|
// Run tests (they do not get executed with the workspace tests)
|
|
// - See crates/bevy_macros_compile_fail_tests/README.md
|
|
commands.push(
|
|
PreparedCommand::new::<Self>(
|
|
cmd!(sh, "cargo test --target-dir ../../../target {no_fail_fast}"),
|
|
"Compiler errors of the macros compile fail tests seem to be different than expected! Check locally and compare rust versions.",
|
|
)
|
|
.with_subdir("crates/bevy_derive/compile_fail"),
|
|
);
|
|
|
|
// ECS Compile Fail Tests
|
|
// Run UI tests (they do not get executed with the workspace tests)
|
|
// - See crates/bevy_ecs_compile_fail_tests/README.md
|
|
commands.push(
|
|
PreparedCommand::new::<Self>(
|
|
cmd!(sh, "cargo test --target-dir ../../../target {no_fail_fast}"),
|
|
"Compiler errors of the ECS compile fail tests seem to be different than expected! Check locally and compare rust versions.",
|
|
)
|
|
.with_subdir("crates/bevy_ecs/compile_fail"),
|
|
);
|
|
|
|
// Reflect Compile Fail Tests
|
|
// Run tests (they do not get executed with the workspace tests)
|
|
// - See crates/bevy_reflect_compile_fail_tests/README.md
|
|
commands.push(
|
|
PreparedCommand::new::<Self>(
|
|
cmd!(sh, "cargo test --target-dir ../../../target {no_fail_fast}"),
|
|
"Compiler errors of the Reflect compile fail tests seem to be different than expected! Check locally and compare rust versions.",
|
|
)
|
|
.with_subdir("crates/bevy_reflect/compile_fail"),
|
|
);
|
|
|
|
commands
|
|
}
|
|
}
|