дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-27 04:56:08 +02:00
`HostConfig` (9 fields) was written out as a full struct literal in about 100 tests of `ide-host`, almost all of them the same boilerplate, so a new field meant editing ~100 places. This adds one base constructor for tests and migrates every literal that is a plain variant of it. Tests that differ keep struct-update overrides (`HostConfig { sink_for: .., ..HostConfig::for_test(&base) }`). No builder.
- Unit tests (`src/`): `#[cfg(test)] pub(crate) fn HostConfig::for_test(base: &Path)` in `lib.rs`.
- Integration tests (`tests/`): `tests/common/mod.rs` with `host_config(base: &Path)`, pulled in with `mod common;`. It builds the same value as `for_test`.
Both build: `config`, `data`, and `data` again as the machine-local dir (the layout most tests used), `LanguageRegistry::load(None)`, empty syntax, a sink that drops events, identity owner, `Handle::current()`, `project_environment: false`.
Why not one constructor for both: integration tests compile against the crate without `cfg(test)`, so a shared one needs a new `testing` cargo feature plus a dev-dependency on the crate itself (nothing in `ide-host` does that today). Two small definitions need no feature, no `Cargo.toml` change and no public item.
Co-authored-by: Mr0Bread <[email protected]>
28 рядки
1.2 KiB
Rust
28 рядки
1.2 KiB
Rust
mod common;
|
|
|
|
use ide_host::{Host, HostConfig, ops};
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn split_storage_keeps_user_history_and_uses_local_tools_and_caches() {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
let base = dunce::canonicalize(tmp.path()).unwrap();
|
|
let data = base.join("roaming");
|
|
let local = base.join("local");
|
|
let root = base.join("project");
|
|
std::fs::create_dir(&root).unwrap();
|
|
std::fs::write(root.join("notes.txt"), "hello\n").unwrap();
|
|
let host =
|
|
Host::new(HostConfig { data_dir: data.clone(), local_data_dir: local.clone(), ..common::host_config(&base) });
|
|
assert_eq!(std::path::PathBuf::from(ops::tools::jdk_download_location(&host).unwrap()), local.join("tools/jdks"));
|
|
let light = host.open_light("main", &root.join("notes.txt")).unwrap();
|
|
assert!(light.cache_dir.starts_with(&local));
|
|
assert!(data.join("history").exists());
|
|
assert!(!local.join("history").exists());
|
|
let project = host.open_project("main", &root).unwrap();
|
|
assert!(project.cache_dir.starts_with(&local));
|
|
assert!(local.join("index").exists());
|
|
assert!(!data.join("index").exists());
|
|
assert!(!data.join("tools").exists());
|
|
host.shutdown().await;
|
|
}
|