8000 tests: test multi-call logic by BenWiederhake · Pull Request #6198 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tests: test multi-call logic #6198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions tests/test_util_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,154 @@ fn util_name_single() {
scenario.fixtures.plus("uu-sort").display()
)));
}

#[test]
#[cfg(any(unix, windows))]
fn util_invalid_name_help() {
use std::{
io::Write,
process::{Command, Stdio},
};

let scenario = TestScenario::new("invalid_name");
symlink_file(scenario.bin_path, scenario.fixtures.plus("invalid_name")).unwrap();
let child = Command::new(scenario.fixtures.plus("invalid_name"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to adapt the test framework to support this so that we can write this test witht it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, sure, it is possible to do so, but I don't see the benefit?

The tests "unrecognized name" and "non-UTF-8 name" are likely going to be the only use cases for this. Perhaps one more edge case that I overlooked, but I really don't see the advantage to make this more generally available.

.arg("--help")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
let output = child.wait_with_output().unwrap();
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
assert!(
output_str.contains("(multi-call binary)"),
"{:?}",
output_str
);
assert!(
output_str.contains("Usage: invalid_name [function "),
"{:?}",
output_str
);
}

#[test]
// The exact set of permitted filenames depends on many factors. Non-UTF-8 strings
// work on very few platforms, but linux works, especially because it also increases
// the likelihood that a filesystem is being used that supports non-UTF-8 filenames.
#[cfg(target_os = "linux")]
fn util_non_utf8_name_help() {
// Make sure we don't crash even if the util name is invalid UTF-8.
use std::{
ffi::OsStr,
io::Write,
os::unix::ffi::OsStrExt,
path::Path,
process::{Command, Stdio},
};

let scenario = TestScenario::new("invalid_name");
let non_utf8_path = scenario.fixtures.plus(OsStr::from_bytes(b"\xff"));
symlink_file(scenario.bin_path, &non_utf8_path).unwrap();
let child = Command::new(&non_utf8_path)
.arg("--help")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
let output = child.wait_with_output().unwrap();
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
assert!(
output_str.contains("(multi-call binary)"),
"{:?}",
output_str
);
assert!(
output_str.contains("Usage: <unknown binary name> [function "),
"{:?}",
output_str
);
}

#[test]
#[cfg(any(unix, windows))]
fn util_invalid_name_invalid_command() {
use std::{
io::Write,
process::{Command, Stdio},
};

let scenario = TestScenario::new("invalid_name");
symlink_file(scenario.bin_path, scenario.fixtures.plus("invalid_name")).unwrap();
let child = Command::new(scenario.fixtures.plus("invalid_name"))
.arg("definitely_invalid")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
let output = child.wait_with_output().unwrap();
assert_eq!(output.status.code(), Some(1));
assert_eq!(output.stderr, b"");
assert_eq!(
output.stdout,
b"definitely_invalid: function/utility not found\n"
);
}

#[test]
fn util_completion() {
use std::{
io::Write,
process::{Command, Stdio},
};

let scenario = TestScenario::new("completion");
let child = Command::new(scenario.bin_path)
.arg("completion")
.arg("true")
.arg("powershell")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
let output = child.wait_with_output().unwrap();
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
assert!(
output_str.contains("using namespace System.Management.Automation"),
"{:?}",
output_str
);
}

#[test]
fn util_manpage() {
use std::{
io::Write,
process::{Command, Stdio},
};

let scenario = TestScenario::new("completion");
let child = Command::new(scenario.bin_path)
.arg("manpage")
.arg("true")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
let output = child.wait_with_output().unwrap();
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
assert!(output_str.contains("\n.TH true 1 "), "{:?}", output_str);
}
0