use super::*;
#[test]
fn the_hot_build_names_features_and_sets_no_rustflags() {
assert!(
HotMode::Dev.hot_features().contains(&"telar/hot-reload"),
"the dylib half of the loop has to ask for the hot-reload shape"
);
assert!(
!HotMode::Dev
.hot_features()
.iter()
.any(|f| f.contains("cfg")),
"a build shape carried in rustflags recompiles the whole graph on every switch"
);
}
fn watch_probe(name: &str) -> PathBuf {
let root =
std::env::temp_dir().join(format!("cargo_telar_watch_{name}_{}", std::process::id()));
let _ = std::fs::remove_dir_all(&root);
for dir in ["src", "assets", "locales"] {
std::fs::create_dir_all(root.join(dir)).unwrap();
}
std::fs::write(root.join("Cargo.toml"), "[package]\nname = \"solo\"\n").unwrap();
root
}
#[test]
fn the_asset_and_locale_roots_are_watched_too() {
let root = watch_probe("dirs");
let dirs = collect_watch_dirs(&root);
assert!(dirs.contains(&root.join("src")), "{dirs:?}");
assert!(dirs.contains(&root.join("assets")), "{dirs:?}");
assert!(dirs.contains(&root.join("locales")), "{dirs:?}");
let _ = std::fs::remove_dir_all(&root);
}
#[test]
fn a_lone_package_is_watched_at_all() {
let root = watch_probe("lone");
assert!(
!collect_watch_dirs(&root).is_empty(),
"a lone package still has directories worth watching"
);
let _ = std::fs::remove_dir_all(&root);
}
#[test]
fn absent_directories_are_left_out() {
let root = watch_probe("absent");
std::fs::remove_dir_all(root.join("locales")).unwrap();
let dirs = collect_watch_dirs(&root);
assert!(!dirs.contains(&root.join("locales")), "{dirs:?}");
assert!(dirs.contains(&root.join("assets")), "{dirs:?}");
let _ = std::fs::remove_dir_all(&root);
}
#[test]
fn a_directory_inside_another_is_not_watched_separately() {
let root = watch_probe("nested");
std::fs::create_dir_all(root.join("src/shared/assets")).unwrap();
std::fs::write(
root.join("telar.toml"),
"[telar]\nassets = \"src/shared/assets\"\n",
)
.unwrap();
let dirs = collect_watch_dirs(&root);
assert!(dirs.contains(&root.join("src")), "{dirs:?}");
assert!(
!dirs.contains(&root.join("src/shared/assets")),
"the asset root is already covered by the recursive watch on src/: {dirs:?}"
);
let _ = std::fs::remove_dir_all(&root);
}
#[test]
fn an_asset_extension_is_a_rebuild_event() {
let event = notify::Event {
kind: EventKind::Modify(notify::event::ModifyKind::Data(
notify::event::DataChange::Content,
)),
paths: vec![PathBuf::from("/p/assets/badge.webp")],
attrs: Default::default(),
};
assert!(
note_event(&event),
"an edited asset has to rebuild, or the baked artifact goes stale"
);
}
#[test]
fn the_dev_loop_names_no_frontend_of_its_own() {
assert_eq!(HotMode::Dev.features(), &["telar/dev"]);
assert!(
!HotMode::Dev.hot_features().contains(&"telar/desktop-bare"),
"the window the hot host opens comes with `telar/hot-reload`, which names it in the manifest"
);
assert!(
HotMode::Preview.features().contains(&"telar/preview"),
"the preview host is reached through its own feature whatever the target draws on"
);
}
#[test]
fn the_dylib_is_built_with_the_binarys_features() {
let args = [
"-p",
"sandbox",
"--no-default-features",
"--features",
"sandbox/tui",
]
.map(str::to_string);
let lib_args = make_lib_build_args(&args, &["telar/dev"]);
assert!(
lib_args.contains(&"--no-default-features".to_string()),
"{lib_args:?}"
);
let features = lib_args
.iter()
.position(|arg| arg == "--features")
.and_then(|pos| lib_args.get(pos + 1))
.cloned()
.unwrap_or_default();
assert!(features.contains("sandbox/tui"), "{lib_args:?}");
assert!(features.contains("telar/dev"), "{lib_args:?}");
}