Merge pull request #618 from androbtech/cd-coverage

Filesystem change directory coverage.
This commit is contained in:
Andrés N. Robalino 2019-09-08 03:32:00 -05:00 committed by GitHub
commit 207f9ece5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 34 deletions

View file

@ -1,9 +1,107 @@
mod helpers; mod helpers;
use helpers::Playground; use helpers::Playground;
use std::path::PathBuf;
#[test] #[test]
fn cd_directory_not_found() { fn filesytem_change_from_current_directory_using_relative_path() {
Playground::setup("cd_test_1", |dirs, _| {
let actual = nu!(
cwd: dirs.root(),
r#"
cd cd_test_1
pwd | echo $it
"#
);
assert_eq!(PathBuf::from(actual), *dirs.test());
})
}
#[test]
fn filesystem_change_from_current_directory_using_absolute_path() {
Playground::setup("cd_test_2", |dirs, _| {
let actual = nu!(
cwd: dirs.test(),
r#"
cd {}
pwd | echo $it
"#,
dirs.formats()
);
assert_eq!(PathBuf::from(actual), dirs.formats());
})
}
#[test]
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()
);
assert_eq!(PathBuf::from(actual), dirs.test().join("odin"));
})
}
#[test]
fn filesystem_change_current_directory_to_parent_directory() {
Playground::setup("cd_test_4", |dirs, _| {
let actual = nu!(
cwd: dirs.test(),
r#"
cd ..
pwd | echo $it
"#
);
assert_eq!(PathBuf::from(actual), *dirs.root());
})
}
#[test]
fn file_system_change_to_home_directory() {
Playground::setup("cd_test_5", |dirs, _| {
let actual = nu!(
cwd: dirs.test(),
r#"
cd ~
pwd | echo $it
"#
);
assert_eq!(PathBuf::from(actual), dirs::home_dir().unwrap());
})
}
#[test]
fn filesystem_change_to_a_directory_containing_spaces() {
Playground::setup("cd_test_6", |dirs, sandbox| {
sandbox.mkdir("robalino turner katz");
let actual = nu!(
cwd: dirs.test(),
r#"
cd "robalino turner katz"
pwd | echo $it
"#
);
assert_eq!(PathBuf::from(actual), dirs.test().join("robalino turner katz"));
})
}
#[test]
fn filesystem_directory_not_found() {
let actual = nu_error!( let actual = nu_error!(
cwd: "tests/fixtures", cwd: "tests/fixtures",
"cd dir_that_does_not_exist" "cd dir_that_does_not_exist"
@ -12,35 +110,3 @@ fn cd_directory_not_found() {
assert!(actual.contains("dir_that_does_not_exist")); assert!(actual.contains("dir_that_does_not_exist"));
assert!(actual.contains("directory not found")); assert!(actual.contains("directory not found"));
} }
#[test]
fn cd_back() {
Playground::setup("cd_test_back", |dirs, sandbox| {
sandbox
.mkdir("andres")
.mkdir("odin");
let odin = dirs.test().join("odin");
let andres = dirs.test().join("andres");
nu!(
cwd: dirs.test(),
r#"
cd odin
mkdir a
cd ../andres
mkdir b
cd -
mkdir c
mkdir -
cd -
mkdir d
"#
);
assert!(odin.join("a").exists());
assert!(andres.join("b").exists());
assert!(odin.join("c").exists());
assert!(odin.join("-").join("d").exists());
})
}

View file

@ -227,8 +227,14 @@ impl Playground {
playground_root.join(topic).display() playground_root.join(topic).display()
)); ));
let root =
dunce::canonicalize(playground_root).expect(&format!(
"Couldn't canonicalize tests root path {}",
playground_root.display()
));
let dirs = Dirs { let dirs = Dirs {
root: PathBuf::from(playground_root), root,
test, test,
fixtures, fixtures,
}; };