Files

97 lines
2.2 KiB
Rust
Raw Permalink Normal View History

2023-08-21 10:49:27 +02:00
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
2025-08-08 15:10:35 +02:00
#[cfg(target_os = "linux")]
use std::os::unix::ffi::OsStringExt;
2025-03-28 09:51:51 +01:00
use uutests::at_and_ucmd;
use uutests::new_ucmd;
2022-09-10 18:38:14 +02:00
#[test]
fn test_invalid_arg() {
2025-03-01 15:29:11 +01:00
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
2022-09-10 18:38:14 +02:00
}
#[test]
fn test_bsd_single_file() {
new_ucmd!()
.arg("lorem_ipsum.txt")
2020-04-13 20:36:03 +02:00
.succeeds()
.stdout_only_fixture("bsd_single_file.expected");
}
#[test]
fn test_bsd_multiple_files() {
new_ucmd!()
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
2020-04-13 20:36:03 +02:00
.succeeds()
.stdout_only_fixture("bsd_multiple_files.expected");
}
#[test]
fn test_bsd_stdin() {
new_ucmd!()
.pipe_in_fixture("lorem_ipsum.txt")
2020-04-13 20:36:03 +02:00
.succeeds()
.stdout_only_fixture("bsd_stdin.expected");
}
#[test]
fn test_sysv_single_file() {
new_ucmd!()
2020-04-13 20:36:03 +02:00
.arg("-s")
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_only_fixture("sysv_single_file.expected");
}
#[test]
fn test_sysv_multiple_files() {
new_ucmd!()
.arg("-s")
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
2020-04-13 20:36:03 +02:00
.succeeds()
.stdout_only_fixture("sysv_multiple_files.expected");
}
#[test]
fn test_sysv_stdin() {
new_ucmd!()
.arg("-s")
.pipe_in_fixture("lorem_ipsum.txt")
2020-04-13 20:36:03 +02:00
.succeeds()
.stdout_only_fixture("sysv_stdin.expected");
}
#[test]
fn test_invalid_file() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("a");
ucmd.arg("a").fails().stderr_is("sum: a: Is a directory\n");
}
#[test]
fn test_invalid_metadata() {
let (_, mut ucmd) = at_and_ucmd!();
ucmd.arg("b")
.fails()
.stderr_is("sum: b: No such file or directory\n");
}
2025-08-08 15:10:35 +02:00
#[test]
#[cfg(target_os = "linux")]
#[cfg_attr(wasi_runner, ignore = "WASI: argv/filenames must be valid UTF-8")]
2025-08-08 15:10:35 +02:00
fn test_sum_non_utf8_paths() {
let (at, mut ucmd) = at_and_ucmd!();
let filename = std::ffi::OsString::from_vec(vec![0xFF, 0xFE]);
std::fs::write(at.plus(&filename), b"test content").unwrap();
ucmd.arg(&filename).succeeds();
}