Add test for auto-cd

This commit is contained in:
YizhePKU 2024-06-01 20:06:11 +00:00
parent 9f5995e21f
commit e97aa2af0e

View File

@ -5,6 +5,38 @@ use nu_test_support::terminal::{
};
use std::{io::Write, time::Duration};
#[test]
fn auto_cd_works() {
// Setup a directory with a sub-directory in it.
let cwd = tempfile::tempdir().unwrap();
std::fs::create_dir(cwd.path().join("foo")).unwrap();
// Create the PTY and the terminal.
let mut pty = pty_with_nushell(
vec!["--no-config-file".to_string()],
Some(cwd.path().to_path_buf()),
);
let (mut term, mut events) = default_terminal();
// Wait for Nushell to initalize.
std::thread::sleep(Duration::from_millis(500));
#[cfg(windows)]
pty.writer().write_all(b".\\foo\r").unwrap();
#[cfg(unix)]
pty.writer().write_all(b"./foo\r").unwrap();
pty.writer().write_all(b"pwd\r").unwrap();
// Read the response from Nushell.
read_to_end(&mut term, &mut pty, &mut events, pty_write_handler);
// Examine the terminal state.
let (row, _col) = extract_cursor(&term);
let text = extract_text(&term);
assert!(text[row - 1].contains("foo"));
}
#[test]
fn command_hints_are_pwd_aware() {
// PWD-aware command hints require setting history file format to "sqlite".