mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
split: Don't overwrite files
Check that a file exists by calling create_new and changing the interface of instantiate_current_writer to return a Result rather than calling unwrap.
This commit is contained in:
parent
735db78b3d
commit
f2cfc15a70
6 changed files with 136 additions and 47 deletions
|
@ -655,3 +655,31 @@ fn test_line_bytes_no_empty_file() {
|
|||
assert_eq!(at.read("xaj"), "4");
|
||||
assert!(!at.plus("xak").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_guard_input() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["-C", "6"])
|
||||
.pipe_in("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
assert_eq!(at.read("xaa"), "1\n2\n3\n");
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["-C", "6"])
|
||||
.pipe_in("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
assert_eq!(at.read("xaa"), "1\n2\n3\n");
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["-C", "6", "xaa"])
|
||||
.fails()
|
||||
.stderr_only("split: 'xaa' would overwrite input; aborting");
|
||||
assert_eq!(at.read("xaa"), "1\n2\n3\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue