дзеркало
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]>
56 рядки
2.3 KiB
Rust
56 рядки
2.3 KiB
Rust
//! Own test process: the inherited shell deliberately differs from the login shell.
|
|
#![cfg(unix)]
|
|
|
|
mod common;
|
|
|
|
use ide_host::{Host, ops};
|
|
use std::sync::Arc;
|
|
use std::time::{Duration, Instant};
|
|
|
|
#[test]
|
|
fn terminal_activation_uses_the_resolved_default_shell() {
|
|
// SAFETY: no runtime or worker threads have been started.
|
|
unsafe { std::env::set_var("SHELL", "/not-the-terminal/docker") };
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
let root = dunce::canonicalize(tmp.path()).unwrap().join("project");
|
|
let bin = root.join(".venv/bin");
|
|
std::fs::create_dir_all(&bin).unwrap();
|
|
std::fs::write(root.join(".venv/pyvenv.cfg"), "home = /usr/bin\n").unwrap();
|
|
std::fs::write(bin.join("python"), "").unwrap();
|
|
for script in ["activate", "activate.fish", "activate.csh", "activate.nu", "Activate.ps1"] {
|
|
std::fs::write(bin.join(script), "echo activated > activation.marker\n").unwrap();
|
|
}
|
|
let runtime = tokio::runtime::Builder::new_multi_thread().worker_threads(2).enable_all().build().unwrap();
|
|
runtime.block_on(async {
|
|
let host = Arc::new(Host::new(common::host_config(tmp.path())));
|
|
host.trust.decide(&root, true, false).unwrap();
|
|
host.open_project("main", &root).unwrap();
|
|
for shell in [None, Some("".to_owned()), Some(" \t ".to_owned())] {
|
|
let terminal = ops::term::term_spawn(
|
|
&host,
|
|
"main",
|
|
ide_terminal::TerminalOptions {
|
|
cwd: root.clone().into(),
|
|
shell,
|
|
args: vec![],
|
|
env: Default::default(),
|
|
cols: 80,
|
|
rows: 24,
|
|
shell_integration: false,
|
|
},
|
|
ops::Channel::new(|_| {}),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
let deadline = Instant::now() + Duration::from_secs(10);
|
|
while !std::fs::read_to_string(root.join("activation.marker")).is_ok_and(|s| s.trim() == "activated") {
|
|
assert!(Instant::now() < deadline, "default terminal shell must run the activation script");
|
|
tokio::time::sleep(Duration::from_millis(20)).await;
|
|
}
|
|
host.terminals.kill(terminal.id).unwrap();
|
|
std::fs::remove_file(root.join("activation.marker")).unwrap();
|
|
}
|
|
host.shutdown().await;
|
|
});
|
|
}
|