2019-12-17 19:54:39 +01:00
|
|
|
use nu_test_support::fs::{Stub::EmptyFile, Stub::FileWithContent};
|
2020-05-07 13:03:43 +02:00
|
|
|
use nu_test_support::nu;
|
2019-12-17 19:54:39 +01:00
|
|
|
use nu_test_support::playground::Playground;
|
2019-09-08 10:09:05 +02:00
|
|
|
use std::path::PathBuf;
|
2019-09-08 07:10:08 +02:00
|
|
|
|
2019-08-06 09:05:47 +02:00
|
|
|
#[test]
|
2019-09-08 12:15:55 +02:00
|
|
|
fn filesystem_change_from_current_directory_using_relative_path() {
|
2019-09-08 10:09:05 +02:00
|
|
|
Playground::setup("cd_test_1", |dirs, _| {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.root(),
|
|
|
|
r#"
|
|
|
|
cd cd_test_1
|
|
|
|
pwd | echo $it
|
|
|
|
"#
|
|
|
|
);
|
2019-08-06 09:05:47 +02:00
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), *dirs.test());
|
2019-09-08 10:09:05 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filesystem_change_from_current_directory_using_absolute_path() {
|
|
|
|
Playground::setup("cd_test_2", |dirs, _| {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
2020-06-07 05:50:52 +02:00
|
|
|
cd "{}"
|
2019-09-08 10:09:05 +02:00
|
|
|
pwd | echo $it
|
|
|
|
"#,
|
|
|
|
dirs.formats()
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), dirs.formats());
|
2019-09-11 16:36:50 +02:00
|
|
|
})
|
2019-08-16 00:18:18 +02:00
|
|
|
}
|
2019-09-08 07:10:08 +02:00
|
|
|
|
|
|
|
#[test]
|
2019-09-08 10:09:05 +02:00
|
|
|
fn filesystem_switch_back_to_previous_working_directory() {
|
|
|
|
Playground::setup("cd_test_3", |dirs, sandbox| {
|
|
|
|
sandbox.mkdir("odin");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test().join("odin"),
|
|
|
|
r#"
|
|
|
|
cd {}
|
|
|
|
cd -
|
|
|
|
pwd | echo $it
|
|
|
|
"#,
|
|
|
|
dirs.test()
|
|
|
|
);
|
2019-09-08 07:10:08 +02:00
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), dirs.test().join("odin"));
|
2019-09-08 10:09:05 +02:00
|
|
|
})
|
|
|
|
}
|
2019-09-08 07:10:08 +02:00
|
|
|
|
2019-09-08 11:55:49 +02:00
|
|
|
#[test]
|
|
|
|
fn filesytem_change_from_current_directory_using_relative_path_and_dash() {
|
|
|
|
Playground::setup("cd_test_4", |dirs, sandbox| {
|
2019-09-08 12:15:55 +02:00
|
|
|
sandbox.within("odin").mkdir("-");
|
2019-09-08 11:55:49 +02:00
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
cd odin/-
|
|
|
|
pwd | echo $it
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(
|
|
|
|
PathBuf::from(actual.out),
|
|
|
|
dirs.test().join("odin").join("-")
|
|
|
|
);
|
2019-09-08 11:55:49 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-08 10:09:05 +02:00
|
|
|
#[test]
|
|
|
|
fn filesystem_change_current_directory_to_parent_directory() {
|
2019-09-08 11:55:49 +02:00
|
|
|
Playground::setup("cd_test_5", |dirs, _| {
|
2019-09-08 10:09:05 +02:00
|
|
|
let actual = nu!(
|
2019-09-08 07:10:08 +02:00
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
2019-09-08 10:09:05 +02:00
|
|
|
cd ..
|
|
|
|
pwd | echo $it
|
2019-09-08 07:10:08 +02:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), *dirs.root());
|
2019-09-08 07:10:08 +02:00
|
|
|
})
|
|
|
|
}
|
2019-09-08 10:09:05 +02:00
|
|
|
|
2020-04-06 13:28:56 +02:00
|
|
|
#[test]
|
|
|
|
fn filesystem_change_current_directory_to_two_parents_up_using_multiple_dots() {
|
|
|
|
Playground::setup("cd_test_6", |dirs, sandbox| {
|
|
|
|
sandbox.within("foo").mkdir("bar");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test().join("foo/bar"),
|
|
|
|
r#"
|
|
|
|
cd ...
|
|
|
|
pwd | echo $it
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), *dirs.test());
|
2020-04-06 13:28:56 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-03-16 07:28:18 +01:00
|
|
|
#[test]
|
|
|
|
fn filesystem_change_current_directory_to_parent_directory_after_delete_cwd() {
|
2020-04-06 13:28:56 +02:00
|
|
|
Playground::setup("cd_test_7", |dirs, sandbox| {
|
2020-03-16 07:28:18 +01:00
|
|
|
sandbox.within("foo").mkdir("bar");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test().join("foo/bar"),
|
|
|
|
r#"
|
2020-06-07 05:50:52 +02:00
|
|
|
rm {}/foo/bar
|
2020-03-16 07:28:18 +01:00
|
|
|
echo ","
|
2020-06-07 05:50:52 +02:00
|
|
|
cd ..
|
2020-03-16 07:28:18 +01:00
|
|
|
pwd | echo $it
|
|
|
|
"#,
|
|
|
|
dirs.test()
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = actual.out.split(',').nth(1).unwrap();
|
2020-03-16 07:28:18 +01:00
|
|
|
|
|
|
|
assert_eq!(PathBuf::from(actual), *dirs.test().join("foo"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-18 03:59:23 +02:00
|
|
|
#[cfg(feature = "dirs")]
|
2019-09-08 10:09:05 +02:00
|
|
|
#[test]
|
2019-09-08 12:15:55 +02:00
|
|
|
fn filesystem_change_to_home_directory() {
|
2020-04-06 13:28:56 +02:00
|
|
|
Playground::setup("cd_test_8", |dirs, _| {
|
2019-09-08 10:09:05 +02:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
cd ~
|
|
|
|
pwd | echo $it
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(Some(PathBuf::from(actual.out)), dirs::home_dir());
|
2019-09-08 10:09:05 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filesystem_change_to_a_directory_containing_spaces() {
|
2020-04-06 13:28:56 +02:00
|
|
|
Playground::setup("cd_test_9", |dirs, sandbox| {
|
2019-09-08 10:09:05 +02:00
|
|
|
sandbox.mkdir("robalino turner katz");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
cd "robalino turner katz"
|
|
|
|
pwd | echo $it
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2019-09-11 16:36:50 +02:00
|
|
|
assert_eq!(
|
2020-05-07 13:03:43 +02:00
|
|
|
PathBuf::from(actual.out),
|
2019-09-11 16:36:50 +02:00
|
|
|
dirs.test().join("robalino turner katz")
|
|
|
|
);
|
2019-09-08 10:09:05 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-24 22:34:30 +02:00
|
|
|
#[test]
|
|
|
|
fn filesystem_not_a_directory() {
|
2020-04-06 13:28:56 +02:00
|
|
|
Playground::setup("cd_test_10", |dirs, sandbox| {
|
2019-09-24 22:34:30 +02:00
|
|
|
sandbox.with_files(vec![EmptyFile("ferris_did_it.txt")]);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2019-09-24 22:34:30 +02:00
|
|
|
cwd: dirs.test(),
|
|
|
|
"cd ferris_did_it.txt"
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert!(
|
|
|
|
actual.err.contains("ferris_did_it.txt"),
|
|
|
|
"actual={:?}",
|
|
|
|
actual.err
|
|
|
|
);
|
|
|
|
assert!(
|
|
|
|
actual.err.contains("is not a directory"),
|
|
|
|
"actual={:?}",
|
|
|
|
actual.err
|
|
|
|
);
|
2019-09-24 22:34:30 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-08 10:09:05 +02:00
|
|
|
#[test]
|
|
|
|
fn filesystem_directory_not_found() {
|
2020-04-25 08:09:00 +02:00
|
|
|
Playground::setup("cd_test_11", |dirs, _| {
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2020-04-25 08:09:00 +02:00
|
|
|
cwd: dirs.test(),
|
|
|
|
"cd dir_that_does_not_exist"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err.contains("dir_that_does_not_exist"),
|
2020-04-25 08:09:00 +02:00
|
|
|
"actual={:?}",
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err
|
2020-04-25 08:09:00 +02:00
|
|
|
);
|
|
|
|
assert!(
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err.contains("directory not found"),
|
2020-04-25 08:09:00 +02:00
|
|
|
"actual={:?}",
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err
|
2020-04-25 08:09:00 +02:00
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filesystem_change_directory_to_symlink_relative() {
|
|
|
|
Playground::setup("cd_test_12", |dirs, sandbox| {
|
|
|
|
sandbox.mkdir("foo");
|
|
|
|
sandbox.mkdir("boo");
|
|
|
|
sandbox.symlink("foo", "foo_link");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test().join("boo"),
|
|
|
|
r#"
|
|
|
|
cd ../foo_link
|
|
|
|
pwd | echo $it
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), dirs.test().join("foo"));
|
2020-04-25 08:09:00 +02:00
|
|
|
})
|
2019-09-08 12:15:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valuesystem_change_from_current_path_using_relative_path() {
|
2020-04-25 08:09:00 +02:00
|
|
|
Playground::setup("cd_test_13", |dirs, sandbox| {
|
2019-09-11 16:36:50 +02:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-09-08 12:15:55 +02:00
|
|
|
[[bin]]
|
|
|
|
path = "src/plugins/turner.rs"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
path = "src/plugins/robalino.rs"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
path = "src/plugins/katz.rs"
|
2019-09-11 16:36:50 +02:00
|
|
|
"#,
|
2019-09-08 12:15:55 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
enter sample.toml
|
|
|
|
cd bin
|
|
|
|
pwd | echo $it
|
|
|
|
exit
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/bin"));
|
2019-09-08 12:15:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valuesystem_change_from_current_path_using_absolute_path() {
|
2020-04-25 08:09:00 +02:00
|
|
|
Playground::setup("cd_test_14", |dirs, sandbox| {
|
2019-09-11 16:36:50 +02:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-09-08 12:15:55 +02:00
|
|
|
[dependencies]
|
|
|
|
turner-ts = "0.1.1"
|
|
|
|
robalino-tkd = "0.0.1"
|
|
|
|
katz-ember = "0.2.3"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
path = "src/plugins/arepa.rs"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
path = "src/plugins/bbq.rs"
|
2019-09-11 16:36:50 +02:00
|
|
|
"#,
|
2019-09-08 12:15:55 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
enter sample.toml
|
|
|
|
cd bin
|
|
|
|
cd /dependencies
|
|
|
|
pwd | echo $it
|
|
|
|
exit
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/dependencies"));
|
2019-09-11 16:36:50 +02:00
|
|
|
})
|
2019-09-08 12:15:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valuesystem_switch_back_to_previous_working_path() {
|
2020-04-25 08:09:00 +02:00
|
|
|
Playground::setup("cd_test_15", |dirs, sandbox| {
|
2019-09-11 16:36:50 +02:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-09-08 12:15:55 +02:00
|
|
|
[dependencies]
|
|
|
|
turner-ts = "0.1.1"
|
|
|
|
robalino-tkd = "0.0.1"
|
|
|
|
katz-ember = "0.2.3"
|
|
|
|
odin-gf = "0.2.1"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
path = "src/plugins/arepa.rs"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
path = "src/plugins/bbq.rs"
|
2019-09-11 16:36:50 +02:00
|
|
|
"#,
|
2019-09-08 12:15:55 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
enter sample.toml
|
|
|
|
cd dependencies
|
|
|
|
cd /bin
|
|
|
|
cd -
|
|
|
|
pwd | echo $it
|
|
|
|
exit
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/dependencies"));
|
2019-09-08 12:15:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valuesystem_change_from_current_path_using_relative_path_and_dash() {
|
2020-04-25 08:09:00 +02:00
|
|
|
Playground::setup("cd_test_16", |dirs, sandbox| {
|
2019-09-08 12:15:55 +02:00
|
|
|
sandbox
|
|
|
|
.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
- = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
path = "src/plugins/arepa.rs"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
path = "src/plugins/bbq.rs"
|
|
|
|
"#
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
enter sample.toml
|
|
|
|
cd package/-
|
|
|
|
cd /bin
|
|
|
|
cd -
|
|
|
|
pwd | echo $it
|
|
|
|
exit
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/package/-"));
|
2019-09-08 12:15:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valuesystem_change_current_path_to_parent_path() {
|
2020-04-25 08:09:00 +02:00
|
|
|
Playground::setup("cd_test_17", |dirs, sandbox| {
|
2019-09-08 12:15:55 +02:00
|
|
|
sandbox
|
|
|
|
.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
emberenios = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
|
|
|
"#
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
enter sample.toml
|
|
|
|
cd package/emberenios
|
|
|
|
cd ..
|
|
|
|
pwd | echo $it
|
|
|
|
exit
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(PathBuf::from(actual.out), PathBuf::from("/package"));
|
2019-09-08 12:15:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valuesystem_change_to_a_path_containing_spaces() {
|
2020-04-25 08:09:00 +02:00
|
|
|
Playground::setup("cd_test_18", |dirs, sandbox| {
|
2019-09-11 16:36:50 +02:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
2019-09-08 12:15:55 +02:00
|
|
|
["pa que te"]
|
|
|
|
el = "pollo loco"
|
2019-09-11 16:36:50 +02:00
|
|
|
"#,
|
2019-09-08 12:15:55 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
enter sample.toml
|
|
|
|
cd "pa que te"
|
|
|
|
pwd | echo $it
|
|
|
|
exit
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(
|
|
|
|
PathBuf::from(actual.out),
|
|
|
|
PathBuf::from("/").join("pa que te")
|
|
|
|
);
|
2019-09-08 12:15:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valuesystem_path_not_found() {
|
2020-04-25 08:09:00 +02:00
|
|
|
Playground::setup("cd_test_19", |dirs, _| {
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2020-04-25 08:09:00 +02:00
|
|
|
cwd: dirs.formats(),
|
|
|
|
r#"
|
2019-09-08 12:15:55 +02:00
|
|
|
enter cargo_sample.toml
|
|
|
|
cd im_a_path_that_does_not_exist
|
|
|
|
exit
|
|
|
|
"#
|
2020-04-25 08:09:00 +02:00
|
|
|
);
|
2019-09-08 12:15:55 +02:00
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert!(actual.err.contains("Can not change to path inside"));
|
|
|
|
assert!(actual.err.contains("No such path exists"));
|
2020-04-25 08:09:00 +02:00
|
|
|
})
|
2019-09-08 12:15:55 +02:00
|
|
|
}
|
2020-06-21 21:02:58 +02:00
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
#[test]
|
|
|
|
fn test_change_windows_drive() {
|
|
|
|
Playground::setup("cd_test_20", |dirs, sandbox| {
|
|
|
|
sandbox.mkdir("test_folder");
|
|
|
|
|
|
|
|
let _actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
subst Z: test_folder
|
|
|
|
Z:
|
|
|
|
echo "some text" | save test_file.txt
|
|
|
|
cd ~
|
|
|
|
subst Z: /d
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
assert!(dirs
|
|
|
|
.test()
|
|
|
|
.join("test_folder")
|
|
|
|
.join("test_file.txt")
|
|
|
|
.exists());
|
|
|
|
})
|
|
|
|
}
|