Fork of daniellemaywood.uk/gleam — Wasm codegen work
1.4 kB
60 lines
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2022 The Gleam contributors
3
4use std::path::PathBuf;
5
6pub fn main() {
7 println!("cargo:rerun-if-changed=cases");
8
9 let mut module = "// SPDX-License-Identifier: Apache-2.0
10// SPDX-FileCopyrightText: 2024 The Gleam contributors
11
12//! This file is generated by build.rs
13//! Do not edit it directly, instead add new test cases to ./cases
14"
15 .to_string();
16
17 let cases = PathBuf::from("./cases");
18
19 let mut names: Vec<_> = std::fs::read_dir(&cases)
20 .unwrap()
21 .map(|entry| entry.unwrap().file_name().into_string().unwrap())
22 .collect();
23 names.sort();
24
25 for name in names {
26 let path = cases.join(&name);
27 let path = path.to_str().unwrap().replace('\\', "/");
28 module.push_str(
29 "
30#[rustfmt::skip]
31#[test]
32fn ",
33 );
34 module.push_str(&name);
35 module.push_str("() {\n");
36 module.push_str(" let output = crate::prepare(\"");
37 module.push_str(&path);
38 module.push_str(
39 "\");
40 insta::assert_snapshot!(
41 \"",
42 );
43 module.push_str(&name);
44 module.push_str(
45 "\",
46 output,
47 \"",
48 );
49 module.push_str(&path);
50 module.push_str(
51 "\",
52 );
53}
54",
55 );
56 }
57
58 let out = PathBuf::from("./src/generated_tests.rs");
59 std::fs::write(out, module).unwrap();
60}