mirror of
https://github.com/nushell/nushell
synced 2024-12-29 14:33:13 +00:00
1ba5b25b29
* Make `g -` switch to the last used shell Related #6223 Signed-off-by: nibon7 <nibon7@163.com> * simplify error handling Signed-off-by: nibon7 <nibon7@163.com> * update NUSHELL_LAST_SHELL environment Signed-off-by: nibon7 <nibon7@163.com> * add test Signed-off-by: nibon7 <nibon7@163.com> * fix description Signed-off-by: nibon7 <nibon7@163.com>
91 lines
1.9 KiB
Rust
91 lines
1.9 KiB
Rust
use nu_test_support::{nu, pipeline, playground::Playground};
|
|
|
|
#[test]
|
|
fn list_shells() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"g | get path | length "#
|
|
));
|
|
|
|
assert_eq!(actual.out, "1");
|
|
}
|
|
|
|
#[test]
|
|
fn enter_shell() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"g 0"#
|
|
));
|
|
|
|
assert!(actual.err.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn enter_not_exist_shell() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"g 1"#
|
|
));
|
|
|
|
assert!(actual.err.contains("Not found"));
|
|
}
|
|
|
|
#[test]
|
|
fn switch_to_last_used_shell_1() {
|
|
Playground::setup("switch_last_used_shell_1", |dirs, sandbox| {
|
|
sandbox.mkdir("foo").mkdir("bar");
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
pipeline(
|
|
r#"enter foo; enter ../bar; g 0; g -;g | get active.2"#
|
|
));
|
|
|
|
assert_eq!(actual.out, "true");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn switch_to_last_used_shell_2() {
|
|
Playground::setup("switch_last_used_shell_2", |dirs, sandbox| {
|
|
sandbox.mkdir("foo").mkdir("bar");
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
pipeline(
|
|
r#"enter foo; enter ../bar; n; g -;g | get active.2"#
|
|
));
|
|
|
|
assert_eq!(actual.out, "true");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn switch_to_last_used_shell_3() {
|
|
Playground::setup("switch_last_used_shell_3", |dirs, sandbox| {
|
|
sandbox.mkdir("foo").mkdir("bar");
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
pipeline(
|
|
r#"enter foo; enter ../bar; p; g -;g | get active.2"#
|
|
));
|
|
|
|
assert_eq!(actual.out, "true");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn switch_to_last_used_shell_4() {
|
|
Playground::setup("switch_last_used_shell_4", |dirs, sandbox| {
|
|
sandbox.mkdir("foo").mkdir("bar");
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
pipeline(
|
|
r#"enter foo; enter ../bar; g 2; exit; g -;g | get active.0"#
|
|
));
|
|
|
|
assert_eq!(actual.out, "true");
|
|
})
|
|
}
|