Skip to content

Move to use uutests #273

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: local
hooks:
- id: rust-linting
name: Rust linting
description: Run cargo fmt on files included in the commit.
entry: cargo +stable fmt --
pass_filenames: true
types: [file, rust]
language: system
- id: rust-clippy
name: Rust clippy
description: Run cargo clippy on files included in the commit.
entry: cargo +stable clippy --workspace --all-targets --all-features --
pass_filenames: false
types: [file, rust]
language: system
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ tempfile = "3.9.0"
textwrap = { version = "0.16.0", features = ["terminal_size"] }
thiserror = "2.0"
uucore = "0.0.30"
uutests = "0.0.30"
xattr = "1.3.1"

[dependencies]
Expand Down Expand Up @@ -107,7 +108,9 @@ pretty_assertions = "1"
rand = { workspace = true }
regex = { workspace = true }
tempfile = { workspace = true }
uutests = { workspace = true }
uucore = { workspace = true, features = ["entries", "process", "signals"] }
ctor = "0.4.1"

[target.'cfg(unix)'.dev-dependencies]
nix = { workspace = true, features = ["term"] }
Expand Down
13 changes: 10 additions & 3 deletions tests/by-util/test_blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -23,9 +25,12 @@ fn test_report_mutually_exclusive_with_others() {

#[cfg(target_os = "linux")]
mod linux {
use crate::common::util::TestScenario;
use regex::Regex;

use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;

#[test]
fn test_fails_on_first_error() {
new_ucmd!()
Expand Down Expand Up @@ -56,7 +61,9 @@ 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() {
Expand Down
6 changes: 5 additions & 1 deletion tests/by-util/test_ctrlaltdel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
// file that was distributed with this source code.

#[cfg(target_os = "linux")]
use crate::common::util::TestScenario;
use uutests::new_ucmd;
#[cfg(target_os = "linux")]
use uutests::util::TestScenario;
#[cfg(target_os = "linux")]
use uutests::util_name;

#[test]
#[cfg(target_os = "linux")]
Expand Down
5 changes: 4 additions & 1 deletion tests/by-util/test_dmesg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
//
// 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() {
Expand Down
13 changes: 10 additions & 3 deletions tests/by-util/test_fsfreeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -23,7 +25,10 @@ fn test_operations_mutually_exclusive() {

#[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_fails_on_non_existing_path() {
Expand All @@ -48,7 +53,9 @@ 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() {
Expand Down
7 changes: 6 additions & 1 deletion tests/by-util/test_last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) symdir somefakedir

use uutests::at_and_ucmd;
#[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)]
use regex::Regex;
Expand Down
4 changes: 3 additions & 1 deletion tests/by-util/test_lscpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion tests/by-util/test_lslocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
// file that was distributed with this source code.

#[cfg(target_os = "linux")]
use crate::common::util::TestScenario;
use uutests::new_ucmd;
#[cfg(target_os = "linux")]
use uutests::util::TestScenario;
#[cfg(target_os = "linux")]
use uutests::util_name;

#[test]
#[cfg(target_os = "linux")]
Expand Down
4 changes: 3 additions & 1 deletion tests/by-util/test_lsmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// 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 std::path::Path;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;

fn write_file_content(dir: &Path, name: &str, content: &str) {
std::fs::create_dir_all(dir).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion tests/by-util/test_mcookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::io::Write;

use tempfile::NamedTempFile;

use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;

#[test]
fn test_invalid_arg() {
Expand Down
8 changes: 6 additions & 2 deletions tests/by-util/test_mesg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_verb() {
Expand All @@ -24,7 +26,9 @@ fn test_no_terminal() {

#[cfg(not(target_family = "unix"))]
mod non_unix {
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;

#[test]
fn test_fails_on_unsupported_platforms() {
Expand Down
5 changes: 3 additions & 2 deletions tests/by-util/test_mountpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +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() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
Expand Down
4 changes: 3 additions & 1 deletion tests/by-util/test_renice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) symdir somefakedir

use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;

#[test]
fn test_invalid_arg() {
Expand Down
5 changes: 4 additions & 1 deletion tests/by-util/test_rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// 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::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;

#[test]
fn test_invalid_arg() {
Expand Down
24 changes: 17 additions & 7 deletions tests/by-util/test_setsid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

#[cfg(target_family = "unix")]
mod unix {
use crate::common::util::{TestScenario, UCommand, TESTS_BINARY};

use uutests::new_ucmd;
use uutests::util::get_tests_binary;
use uutests::util::TestScenario;
use uutests::util::UCommand;
use uutests::util_name;
#[test]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
Expand Down Expand Up @@ -77,8 +80,11 @@ mod unix {

#[test]
fn unprivileged_user_cannot_steal_controlling_tty() {
let shell_cmd =
format!("{TESTS_BINARY} setsid -w -c {TESTS_BINARY} setsid -w -c /b/usrin/true");
let shell_cmd = format!(
"{} setsid -w -c {} setsid -w -c /b/usrin/true",
get_tests_binary(),
get_tests_binary()
);
UCommand::new()
.terminal_simulation(true)
.arg(&shell_cmd)
Expand All @@ -92,7 +98,8 @@ mod unix {
#[test]
fn unprivileged_user_can_take_new_controlling_tty() {
let shell_cmd = format!(
"/usr/bin/cat /proc/self/stat; {TESTS_BINARY} setsid -w -c /usr/bin/cat /proc/self/stat"
"/usr/bin/cat /proc/self/stat; {} setsid -w -c /usr/bin/cat /proc/self/stat",
get_tests_binary()
);

let cmd_result = UCommand::new()
Expand Down Expand Up @@ -124,7 +131,8 @@ mod unix {
#[test]
fn setsid_takes_session_leadership() {
let shell_cmd = format!(
"/usr/bin/cat /proc/self/stat; {TESTS_BINARY} setsid /usr/bin/cat /proc/self/stat"
"/usr/bin/cat /proc/self/stat; {} setsid /usr/bin/cat /proc/self/stat",
get_tests_binary()
);

let cmd_result = UCommand::new()
Expand Down Expand Up @@ -161,7 +169,9 @@ mod unix {

#[cfg(not(target_family = "unix"))]
mod non_unix {
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;

#[test]
fn unsupported_platforms() {
Expand Down
Loading