Add a test for embedded conditionals

Also fix the initialization of properties in C++, make them zero-initialized like in rust
This commit is contained in:
Olivier Goffart 2020-06-16 17:47:10 +02:00
parent d7fe69ff74
commit e8c825b434
3 changed files with 28 additions and 13 deletions

View file

@ -43,6 +43,6 @@ struct Property
private: private:
internal::PropertyHandleOpaque inner; internal::PropertyHandleOpaque inner;
mutable T value; mutable T value{};
}; };
} }

View file

@ -1,14 +1,21 @@
TestCase := Rectangle { TestCase := Rectangle {
property<bool> condition; property<bool> condition;
property<int32> test_value: condition ? 1 : 2; property<int32> test_value: condition ? 1 : 2;
property<bool> condition2;
property<int32> test_value2: condition ? condition2 ? 1 : 2 : condition2 ? 3 : 4;
} }
/* /*
```cpp ```cpp
TestCase instance; TestCase instance;
instance.set_condition(true); instance.set_condition(true);
assert(instance.get_test_value() == 1); assert(instance.get_test_value() == 1);
assert(instance.get_test_value2() == 2);
instance.set_condition(false); instance.set_condition(false);
assert(instance.get_test_value() == 2); assert(instance.get_test_value() == 2);
assert(instance.get_test_value2() == 4);
instance.set_condition2(true);
assert(instance.get_test_value2() == 3);
``` ```
@ -16,8 +23,12 @@ assert(instance.get_test_value() == 2);
let instance = TestCase::default(); let instance = TestCase::default();
instance.set_condition(true); instance.set_condition(true);
assert_eq!(instance.get_test_value(), 1); assert_eq!(instance.get_test_value(), 1);
assert_eq!(instance.get_test_value2(), 2);
instance.set_condition(false); instance.set_condition(false);
assert_eq!(instance.get_test_value(), 2); assert_eq!(instance.get_test_value(), 2);
assert_eq!(instance.get_test_value2(), 4);
instance.set_condition2(true);
assert_eq!(instance.get_test_value2(), 3);
``` ```
```js ```js

View file

@ -1,6 +1,7 @@
use sixtyfps_compilerlib::*; use sixtyfps_compilerlib::*;
use std::error::Error; use std::error::Error;
use std::io::Write; use std::io::Write;
use std::ops::Deref;
pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box<dyn Error>> { pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box<dyn Error>> {
let source = std::fs::read_to_string(&testcase.absolute_path)?; let source = std::fs::read_to_string(&testcase.absolute_path)?;
@ -82,20 +83,23 @@ pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box<dyn Error>>
return Err("C++ Compilation error (see stdout)".to_owned().into()); return Err("C++ Compilation error (see stdout)".to_owned().into());
} }
std::process::Command::new(binary_path.clone()) let output = std::process::Command::new(binary_path.deref())
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.spawn() .spawn()
.map_err(|err| format!("Error launching testcase binary: {}", err))? .map_err(|err| format!("Error launching testcase binary: {}", err))?
.wait() .wait_with_output()
.map_err(|err| format!("Test case could not be run: {}", err)) .map_err(|err| format!("Test case could not be run: {}", err))?;
.and_then(|status| {
if status.success() { if !output.status.success() {
Ok(()) print!("{}", String::from_utf8_lossy(output.stdout.as_ref()));
} else if let Some(exit_code) = status.code() { print!("{}", String::from_utf8_lossy(output.stderr.as_ref()));
Err(format!("Test case exited with non-zero code: {}", exit_code)) if let Some(exit_code) = output.status.code() {
} else { return Err(format!("Test case exited with non-zero code: {}", exit_code).into());
Err("Test case exited by signal".into()) } else {
} return Err("Test case exited by signal".into());
})?; }
}
if keep_temp_files { if keep_temp_files {
println!( println!(