mirror of
https://github.com/nushell/nushell
synced 2024-12-26 04:53:09 +00:00
Filesystem shell can't cd into files. Ever.
This commit is contained in:
parent
ffa536bea3
commit
837d12decd
2 changed files with 30 additions and 7 deletions
|
@ -187,6 +187,14 @@ impl Shell for FilesystemShell {
|
||||||
} else {
|
} else {
|
||||||
let path = PathBuf::from(self.path());
|
let path = PathBuf::from(self.path());
|
||||||
|
|
||||||
|
if target.exists() && !target.is_dir() {
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
"Can not change to directory",
|
||||||
|
"is not a directory",
|
||||||
|
v.tag().clone(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
match dunce::canonicalize(path.join(&target)) {
|
match dunce::canonicalize(path.join(&target)) {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
|
@ -120,6 +120,21 @@ fn filesystem_change_to_a_directory_containing_spaces() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn filesystem_not_a_directory() {
|
||||||
|
Playground::setup("cd_test_8", |dirs, sandbox| {
|
||||||
|
sandbox.with_files(vec![EmptyFile("ferris_did_it.txt")]);
|
||||||
|
|
||||||
|
let actual = nu_error!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"cd ferris_did_it.txt"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(actual.contains("ferris_did_it.txt"));
|
||||||
|
assert!(actual.contains("is not a directory"));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn filesystem_directory_not_found() {
|
fn filesystem_directory_not_found() {
|
||||||
let actual = nu_error!(
|
let actual = nu_error!(
|
||||||
|
@ -133,7 +148,7 @@ fn filesystem_directory_not_found() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_from_current_path_using_relative_path() {
|
fn valuesystem_change_from_current_path_using_relative_path() {
|
||||||
Playground::setup("cd_test_8", |dirs, sandbox| {
|
Playground::setup("cd_test_9", |dirs, sandbox| {
|
||||||
sandbox.with_files(vec![FileWithContent(
|
sandbox.with_files(vec![FileWithContent(
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
|
@ -164,7 +179,7 @@ fn valuesystem_change_from_current_path_using_relative_path() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_from_current_path_using_absolute_path() {
|
fn valuesystem_change_from_current_path_using_absolute_path() {
|
||||||
Playground::setup("cd_test_9", |dirs, sandbox| {
|
Playground::setup("cd_test_10", |dirs, sandbox| {
|
||||||
sandbox.with_files(vec![FileWithContent(
|
sandbox.with_files(vec![FileWithContent(
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
|
@ -198,7 +213,7 @@ fn valuesystem_change_from_current_path_using_absolute_path() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_switch_back_to_previous_working_path() {
|
fn valuesystem_switch_back_to_previous_working_path() {
|
||||||
Playground::setup("cd_test_10", |dirs, sandbox| {
|
Playground::setup("cd_test_11", |dirs, sandbox| {
|
||||||
sandbox.with_files(vec![FileWithContent(
|
sandbox.with_files(vec![FileWithContent(
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
|
@ -234,7 +249,7 @@ fn valuesystem_switch_back_to_previous_working_path() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_from_current_path_using_relative_path_and_dash() {
|
fn valuesystem_change_from_current_path_using_relative_path_and_dash() {
|
||||||
Playground::setup("cd_test_11", |dirs, sandbox| {
|
Playground::setup("cd_test_12", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox
|
||||||
.with_files(vec![FileWithContent(
|
.with_files(vec![FileWithContent(
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
|
@ -268,7 +283,7 @@ fn valuesystem_change_from_current_path_using_relative_path_and_dash() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_current_path_to_parent_path() {
|
fn valuesystem_change_current_path_to_parent_path() {
|
||||||
Playground::setup("cd_test_12", |dirs, sandbox| {
|
Playground::setup("cd_test_13", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox
|
||||||
.with_files(vec![FileWithContent(
|
.with_files(vec![FileWithContent(
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
|
@ -295,7 +310,7 @@ fn valuesystem_change_current_path_to_parent_path() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_to_home_directory() {
|
fn valuesystem_change_to_home_directory() {
|
||||||
Playground::setup("cd_test_13", |dirs, sandbox| {
|
Playground::setup("cd_test_14", |dirs, sandbox| {
|
||||||
sandbox.with_files(vec![FileWithContent(
|
sandbox.with_files(vec![FileWithContent(
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
|
@ -321,7 +336,7 @@ fn valuesystem_change_to_home_directory() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_to_a_path_containing_spaces() {
|
fn valuesystem_change_to_a_path_containing_spaces() {
|
||||||
Playground::setup("cd_test_14", |dirs, sandbox| {
|
Playground::setup("cd_test_15", |dirs, sandbox| {
|
||||||
sandbox.with_files(vec![FileWithContent(
|
sandbox.with_files(vec![FileWithContent(
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
|
|
Loading…
Reference in a new issue