1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 19:36:16 +00:00

Merge branch 'main' into rm-correct-prompts

This commit is contained in:
Pat Laster 2022-10-22 14:12:55 -05:00 committed by GitHub
commit 99942b4234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 12 deletions

View file

@ -34,7 +34,7 @@ macro_rules! test_digest {
fn test_nonames() {
let ts = TestScenario::new("hashsum");
// EXPECTED_FILE has no newline character at the end
if DIGEST_ARG == "b3sum" {
if DIGEST_ARG == "--b3sum" {
// Option only available on b3sum
assert_eq!(format!("{0}\n{0}\n", ts.fixtures.read(EXPECTED_FILE)),
ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--no-names").arg("input.txt").arg("-").pipe_in_fixture("input.txt")

View file

@ -1117,14 +1117,36 @@ fn test_tmp_files_deleted_on_sigint() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("tmp_dir");
let file_name = "big_file_to_sort.txt";
{
use rand::{Rng, SeedableRng};
use std::io::Write;
let mut file = at.make_file(file_name);
// approximately 20 MB
for _ in 0..40 {
let lines = rand_pcg::Pcg32::seed_from_u64(123)
.sample_iter(rand::distributions::uniform::Uniform::new(0, 10000))
.take(100000)
.map(|x| x.to_string() + "\n")
.collect::<String>();
file.write_all(lines.as_bytes()).unwrap();
}
}
ucmd.args(&[
"ext_sort.txt",
file_name,
"--buffer-size=1", // with a small buffer size `sort` will be forced to create a temporary directory very soon.
"--temporary-directory=tmp_dir",
]);
let mut child = ucmd.run_no_wait();
// wait a short amount of time so that `sort` can create a temporary directory.
std::thread::sleep(Duration::from_millis(100));
let mut timeout = Duration::from_millis(100);
for _ in 0..5 {
std::thread::sleep(timeout);
if read_dir(at.plus("tmp_dir")).unwrap().next().is_some() {
break;
}
timeout *= 2;
}
// `sort` should have created a temporary directory.
assert!(read_dir(at.plus("tmp_dir")).unwrap().next().is_some());
// kill sort with SIGINT