use uutests

This commit is contained in:
Sylvestre Ledru
2025-04-11 23:46:36 +02:00
parent 3d54f33730
commit e9ea7a5dc0
23 changed files with 336 additions and 4064 deletions
Generated
+260 -186
View File
File diff suppressed because it is too large Load Diff
+4
View File
@@ -65,6 +65,8 @@ tempfile = "3.10.1"
textwrap = { version = "0.16.1", features = ["terminal_size"] }
thiserror = "2.0.4"
uucore = "0.0.30"
uutests = "0.0.30"
ctor = "0.4.1"
walkdir = "2.5.0"
windows = { version = "0.61.1" }
windows-sys = { version = "0.59.0", default-features = false }
@@ -105,6 +107,8 @@ pretty_assertions = "1.4.0"
rand = { workspace = true }
regex = { workspace = true }
tempfile = { workspace = true }
ctor = { workspace = true }
uutests = { workspace = true }
uucore = { workspace = true, features = ["entries", "process", "signals"] }
[target.'cfg(unix)'.dev-dependencies]
+3 -1
View File
@@ -6,7 +6,9 @@
use pretty_assertions::assert_eq;
use regex::Regex;
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
// TODO: make tests combineable (e.g. test --total --human)
+3 -1
View File
@@ -9,9 +9,11 @@ use std::{
process::{Child, Command},
};
use crate::common::util::TestScenario;
#[cfg(target_os = "linux")]
use regex::Regex;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[cfg(target_os = "linux")]
const SINGLE_PID: &str = "^[1-9][0-9]*";
+3 -1
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_no_args() {
+3 -1
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {
+5 -1
View File
@@ -4,7 +4,11 @@
// file that was distributed with this source code.
#[cfg(unix)]
use crate::common::util::TestScenario;
use uutests::new_ucmd;
#[cfg(unix)]
use uutests::util::TestScenario;
#[cfg(unix)]
use uutests::util_name;
#[cfg(unix)]
#[test]
+3 -1
View File
@@ -3,11 +3,13 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
#[cfg(target_os = "linux")]
use regex::Regex;
#[cfg(target_os = "linux")]
use std::process;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
const NON_EXISTING_PID: &str = "999999";
#[cfg(target_os = "linux")]
+3 -1
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
#[cfg(target_os = "linux")]
+3 -1
View File
@@ -7,7 +7,9 @@ use std::process;
use regex::Regex;
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_no_args() {
+5 -2
View File
@@ -4,8 +4,11 @@
// file that was distributed with this source code.
#[cfg(target_os = "linux")]
use crate::common::util::run_ucmd_as_root;
use crate::common::util::TestScenario;
use uutests::util::run_ucmd_as_root;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {
+3 -1
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_no_args() {
+11 -3
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {
@@ -12,7 +14,10 @@ fn test_invalid_arg() {
#[cfg(target_os = "linux")]
mod linux {
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_get_simple() {
@@ -68,7 +73,10 @@ mod linux {
#[cfg(not(target_os = "linux"))]
mod non_linux {
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_fails_on_unsupported_platforms() {
+3 -1
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {
+3 -1
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {
+3 -1
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_simple() {
+3 -1
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {
+3 -1
View File
@@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
// runddl32.exe has no console window, no side effects,
// and no arguments are required.
-93
View File
@@ -1,93 +0,0 @@
// This file is part of the uutils procps package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
/// Platform-independent helper for constructing a `PathBuf` from individual elements
#[macro_export]
macro_rules! path_concat {
($e:expr, ..$n:expr) => {{
use std::path::PathBuf;
let n = $n;
let mut pb = PathBuf::new();
for _ in 0..n {
pb.push($e);
}
pb.to_str().unwrap().to_owned()
}};
($($e:expr),*) => {{
use std::path::PathBuf;
let mut pb = PathBuf::new();
$(
pb.push($e);
)*
pb.to_str().unwrap().to_owned()
}};
}
/// Deduce the name of the test binary from the test filename.
///
/// e.g.: `tests/by-util/test_cat.rs` -> `cat`
#[macro_export]
macro_rules! util_name {
() => {
module_path!()
.split("_")
.nth(1)
.and_then(|s| s.split("::").next())
.expect("no test name")
};
}
/// Convenience macro for acquiring a [`UCommand`] builder.
///
/// Returns the following:
/// - a [`UCommand`] builder for invoking the binary to be tested
///
/// This macro is intended for quick, single-call tests. For more complex tests
/// that require multiple invocations of the tested binary, see [`TestScenario`]
///
/// [`UCommand`]: crate::tests::common::util::UCommand
/// [`TestScenario]: crate::tests::common::util::TestScenario
#[macro_export]
macro_rules! new_ucmd {
() => {
TestScenario::new(util_name!()).ucmd()
};
}
/// Convenience macro for acquiring a [`UCommand`] builder and a test path.
///
/// Returns a tuple containing the following:
/// - an [`AtPath`] that points to a unique temporary test directory
/// - a [`UCommand`] builder for invoking the binary to be tested
///
/// This macro is intended for quick, single-call tests. For more complex tests
/// that require multiple invocations of the tested binary, see [`TestScenario`]
///
/// [`UCommand`]: crate::tests::common::util::UCommand
/// [`AtPath`]: crate::tests::common::util::AtPath
/// [`TestScenario]: crate::tests::common::util::TestScenario
#[macro_export]
macro_rules! at_and_ucmd {
() => {{
let ts = TestScenario::new(util_name!());
(ts.fixtures.clone(), ts.ucmd())
}};
}
/// If `common::util::expected_result` returns an error, i.e. the `util` in `$PATH` doesn't
/// include a procps version string or the version is too low,
/// this macro can be used to automatically skip the test and print the reason.
#[macro_export]
macro_rules! unwrap_or_return {
( $e:expr ) => {
match $e {
Ok(x) => x,
Err(e) => {
println!("test skipped: {}", e);
return;
}
}
};
}
-8
View File
@@ -1,8 +0,0 @@
// This file is part of the uutils procps package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
#[macro_use]
pub mod macros;
pub mod random;
pub mod util;

Some files were not shown because too many files have changed in this diff Show More