this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 95 lines 3.4 kB view raw
1use assert_cmd::prelude::*; 2use assert_fs::prelude::*; 3use predicates::prelude::*; 4use std::process::Command; 5 6mod common; 7use common::*; 8 9mod force { 10 use super::*; 11 12 /// Without --force, cmprss must refuse to overwrite an existing -o target. 13 /// 14 /// ``` bash 15 /// echo 'sentinel' > output.gz 16 /// cmprss gzip -o output.gz input.txt # fails, output.gz untouched 17 /// ``` 18 #[test] 19 fn refuses_overwrite_without_force() -> Result<(), Box<dyn std::error::Error>> { 20 let working_dir = create_working_dir()?; 21 let input = working_dir.child("input.txt"); 22 input.write_str("the real payload")?; 23 24 let output = working_dir.child("output.gz"); 25 output.write_str("sentinel — must not be clobbered")?; 26 27 let mut cmd = Command::cargo_bin("cmprss")?; 28 cmd.current_dir(&working_dir) 29 .args(["gzip", "-o", "output.gz", "input.txt"]); 30 cmd.assert() 31 .failure() 32 .stderr(predicate::str::contains("already exists")); 33 34 // The existing file must be byte-for-byte unchanged. 35 output.assert("sentinel — must not be clobbered"); 36 Ok(()) 37 } 38 39 /// With --force, cmprss overwrites an existing -o target. 40 #[test] 41 fn overwrites_with_force_explicit_output() -> Result<(), Box<dyn std::error::Error>> { 42 let working_dir = create_working_dir()?; 43 let input = working_dir.child("input.txt"); 44 input.write_str("the real payload")?; 45 46 let output = working_dir.child("output.gz"); 47 output.write_str("sentinel — should be clobbered")?; 48 49 let mut cmd = Command::cargo_bin("cmprss")?; 50 cmd.current_dir(&working_dir) 51 .args(["gzip", "--force", "-o", "output.gz", "input.txt"]); 52 cmd.assert().success(); 53 54 // The file now contains real gzip output — confirm by round-tripping. 55 let mut extract = Command::cargo_bin("cmprss")?; 56 extract 57 .current_dir(&working_dir) 58 .args(["gzip", "--extract", "output.gz", "output.txt"]); 59 extract.assert().success(); 60 working_dir.child("output.txt").assert("the real payload"); 61 Ok(()) 62 } 63 64 /// With --force, a trailing existing file in the positional io_list is 65 /// taken as the output and overwritten. Without --force, that trailing 66 /// file gets mistakenly pulled into the input list. 67 #[test] 68 fn overwrites_with_force_positional_output() -> Result<(), Box<dyn std::error::Error>> { 69 let working_dir = create_working_dir()?; 70 let input = working_dir.child("input.txt"); 71 input.write_str("the real payload")?; 72 73 let output = working_dir.child("input.txt.gz"); 74 output.write_str("stale archive")?; 75 76 let mut cmd = Command::cargo_bin("cmprss")?; 77 cmd.current_dir(&working_dir) 78 .args(["gzip", "--force", "input.txt", "input.txt.gz"]); 79 cmd.assert().success(); 80 81 // Round-trip the new archive to confirm it contains the fresh payload. 82 let mut extract = Command::cargo_bin("cmprss")?; 83 extract.current_dir(&working_dir).args([ 84 "gzip", 85 "--extract", 86 "input.txt.gz", 87 "roundtrip.txt", 88 ]); 89 extract.assert().success(); 90 working_dir 91 .child("roundtrip.txt") 92 .assert("the real payload"); 93 Ok(()) 94 } 95}