Fork of daniellemaywood.uk/gleam — Wasm codegen work
1.1 kB
46 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(&format!(
29 r#"
30#[rustfmt::skip]
31#[test]
32fn {name}() {{
33 let output = crate::prepare("{path}");
34 insta::assert_snapshot!(
35 "{name}",
36 output,
37 "{path}",
38 );
39}}
40"#
41 ));
42 }
43
44 let out = PathBuf::from("./src/generated_tests.rs");
45 std::fs::write(out, module).unwrap();
46}