2023-12-22 12:27:01 +01:00
|
|
|
mod abbrs;
|
2023-07-03 12:19:40 -07:00
|
|
|
mod common;
|
2023-10-08 23:22:27 +02:00
|
|
|
mod complete;
|
2023-12-09 16:48:02 +01:00
|
|
|
mod debounce;
|
2023-12-02 18:20:40 +01:00
|
|
|
mod editable_line;
|
2023-12-09 21:20:38 +01:00
|
|
|
mod encoding;
|
2023-10-08 23:22:27 +02:00
|
|
|
mod env;
|
|
|
|
mod env_universal_common;
|
|
|
|
mod expand;
|
2023-03-04 23:49:17 -06:00
|
|
|
mod fd_monitor;
|
2023-10-08 23:22:27 +02:00
|
|
|
mod highlight;
|
|
|
|
mod history;
|
2024-01-21 12:40:43 -08:00
|
|
|
mod input;
|
|
|
|
mod input_common;
|
2024-03-30 16:10:12 +01:00
|
|
|
mod key;
|
2023-12-02 16:26:45 +01:00
|
|
|
mod pager;
|
2023-12-09 20:47:43 +01:00
|
|
|
mod parse_util;
|
2023-10-08 23:22:27 +02:00
|
|
|
mod parser;
|
2023-12-22 12:27:01 +01:00
|
|
|
mod reader;
|
2023-10-08 23:22:27 +02:00
|
|
|
mod redirection;
|
2023-11-25 19:40:31 +01:00
|
|
|
mod screen;
|
2024-03-09 22:05:23 -06:00
|
|
|
mod std;
|
2023-07-03 12:19:40 -07:00
|
|
|
mod string_escape;
|
2024-03-23 17:22:52 +01:00
|
|
|
mod termsize;
|
2023-12-10 10:38:06 +01:00
|
|
|
mod threads;
|
2023-09-17 13:42:24 +02:00
|
|
|
mod tokenizer;
|
2023-10-08 23:22:27 +02:00
|
|
|
mod topic_monitor;
|
2023-12-09 17:10:36 +01:00
|
|
|
mod wgetopt;
|
2023-10-08 23:22:27 +02:00
|
|
|
|
2024-01-03 20:57:28 +01:00
|
|
|
pub mod prelude {
|
2024-03-24 12:28:47 +01:00
|
|
|
use crate::common::ScopeGuarding;
|
2024-01-03 20:57:28 +01:00
|
|
|
use crate::env::{env_init, misc_init};
|
2024-06-19 14:05:27 -07:00
|
|
|
use crate::parser::{Parser, ParserRef};
|
2024-01-03 20:57:28 +01:00
|
|
|
use crate::reader::reader_init;
|
|
|
|
use crate::signal::signal_reset_handlers;
|
2023-10-08 23:22:27 +02:00
|
|
|
pub use crate::tests::env::{PwdEnvironment, TestEnvironment};
|
2024-01-03 20:57:28 +01:00
|
|
|
use crate::topic_monitor::topic_monitor_init;
|
2023-10-08 23:22:27 +02:00
|
|
|
use crate::wutil::wgetcwd;
|
2024-01-03 20:57:28 +01:00
|
|
|
use crate::{env::EnvStack, proc::proc_init};
|
|
|
|
use once_cell::sync::OnceCell;
|
2024-06-19 14:05:27 -07:00
|
|
|
use std::cell::RefCell;
|
2024-01-12 09:11:56 +01:00
|
|
|
use std::env::set_current_dir;
|
2024-01-03 20:57:28 +01:00
|
|
|
use std::ffi::CString;
|
2024-06-19 14:05:27 -07:00
|
|
|
use std::rc::Rc;
|
2023-10-08 23:22:27 +02:00
|
|
|
|
2024-06-19 14:05:27 -07:00
|
|
|
/// A wrapper around a Parser with some test helpers.
|
|
|
|
pub struct TestParser {
|
|
|
|
parser: ParserRef,
|
|
|
|
pushed_dirs: RefCell<Vec<String>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestParser {
|
|
|
|
pub fn new() -> TestParser {
|
|
|
|
TestParser {
|
|
|
|
parser: Parser::new(Rc::new(EnvStack::new()), false),
|
|
|
|
pushed_dirs: RefCell::new(Vec::new()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Helper to chdir and then update $PWD.
|
|
|
|
pub fn pushd(&self, path: &str) {
|
|
|
|
let cwd = wgetcwd();
|
|
|
|
self.pushed_dirs.borrow_mut().push(cwd.to_string());
|
|
|
|
|
|
|
|
// We might need to create the directory. We don't care if this fails due to the directory
|
|
|
|
// already being present.
|
|
|
|
std::fs::create_dir_all(path).unwrap();
|
2023-10-08 23:22:27 +02:00
|
|
|
|
2024-06-19 14:05:27 -07:00
|
|
|
std::env::set_current_dir(path).unwrap();
|
|
|
|
self.parser.vars().set_pwd_from_getcwd();
|
|
|
|
}
|
2023-10-08 23:22:27 +02:00
|
|
|
|
2024-06-19 14:05:27 -07:00
|
|
|
pub fn popd(&self) {
|
|
|
|
let old_cwd = self.pushed_dirs.borrow_mut().pop().unwrap();
|
|
|
|
std::env::set_current_dir(old_cwd).unwrap();
|
|
|
|
self.parser.vars().set_pwd_from_getcwd();
|
|
|
|
}
|
2023-10-08 23:22:27 +02:00
|
|
|
}
|
|
|
|
|
2024-06-19 14:05:27 -07:00
|
|
|
impl std::ops::Deref for TestParser {
|
|
|
|
type Target = Parser;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.parser
|
|
|
|
}
|
2023-10-08 23:22:27 +02:00
|
|
|
}
|
2024-01-03 20:57:28 +01:00
|
|
|
|
2024-03-24 12:28:47 +01:00
|
|
|
pub fn test_init() -> impl ScopeGuarding<Target = ()> {
|
2024-01-03 20:57:28 +01:00
|
|
|
static DONE: OnceCell<()> = OnceCell::new();
|
|
|
|
DONE.get_or_init(|| {
|
2024-05-04 19:47:16 -05:00
|
|
|
// If we are building with `cargo build` and have build w/ `cmake`, FISH_BUILD_DIR might
|
|
|
|
// not yet exist.
|
|
|
|
std::fs::create_dir_all(env!("FISH_BUILD_DIR")).unwrap();
|
2024-01-12 09:11:56 +01:00
|
|
|
set_current_dir(env!("FISH_BUILD_DIR")).unwrap();
|
2024-01-03 20:57:28 +01:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Set default signal handlers, so we can ctrl-C out of this.
|
|
|
|
signal_reset_handlers();
|
|
|
|
|
|
|
|
// Set PWD from getcwd - fixes #5599
|
2024-06-23 13:49:30 -07:00
|
|
|
EnvStack::globals().set_pwd_from_getcwd();
|
2024-01-03 20:57:28 +01:00
|
|
|
});
|
2024-03-24 12:28:47 +01:00
|
|
|
reader_init()
|
2024-01-03 20:57:28 +01:00
|
|
|
}
|
2024-01-03 20:57:28 +01:00
|
|
|
|
|
|
|
pub use serial_test::serial;
|
2023-10-08 23:22:27 +02:00
|
|
|
}
|