slint/tests/doctests/main.rs
Simon Hausmann 4a9cd954b8 Rework the Rust entry point API for the interpreter
Switch to the stateful `ComponentCompiler` concept that we discussed for the C++ API.
2021-03-18 18:20:50 +01:00

37 lines
1.2 KiB
Rust

/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */
#[cfg(test)]
fn do_test(snippet: &str) -> Result<(), Box<dyn std::error::Error>> {
let mut compiler = sixtyfps_interpreter::ComponentCompiler::new();
let component =
spin_on::spin_on(compiler.build_from_source(snippet.into(), Default::default()));
#[cfg(feature = "display-diagnostics")]
sixtyfps_interpreter::print_diagnostics(&compiler.diagnostics());
for d in compiler.diagnostics() {
if d.level() == sixtyfps_interpreter::DiagnosticLevel::Error {
return Err(d.message().to_owned().into());
}
}
if component.is_none() {
Err(String::from("Failure").into())
} else {
Ok(())
}
}
include!(env!("TEST_FUNCTIONS"));
fn main() {
println!("Nothing to see here, please run me through cargo test :)");
}