1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
3 | |
4 | use std::io::Write; |
5 | use std::path::PathBuf; |
6 | |
7 | fn main() -> Result<(), Box<dyn std::error::Error>> { |
8 | // target/{debug|release}/build/package/out/ -> target/{debug|release} |
9 | let mut target_dir = PathBuf::from(std::env::var("OUT_DIR" ).unwrap()); |
10 | target_dir.pop(); |
11 | target_dir.pop(); |
12 | target_dir.pop(); |
13 | |
14 | println!("cargo:rustc-env=SLINT_ENABLE_EXPERIMENTAL_FEATURES=1" ,); |
15 | |
16 | let tests_file_path = |
17 | std::path::Path::new(&std::env::var_os("OUT_DIR" ).unwrap()).join("test_functions.rs" ); |
18 | |
19 | let mut tests_file = std::fs::File::create(&tests_file_path)?; |
20 | |
21 | for testcase in test_driver_lib::collect_test_cases("cases" )?.into_iter().filter(|testcase| { |
22 | // Style testing not supported yet |
23 | testcase.requested_style.is_none() |
24 | }) { |
25 | println!("cargo:rerun-if-changed= {}" , testcase.absolute_path.display()); |
26 | let test_function_name = testcase.identifier(); |
27 | let ignored = testcase.is_ignored("js" ); |
28 | |
29 | write!( |
30 | tests_file, |
31 | r##" |
32 | #[test] |
33 | {ignore} |
34 | fn test_nodejs_ {function_name}() {{ |
35 | nodejs::test(&test_driver_lib::TestCase {{ |
36 | absolute_path: std::path::PathBuf::from(r#" {absolute_path}"#), |
37 | relative_path: std::path::PathBuf::from(r#" {relative_path}"#), |
38 | requested_style: None, |
39 | }}).unwrap(); |
40 | }} |
41 | "## , |
42 | ignore = if ignored { "#[ignore]" } else { "" }, |
43 | function_name = test_function_name, |
44 | absolute_path = testcase.absolute_path.to_string_lossy(), |
45 | relative_path = testcase.relative_path.to_string_lossy(), |
46 | )?; |
47 | } |
48 | |
49 | println!("cargo:rustc-env=TEST_FUNCTIONS= {}" , tests_file_path.to_string_lossy()); |
50 | |
51 | Ok(()) |
52 | } |
53 | |