mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 07:02:19 +01:00
Test coverage for pull #235
This commit is contained in:
parent
ecccbca076
commit
610a91a658
@ -81,12 +81,31 @@ fn open_error_if_file_not_found() {
|
||||
assert!(output.contains("File could not be opened"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_figures_out_intelligently_where_to_write_out_with_metadata() {
|
||||
let (playground_path, tests_dir) = h::setup_playground_for("save_smart_test");
|
||||
|
||||
let full_path = format!("{}/{}", playground_path, tests_dir);
|
||||
let subject_file = format!("{}/{}", full_path, "cargo_sample.toml");
|
||||
|
||||
h::copy_file_to("tests/fixtures/formats/cargo_sample.toml", &subject_file);
|
||||
|
||||
nu!(
|
||||
_output,
|
||||
cwd("tests/fixtures"),
|
||||
"open nuplayground/save_smart_test/cargo_sample.toml | inc package.version --minor | save"
|
||||
);
|
||||
|
||||
let actual = h::file_contents(&subject_file);
|
||||
assert!(actual.contains("0.2.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_can_write_out_csv() {
|
||||
let (playground_path, tests_dir) = h::setup_playground_for("save_test");
|
||||
|
||||
let full_path = format!("{}/{}", playground_path, tests_dir );
|
||||
let expected_file = format!("{}/{}", full_path , "cargo_sample.csv");
|
||||
let full_path = format!("{}/{}", playground_path, tests_dir);
|
||||
let expected_file = format!("{}/{}", full_path, "cargo_sample.csv");
|
||||
|
||||
nu!(
|
||||
_output,
|
||||
@ -100,10 +119,10 @@ fn save_can_write_out_csv() {
|
||||
|
||||
#[test]
|
||||
fn cp_can_copy_a_file() {
|
||||
let (playground_path, tests_dir) = h::setup_playground_for("cp_test");
|
||||
let (playground_path, tests_dir) = h::setup_playground_for("cp_test");
|
||||
|
||||
let full_path = format!("{}/{}", playground_path, tests_dir );
|
||||
let expected_file = format!("{}/{}", full_path , "sample.ini" );
|
||||
let full_path = format!("{}/{}", playground_path, tests_dir);
|
||||
let expected_file = format!("{}/{}", full_path, "sample.ini");
|
||||
|
||||
nu!(
|
||||
_output,
|
||||
@ -116,10 +135,10 @@ fn cp_can_copy_a_file() {
|
||||
|
||||
#[test]
|
||||
fn cp_copies_the_file_inside_directory_if_path_to_copy_is_directory() {
|
||||
let (playground_path, tests_dir) = h::setup_playground_for("cp_test_2");
|
||||
let (playground_path, tests_dir) = h::setup_playground_for("cp_test_2");
|
||||
|
||||
let full_path = format!("{}/{}", playground_path, tests_dir );
|
||||
let expected_file = format!("{}/{}", full_path , "sample.ini" );
|
||||
let full_path = format!("{}/{}", playground_path, tests_dir);
|
||||
let expected_file = format!("{}/{}", full_path, "sample.ini");
|
||||
|
||||
nu!(
|
||||
_output,
|
||||
@ -134,11 +153,7 @@ fn cp_copies_the_file_inside_directory_if_path_to_copy_is_directory() {
|
||||
fn cp_error_if_attempting_to_copy_a_directory_to_another_directory() {
|
||||
let (playground_path, _) = h::setup_playground_for("cp_test_3");
|
||||
|
||||
nu_error!(
|
||||
output,
|
||||
cwd(&playground_path),
|
||||
"cp ../formats cp_test_3"
|
||||
);
|
||||
nu_error!(output, cwd(&playground_path), "cp ../formats cp_test_3");
|
||||
|
||||
assert!(output.contains("../formats"));
|
||||
assert!(output.contains("is a directory (not copied)"));
|
||||
@ -170,7 +185,10 @@ fn rm_can_remove_directory_contents_with_recursive_flag() {
|
||||
"rm rm_test --recursive"
|
||||
);
|
||||
|
||||
assert!(!h::file_exists_at(&format!("{}/{}", playground_path, tests_dir)));
|
||||
assert!(!h::file_exists_at(&format!(
|
||||
"{}/{}",
|
||||
playground_path, tests_dir
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -197,4 +215,4 @@ fn rm_error_if_attempting_to_delete_two_dot_as_argument() {
|
||||
nu_error!(output, cwd("tests/fixtures/nuplayground"), "rm ..");
|
||||
|
||||
assert!(output.contains("may not be removed"));
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ use std::io::Read;
|
||||
#[macro_export]
|
||||
macro_rules! nu {
|
||||
($out:ident, $cwd:expr, $commands:expr) => {
|
||||
pub use std::error::Error;
|
||||
pub use std::io::prelude::*;
|
||||
pub use std::process::{Command, Stdio};
|
||||
pub use std::error::Error;
|
||||
|
||||
let commands = &*format!(
|
||||
"
|
||||
@ -93,16 +93,21 @@ pub fn setup_playground_for(topic: &str) -> (String, String) {
|
||||
}
|
||||
|
||||
pub fn file_contents(full_path: &str) -> String {
|
||||
let mut file = std::fs::File::open(full_path).expect("can not open file");
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents).expect("can not read file");
|
||||
contents
|
||||
let mut file = std::fs::File::open(full_path).expect("can not open file");
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)
|
||||
.expect("can not read file");
|
||||
contents
|
||||
}
|
||||
|
||||
pub fn create_file_at(full_path: &str) {
|
||||
std::fs::write(PathBuf::from(full_path), "fake data".as_bytes()).expect("can not create file");
|
||||
}
|
||||
|
||||
pub fn copy_file_to(source: &str, destination: &str) {
|
||||
std::fs::copy(source, destination).expect("can not copy file");
|
||||
}
|
||||
|
||||
pub fn file_exists_at(full_path: &str) -> bool {
|
||||
PathBuf::from(full_path).exists()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user