i-slint-compiler: Add some tests for fileaccess

This commit is contained in:
Tobias Hunger 2023-10-24 19:09:02 +02:00 committed by Tobias Hunger
parent a76c3ec789
commit 46b7839db2

View file

@ -38,6 +38,44 @@ pub fn load_file(path: &std::path::Path) -> Option<VirtualFile> {
}
}
#[test]
fn test_load_file() {
let builtin = load_file(&std::path::PathBuf::from(
"builtin:/foo/../common/./MadeWithSlint-logo-dark.svg",
))
.unwrap();
assert!(builtin.is_builtin());
assert_eq!(
builtin.canon_path,
std::path::PathBuf::from("builtin:/common/MadeWithSlint-logo-dark.svg")
);
let dir = std::env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().to_string();
let dir_path = std::path::PathBuf::from(dir);
let non_existing = dir_path.join("XXXCargo.tomlXXX");
assert!(load_file(&non_existing).is_none());
assert!(dir_path.exists()); // We need some existing path for all the rest
let cargo_toml = dir_path.join("Cargo.toml");
let abs_cargo_toml = load_file(&cargo_toml).unwrap();
assert!(!abs_cargo_toml.is_builtin());
assert!(crate::pathutils::is_absolute(&abs_cargo_toml.canon_path));
assert!(abs_cargo_toml.canon_path.exists());
let current = std::env::current_dir().unwrap();
assert!(current.ends_with("compiler")); // This test is run in .../internal/compiler
let cargo_toml = std::path::PathBuf::from("./tests/../Cargo.toml");
let rel_cargo_toml = load_file(&cargo_toml).unwrap();
assert!(!rel_cargo_toml.is_builtin());
assert!(crate::pathutils::is_absolute(&rel_cargo_toml.canon_path));
assert!(rel_cargo_toml.canon_path.exists());
assert_eq!(abs_cargo_toml.canon_path, rel_cargo_toml.canon_path);
}
mod builtin_library {
include!(env!("SLINT_WIDGETS_LIBRARY"));