2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2016-05-22 11:59:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_default_mode() {
|
|
|
|
// test the default mode
|
2016-08-13 21:59:21 +00:00
|
|
|
|
|
|
|
// accept some reasonable default
|
2021-03-28 11:00:49 +00:00
|
|
|
new_ucmd!().args(&["dir/file"]).succeeds().no_stdout();
|
2016-08-13 21:59:21 +00:00
|
|
|
|
2021-03-28 11:00:49 +00:00
|
|
|
// accept non-portable chars
|
|
|
|
new_ucmd!().args(&["dir#/$file"]).succeeds().no_stdout();
|
|
|
|
|
|
|
|
// accept empty path
|
|
|
|
new_ucmd!().args(&[""]).succeeds().no_stdout();
|
|
|
|
|
|
|
|
// fail on long path
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
2021-03-28 11:00:49 +00:00
|
|
|
.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 18:36:03 +00:00
|
|
|
.fails()
|
|
|
|
.no_stdout();
|
2016-05-22 11:59:57 +00:00
|
|
|
}
|
2021-03-28 11:00:49 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_posix_mode() {
|
|
|
|
// test the posix mode
|
|
|
|
|
|
|
|
// accept some reasonable default
|
|
|
|
new_ucmd!().args(&["-p", "dir/file"]).succeeds().no_stdout();
|
|
|
|
|
|
|
|
// fail on long path
|
|
|
|
new_ucmd!()
|
2021-06-06 19:13:54 +00:00
|
|
|
.args(&["-p", "dir".repeat(libc::PATH_MAX as usize + 1).as_str()])
|
2021-03-28 11:00:49 +00:00
|
|
|
.fails()
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
// fail on long filename
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&[
|
|
|
|
"-p",
|
2021-06-06 19:13:54 +00:00
|
|
|
format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
|
2021-03-28 11:00:49 +00:00
|
|
|
])
|
|
|
|
.fails()
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
// fail on non-portable chars
|
|
|
|
new_ucmd!().args(&["-p", "dir#/$file"]).fails().no_stdout();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_posix_special() {
|
|
|
|
// test the posix special mode
|
|
|
|
|
|
|
|
// 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 19:13:54 +00:00
|
|
|
.args(&["-P", "dir".repeat(libc::PATH_MAX as usize + 1).as_str()])
|
2021-03-28 11:00:49 +00:00
|
|
|
.fails()
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
// fail on long filename
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&[
|
|
|
|
"-P",
|
2021-06-06 19:13:54 +00:00
|
|
|
format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
|
2021-03-28 11:00:49 +00:00
|
|
|
])
|
|
|
|
.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]
|
|
|
|
fn test_posix_all() {
|
|
|
|
// test the posix special mode
|
|
|
|
|
|
|
|
// accept some reasonable default
|
2021-03-30 19:24:01 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-p", "-P", "dir/file"])
|
|
|
|
.succeeds()
|
|
|
|
.no_stdout();
|
2021-03-28 11:00:49 +00:00
|
|
|
|
|
|
|
// 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 19:13:54 +00:00
|
|
|
"dir".repeat(libc::PATH_MAX as usize + 1).as_str(),
|
2021-03-28 11:00:49 +00:00
|
|
|
])
|
|
|
|
.fails()
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
// fail on long filename
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&[
|
|
|
|
"-p",
|
|
|
|
"-P",
|
2021-06-06 19:13:54 +00:00
|
|
|
format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
|
2021-03-28 11:00:49 +00:00
|
|
|
])
|
|
|
|
.fails()
|
|
|
|
.no_stdout();
|
|
|
|
|
|
|
|
// fail on non-portable chars
|
2021-03-30 19:24:01 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-p", "-P", "dir#/$file"])
|
|
|
|
.fails()
|
|
|
|
.no_stdout();
|
2021-03-28 11:00:49 +00:00
|
|
|
|
|
|
|
// fail on leading hyphen char
|
2021-03-30 19:24:01 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-p", "-P", "dir/-file"])
|
|
|
|
.fails()
|
|
|
|
.no_stdout();
|
2021-03-28 11:00:49 +00:00
|
|
|
|
|
|
|
// fail on empty path
|
|
|
|
new_ucmd!().args(&["-p", "-P", ""]).fails().no_stdout();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_args_parsing() {
|
|
|
|
// fail on no args
|
|
|
|
let empty_args: [String; 0] = [];
|
2021-03-30 19:24:01 +00:00
|
|
|
new_ucmd!().args(&empty_args).fails().no_stdout();
|
|
|
|
}
|