widgets tests: Also test with the interpreter

This commit is contained in:
Olivier Goffart 2024-05-07 12:38:33 +02:00 committed by GitHub
parent ac53049408
commit af09222dfd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 15 deletions

View file

@ -6,17 +6,17 @@ import { Slider } from "std-widgets.slint";
export component TestCase inherits Window {
width: 100px;
height: 100px;
slider_min_pos := Slider {
minimum: 10;
maximum: 100;
}
out property <float> pos-val <=> slider-min-pos.value;
slider_min_default := Slider {
maximum: 100;
}
out property <float> default-min <=> slider-min-default.minimum;
out property <float> default-min <=> slider-min-default.minimum;
out property <float> default-val <=> slider-min-default.value;
slider_min_neg := Slider {
@ -24,6 +24,8 @@ export component TestCase inherits Window {
maximum: 100;
}
out property <float> neg-val <=> slider-min-neg.value;
out property <bool> test: pos-val == 10 && default-min == 0 && default-val == 0 && neg-val == -10;
}

View file

@ -14,10 +14,16 @@ pub struct TestCase {
impl TestCase {
/// Return a string which is a valid C++/Rust identifier
pub fn identifier(&self) -> String {
self.relative_path
let mut result = self
.relative_path
.with_extension("")
.to_string_lossy()
.replace([std::path::MAIN_SEPARATOR, '-'], "_")
.replace([std::path::MAIN_SEPARATOR, '-'], "_");
if let Some(requested_style) = &self.requested_style {
result.push_str("_");
result.push_str(requested_style);
}
result
}
/// Returns true if the test case should be ignored for the specified driver.

View file

@ -9,10 +9,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut tests_file = std::fs::File::create(&tests_file_path)?;
for testcase in test_driver_lib::collect_test_cases("cases")?.into_iter().filter(|testcase| {
// Style testing not supported yet
testcase.requested_style.is_none()
}) {
for testcase in test_driver_lib::collect_test_cases("cases")?.into_iter() {
let test_function_name = testcase.identifier();
let ignored = testcase.is_ignored("interpreter");
@ -25,7 +22,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
interpreter::test(&test_driver_lib::TestCase{{
absolute_path: std::path::PathBuf::from(r#"{absolute_path}"#),
relative_path: std::path::PathBuf::from(r#"{relative_path}"#),
requested_style: None,
requested_style: {requested_style},
}}).unwrap();
}}
"##,
@ -33,6 +30,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
function_name = test_function_name,
absolute_path = testcase.absolute_path.to_string_lossy(),
relative_path = testcase.relative_path.to_string_lossy(),
requested_style =
testcase.requested_style.map_or("None".into(), |style| format!("Some({style:?})")),
)?;
}

View file

@ -18,7 +18,7 @@ pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box<dyn Error>>
let mut compiler = slint_interpreter::ComponentCompiler::default();
compiler.set_include_paths(include_paths);
compiler.set_library_paths(library_paths);
compiler.set_style(String::from("fluent")); // force to fluent style as Qt does not like multi-threaded test execution
compiler.set_style(testcase.requested_style.unwrap_or("fluent").into());
let component =
spin_on::spin_on(compiler.build_from_source(source, testcase.absolute_path.clone()));

View file

@ -15,10 +15,6 @@ fn main() -> std::io::Result<()> {
if module_name.starts_with(|c: char| !c.is_ascii_alphabetic()) {
module_name.insert(0, '_');
}
if let Some(style) = testcase.requested_style {
module_name.push('_');
module_name.push_str(style);
}
writeln!(generated_file, "#[path=\"{0}.rs\"] mod r#{0};", module_name)?;
let source = std::fs::read_to_string(&testcase.absolute_path)?;
let ignored = testcase.is_ignored("rust");