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:29:32 +02:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
use std::os::unix::ffi::OsStringExt;
|
2026-03-26 05:40:30 +09:00
|
|
|
#[cfg(unix)]
|
2025-03-28 09:51:51 +01:00
|
|
|
use uutests::new_ucmd;
|
2016-05-22 13:59:57 +02:00
|
|
|
|
2024-01-09 15:17:15 +01:00
|
|
|
#[test]
|
2026-03-26 05:40:30 +09:00
|
|
|
#[cfg(unix)]
|
2024-01-09 15:17:15 +01:00
|
|
|
fn test_no_args() {
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.fails()
|
|
|
|
|
.no_stdout()
|
|
|
|
|
.stderr_contains("pathchk: missing operand");
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-10 18:38:14 +02:00
|
|
|
#[test]
|
2026-03-26 05:40:30 +09:00
|
|
|
#[cfg(unix)]
|
2022-09-10 18:38:14 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-05-22 13:59:57 +02:00
|
|
|
#[test]
|
2026-03-26 05:40:30 +09:00
|
|
|
#[cfg(unix)]
|
2016-05-22 13:59:57 +02:00
|
|
|
fn test_default_mode() {
|
2016-08-13 17:59:21 -04:00
|
|
|
// accept some reasonable default
|
2021-03-28 16:30:49 +05:30
|
|
|
new_ucmd!().args(&["dir/file"]).succeeds().no_stdout();
|
2016-08-13 17:59:21 -04:00
|
|
|
|
2021-03-28 16:30:49 +05:30
|
|
|
// accept non-portable chars
|
|
|
|
|
new_ucmd!().args(&["dir#/$file"]).succeeds().no_stdout();
|
|
|
|
|
|
2023-10-18 22:50:54 +08:00
|
|
|
// fail on empty path
|
2023-10-19 01:29:53 +08:00
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&[""])
|
|
|
|
|
.fails()
|
|
|
|
|
.stderr_only("pathchk: '': No such file or directory\n");
|
2023-10-18 22:50:54 +08:00
|
|
|
|
2023-10-19 01:29:53 +08:00
|
|
|
new_ucmd!().args(&["", ""]).fails().stderr_only(
|
|
|
|
|
"pathchk: '': No such file or directory\n\
|
|
|
|
|
pathchk: '': No such file or directory\n",
|
|
|
|
|
);
|
2021-03-28 16:30:49 +05:30
|
|
|
|
|
|
|
|
// fail on long path
|
2020-04-13 20:36:03 +02:00
|
|
|
new_ucmd!()
|
2021-03-28 16:30:49 +05:30
|
|
|
.args(&["dir".repeat(libc::PATH_MAX as usize + 1)])
|
|
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on long filename
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&[format!(
|
|
|
|
|
"dir/{}",
|
|
|
|
|
"file".repeat(libc::FILENAME_MAX as usize + 1)
|
|
|
|
|
)])
|
2020-04-13 20:36:03 +02:00
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
2016-05-22 13:59:57 +02:00
|
|
|
}
|
2021-03-28 16:30:49 +05:30
|
|
|
|
|
|
|
|
#[test]
|
2026-03-26 05:40:30 +09:00
|
|
|
#[cfg(unix)]
|
2021-03-28 16:30:49 +05:30
|
|
|
fn test_posix_mode() {
|
|
|
|
|
// accept some reasonable default
|
|
|
|
|
new_ucmd!().args(&["-p", "dir/file"]).succeeds().no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on long path
|
|
|
|
|
new_ucmd!()
|
2021-06-06 14:13:54 -05:00
|
|
|
.args(&["-p", "dir".repeat(libc::PATH_MAX as usize + 1).as_str()])
|
2021-03-28 16:30:49 +05:30
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on long filename
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&[
|
|
|
|
|
"-p",
|
2021-06-06 14:13:54 -05:00
|
|
|
format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
|
2021-03-28 16:30:49 +05:30
|
|
|
])
|
|
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on non-portable chars
|
|
|
|
|
new_ucmd!().args(&["-p", "dir#/$file"]).fails().no_stdout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-03-26 05:40:30 +09:00
|
|
|
#[cfg(unix)]
|
2021-03-28 16:30:49 +05:30
|
|
|
fn test_posix_special() {
|
|
|
|
|
// accept some reasonable default
|
|
|
|
|
new_ucmd!().args(&["-P", "dir/file"]).succeeds().no_stdout();
|
|
|
|
|
|
|
|
|
|
// accept non-portable chars
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["-P", "dir#/$file"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// accept non-leading hyphen
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["-P", "dir/file-name"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on long path
|
|
|
|
|
new_ucmd!()
|
2021-06-06 14:13:54 -05:00
|
|
|
.args(&["-P", "dir".repeat(libc::PATH_MAX as usize + 1).as_str()])
|
2021-03-28 16:30:49 +05:30
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on long filename
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&[
|
|
|
|
|
"-P",
|
2021-06-06 14:13:54 -05:00
|
|
|
format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
|
2021-03-28 16:30:49 +05:30
|
|
|
])
|
|
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on leading hyphen char
|
|
|
|
|
new_ucmd!().args(&["-P", "dir/-file"]).fails().no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on empty path
|
|
|
|
|
new_ucmd!().args(&["-P", ""]).fails().no_stdout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-03-26 05:40:30 +09:00
|
|
|
#[cfg(unix)]
|
2021-03-28 16:30:49 +05:30
|
|
|
fn test_posix_all() {
|
|
|
|
|
// accept some reasonable default
|
2021-03-30 21:24:01 +02:00
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["-p", "-P", "dir/file"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.no_stdout();
|
2021-03-28 16:30:49 +05:30
|
|
|
|
|
|
|
|
// accept non-leading hyphen
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["-p", "-P", "dir/file-name"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on long path
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&[
|
|
|
|
|
"-p",
|
|
|
|
|
"-P",
|
2021-06-06 14:13:54 -05:00
|
|
|
"dir".repeat(libc::PATH_MAX as usize + 1).as_str(),
|
2021-03-28 16:30:49 +05:30
|
|
|
])
|
|
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on long filename
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&[
|
|
|
|
|
"-p",
|
|
|
|
|
"-P",
|
2021-06-06 14:13:54 -05:00
|
|
|
format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
|
2021-03-28 16:30:49 +05:30
|
|
|
])
|
|
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
|
|
// fail on non-portable chars
|
2021-03-30 21:24:01 +02:00
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["-p", "-P", "dir#/$file"])
|
|
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
2021-03-28 16:30:49 +05:30
|
|
|
|
|
|
|
|
// fail on leading hyphen char
|
2021-03-30 21:24:01 +02:00
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["-p", "-P", "dir/-file"])
|
|
|
|
|
.fails()
|
|
|
|
|
.no_stdout();
|
2021-03-28 16:30:49 +05:30
|
|
|
|
|
|
|
|
// fail on empty path
|
|
|
|
|
new_ucmd!().args(&["-p", "-P", ""]).fails().no_stdout();
|
|
|
|
|
}
|
2025-08-08 15:29:32 +02:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
fn test_pathchk_non_utf8_paths() {
|
|
|
|
|
let filename = std::ffi::OsString::from_vec(vec![0xFF, 0xFE]);
|
2025-08-11 22:26:10 +02:00
|
|
|
new_ucmd!().arg(&filename).succeeds();
|
2025-08-08 15:29:32 +02:00
|
|
|
}
|