Skip to content

Commit 163a71b

Browse files
committed
fix projects not compiling if compile tests fail
1 parent 8cafb7f commit 163a71b

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎wgsl_to_wgpu/test_compile/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ half = { version = "2.7", features = ["bytemuck"] }
1111
nalgebra = "0.34"
1212
serde = { version = "1.0", features = ["derive"] }
1313
wgpu.workspace = true
14+
trybuild = "1.0"

‎wgsl_to_wgpu/test_compile/build.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ use std::{ffi::OsStr, path::Path};
22

33
const PATH: &str = "../src/snapshots";
44

5-
/// Create a file, which imports all snapshots in `PATH`.
65
fn main() {
76
println!("cargo:rerun-if-changed=build.rs");
87
println!("cargo:rerun-if-changed={}", PATH);
98

9+
// Create a file that imports all snapshots in `PATH`.
1010
let mut import_snapshots = String::new();
1111
for entry in std::fs::read_dir(PATH).unwrap() {
1212
let path = entry.unwrap().path().canonicalize().unwrap();
1313

14+
// TODO: prefer snapshot.new.rs if it exists
1415
if path.extension() != Some(OsStr::new("rs")) {
1516
continue;
1617
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![allow(clippy::unnecessary_cast, nonstandard_style)]
2+
include!(concat!(env!("OUT_DIR"), "/import_snapshots.rs"));
3+
4+
// trybuild requires a main function.
5+
fn main() {}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
#![allow(clippy::unnecessary_cast, nonstandard_style)]
2-
include!(concat!(env!("OUT_DIR"), "/import_snapshots.rs"));
1+
#[test]
2+
fn test_compile() {
3+
// Don't include the generated modules here directly.
4+
// This allows projects to compile even with invalid generated code.
5+
// TODO: this test failure skips other tests unless using --no-fail-fast
6+
// TODO: generate a test.pass for each file instead?
7+
// TODO: write file to OUT_DIR for each snapshot with a dummy main function.
8+
let t = trybuild::TestCases::new();
9+
t.pass("src/compile_tests.rs");
10+
}

0 commit comments

Comments
 (0)