diff --git a/Cargo.toml b/Cargo.toml index 6ed71241..54ce18d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,8 @@ onig = { version = "6.4", default-features = false } uucore = { version = "0.0.30", features = ["entries", "fs", "fsext", "mode"] } nix = { version = "0.29", features = ["fs", "user"] } argmax = "0.3.1" +uutests = { version = "0.0.30" } +ctor = "0.4.1" [dev-dependencies] assert_cmd = "2" diff --git a/tests/common/mod.rs b/tests/common/mod.rs index aa8de375..c42353ba 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -8,3 +8,13 @@ // in one test but not another can cause a dead code warning. #[allow(dead_code)] pub mod test_helpers; +pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_find"); + +// Use the ctor attribute to run this function before any tests +#[ctor::ctor] +fn init() { + unsafe { + // Necessary for uutests to be able to find the binary + std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY); + } +} diff --git a/tests/find_cmd_tests.rs b/tests/find_cmd_tests.rs index c4c3692e..7f7a53d6 100644 --- a/tests/find_cmd_tests.rs +++ b/tests/find_cmd_tests.rs @@ -16,6 +16,8 @@ use std::fs::{self, File}; use std::io::{Read, Write}; use std::{env, io::ErrorKind}; use tempfile::Builder; +use uutests::util::TestScenario; +use uutests::{at_and_ucmd, new_ucmd, util_name}; #[cfg(unix)] use std::os::unix::fs::symlink; @@ -39,15 +41,14 @@ fn fix_up_regex_slashes(re: &str) -> String { re.to_owned() } -#[serial(working_dir)] #[test] fn no_args() { - Command::cargo_bin("find") - .expect("found binary") - .assert() - .success() - .stderr(predicate::str::is_empty()) - .stdout(predicate::str::contains("test_data")); + let ts = TestScenario::new("find"); + ts.cmd(env!("CARGO_BIN_EXE_find")) + .current_dir(env!("CARGO_MANIFEST_DIR")) + .succeeds() + .no_stderr() + .stdout_contains("test_data"); } #[serial(working_dir)] @@ -707,15 +708,13 @@ fn find_time() { #[test] fn expression_empty_parentheses() { - Command::cargo_bin("find") - .expect("found binary") - .args(["-true", "(", ")"]) - .assert() - .failure() - .stderr(predicate::str::contains( - "empty parentheses are not allowed", - )) - .stdout(predicate::str::is_empty()); + let (_at, mut ucmd) = at_and_ucmd!(); + ucmd.arg("-true") + .arg("(") + .arg(")") + .fails() + .stderr_contains("empty parentheses are not allowed") + .no_stdout(); } #[test]