Add back --append flag to save command (#4744)

This commit is contained in:
Genna Wingert
2022-03-05 20:36:58 +01:00
committed by GitHub
parent a4a8f5df54
commit 1527b34d9c
2 changed files with 38 additions and 4 deletions

View File

@ -1,6 +1,7 @@
use nu_test_support::fs::{file_contents, Stub::FileWithContent};
use nu_test_support::nu;
use nu_test_support::playground::Playground;
use std::io::Write;
#[test]
fn figures_out_intelligently_where_to_write_out_with_metadata() {
@ -48,8 +49,6 @@ fn writes_out_csv() {
})
}
// FIXME: jt: needs more work
#[ignore]
#[test]
fn save_append_will_create_file_if_not_exists() {
Playground::setup("save_test_3", |dirs, sandbox| {
@ -64,6 +63,31 @@ fn save_append_will_create_file_if_not_exists() {
let actual = file_contents(expected_file);
println!("{}", actual);
assert!(actual == "hello");
assert_eq!(actual, "hello");
})
}
#[test]
fn save_append_will_not_overwrite_content() {
Playground::setup("save_test_4", |dirs, sandbox| {
sandbox.with_files(vec![]);
let expected_file = dirs.test().join("new-file.txt");
{
let mut file =
std::fs::File::create(&expected_file).expect("Failed to create test file");
file.write_all("hello ".as_bytes())
.expect("Failed to write to test file")
}
nu!(
cwd: dirs.root(),
r#"echo world | save --append save_test_4/new-file.txt"#,
);
let actual = file_contents(expected_file);
println!("{}", actual);
assert_eq!(actual, "hello world");
})
}