дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 09:41:34 +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]>
29 рядки
1.5 KiB
Rust
29 рядки
1.5 KiB
Rust
mod common;
|
|
|
|
use ide_host::Host;
|
|
use ide_host::ops::db;
|
|
use std::sync::Arc;
|
|
|
|
#[tokio::test]
|
|
async fn new_query_consoles_are_numbered_after_the_default_one() {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
let base = tmp.path();
|
|
let host = Arc::new(Host::new(common::host_config(base)));
|
|
let names = |paths: Vec<ide_core::IpcPath>| -> Vec<String> {
|
|
paths.iter().map(|p| p.0.file_name().unwrap().to_string_lossy().into_owned()).collect()
|
|
};
|
|
assert!(db::db_consoles(&host, "pg".into(), false).unwrap().is_empty());
|
|
// The first new console is the default one, then console_1, console_2…
|
|
assert_eq!(names(db::db_consoles(&host, "pg".into(), true).unwrap()), ["console.sql"]);
|
|
assert_eq!(names(db::db_consoles(&host, "pg".into(), true).unwrap()), ["console.sql", "console_1.sql"]);
|
|
let all = db::db_consoles(&host, "pg".into(), true).unwrap();
|
|
assert_eq!(names(all.clone()), ["console.sql", "console_1.sql", "console_2.sql"]);
|
|
// Numbers sort numerically, and the default console path is the first one.
|
|
std::fs::write(all[0].0.with_file_name("console_10.sql"), "").unwrap();
|
|
assert_eq!(names(db::db_consoles(&host, "pg".into(), false).unwrap())[3], "console_10.sql");
|
|
assert_eq!(db::db_console_path(&host, "pg".into()).unwrap().0, all[0].0);
|
|
// Each database of a source has its own consoles.
|
|
assert!(db::db_consoles(&host, "pg:other".into(), false).unwrap().is_empty());
|
|
assert!(db::db_consoles(&host, "../x".into(), true).is_err());
|
|
}
|