mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 12:04:39 +08:00
Port unit test initialization routine
Here are the differences to the C++ version in fish_tests: 1. we don't need to chdir to repo root, cargo test already does. 2. we don't need srandom because we already use deterministic RNGs for tests. 3. we don't yet call asan_before_exit(). Not yet sure how to hook into "cargo test" before exit.
This commit is contained in:
parent
b2d4619125
commit
ae9e7a25f8
|
@ -31,11 +31,17 @@ mod tokenizer;
|
|||
mod topic_monitor;
|
||||
mod wgetopt;
|
||||
|
||||
mod prelude {
|
||||
use crate::env::EnvStack;
|
||||
pub mod prelude {
|
||||
use crate::env::{env_init, misc_init};
|
||||
use crate::reader::reader_init;
|
||||
use crate::signal::signal_reset_handlers;
|
||||
pub use crate::tests::env::{PwdEnvironment, TestEnvironment};
|
||||
use crate::topic_monitor::topic_monitor_init;
|
||||
use crate::wutil::wgetcwd;
|
||||
use crate::{env::EnvStack, proc::proc_init};
|
||||
use once_cell::sync::Lazy;
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::ffi::CString;
|
||||
use std::sync::Mutex;
|
||||
|
||||
static PUSHED_DIRS: Lazy<Mutex<Vec<String>>> = Lazy::new(Mutex::default);
|
||||
|
@ -57,4 +63,28 @@ mod prelude {
|
|||
std::env::set_current_dir(old_cwd).unwrap();
|
||||
EnvStack::principal().set_pwd_from_getcwd();
|
||||
}
|
||||
|
||||
pub fn test_init() {
|
||||
static DONE: OnceCell<()> = OnceCell::new();
|
||||
DONE.get_or_init(|| {
|
||||
{
|
||||
let s = CString::new("").unwrap();
|
||||
unsafe {
|
||||
libc::setlocale(libc::LC_ALL, s.as_ptr());
|
||||
}
|
||||
}
|
||||
topic_monitor_init();
|
||||
crate::threads::init();
|
||||
proc_init();
|
||||
env_init(None, true, false);
|
||||
misc_init();
|
||||
reader_init();
|
||||
|
||||
// Set default signal handlers, so we can ctrl-C out of this.
|
||||
signal_reset_handlers();
|
||||
|
||||
// Set PWD from getcwd - fixes #5599
|
||||
EnvStack::principal().set_pwd_from_getcwd();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user