Skip to content

Commit 1e8f868

Browse files
committed
coreutils: use uutests
1 parent 1d18c10 commit 1e8f868

File tree

3 files changed

+145
-49
lines changed

3 files changed

+145
-49
lines changed

Cargo.lock

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ feat_os_windows_legacy = [
263263
# * bypass/override ~ translate 'test' feature name to avoid dependency collision with rust core 'test' crate (o/w surfaces as compiler errors during testing)
264264
test = ["uu_test"]
265265

266+
[workspace]
267+
members = ["tests/uutests"]
268+
default-members = ["."]
269+
266270
[workspace.package]
267271
readme = "README.package.md"
268272

@@ -366,6 +370,7 @@ uucore = { version = "0.0.30", package = "uucore", path = "src/uucore" }
366370
uucore_procs = { version = "0.0.30", package = "uucore_procs", path = "src/uucore_procs" }
367371
uu_ls = { version = "0.0.30", path = "src/uu/ls" }
368372
uu_base32 = { version = "0.0.30", path = "src/uu/base32" }
373+
uutests = { version = "0.0.30", package = "uutests", path = "tests/uutests/" }
369374

370375
[dependencies]
371376
clap = { workspace = true }
@@ -493,6 +498,7 @@ yes = { optional = true, version = "0.0.30", package = "uu_yes", path = "src/uu/
493498
#pin_cc = { version="1.0.61, < 1.0.62", package="cc" } ## cc v1.0.62 has compiler errors for MinRustV v1.32.0, requires 1.34 (for `std::str::split_ascii_whitespace()`)
494499

495500
[dev-dependencies]
501+
uutests = { workspace = true }
496502
chrono = { workspace = true }
497503
filetime = { workspace = true }
498504
glob = { workspace = true }
@@ -505,6 +511,7 @@ sha1 = { workspace = true, features = ["std"] }
505511
tempfile = { workspace = true }
506512
time = { workspace = true, features = ["local-offset"] }
507513
unindent = "0.2.3"
514+
#uutests = { workspace = true }
508515
uucore = { workspace = true, features = [
509516
"mode",
510517
"entries",
@@ -516,17 +523,17 @@ walkdir = { workspace = true }
516523
hex-literal = "0.4.1"
517524
rstest = { workspace = true }
518525

519-
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dev-dependencies]
526+
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
520527
procfs = { version = "0.17", default-features = false }
521528

522-
[target.'cfg(unix)'.dev-dependencies]
529+
[target.'cfg(unix)'.dependencies]
523530
nix = { workspace = true, features = ["process", "signal", "user", "term"] }
524531
rlimit = "0.10.1"
525532
xattr = { workspace = true }
526533

527534
# Specifically used in test_uptime::test_uptime_with_file_containing_valid_boot_time_utmpx_record
528535
# to deserialize a utmpx struct into a binary file
529-
[target.'cfg(all(target_family= "unix",not(target_os = "macos")))'.dev-dependencies]
536+
[target.'cfg(all(target_family= "unix",not(target_os = "macos")))'.dependencies]
530537
serde = { version = "1.0.202", features = ["derive"] }
531538
bincode = { version = "1.3.3" }
532539
serde-big-array = "0.5.1"

tests/test_util_name.rs

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5-
#![allow(unused_imports)]
6-
mod common;
7-
8-
use common::util::TestScenario;
5+
use uutests::util::TestScenario;
96

107
#[cfg(unix)]
118
use std::os::unix::fs::symlink as symlink_file;
12-
#[cfg(windows)]
13-
use std::os::windows::fs::symlink_file;
149

1510
#[test]
1611
#[cfg(feature = "ls")]
1712
fn execution_phrase_double() {
1813
use std::process::Command;
1914

2015
let scenario = TestScenario::new("ls");
16+
println!("scenario.bin_path: {:?}", scenario.bin_path);
17+
if !scenario.bin_path.exists() {
18+
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
19+
return;
20+
}
2121
let output = Command::new(&scenario.bin_path)
2222
.arg("ls")
2323
.arg("--some-invalid-arg")
@@ -28,25 +28,6 @@ fn execution_phrase_double() {
2828
.contains(&format!("Usage: {} ls", scenario.bin_path.display(),)));
2929
}
3030

31-
#[test]
32-
#[cfg(feature = "ls")]
33-
#[cfg(any(unix, windows))]
34-
fn execution_phrase_single() {
35-
use std::process::Command;
36-
37-
let scenario = TestScenario::new("ls");
38-
symlink_file(&scenario.bin_path, scenario.fixtures.plus("uu-ls")).unwrap();
39-
let output = Command::new(scenario.fixtures.plus("uu-ls"))
40-
.arg("--some-invalid-arg")
41-
.output()
42-
.unwrap();
43-
dbg!(String::from_utf8(output.stderr.clone()).unwrap());
44-
assert!(String::from_utf8(output.stderr).unwrap().contains(&format!(
45-
"Usage: {}",
46-
scenario.fixtures.plus("uu-ls").display()
47-
)));
48-
}
49-
5031
#[test]
5132
#[cfg(feature = "sort")]
5233
fn util_name_double() {
@@ -56,6 +37,11 @@ fn util_name_double() {
5637
};
5738

5839
let scenario = TestScenario::new("sort");
40+
println!("scenario.bin_path: {:?}", scenario.bin_path);
41+
if !scenario.bin_path.exists() {
42+
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
43+
return;
44+
}
5945
let mut child = Command::new(&scenario.bin_path)
6046
.arg("sort")
6147
.stdin(Stdio::piped())
@@ -65,19 +51,25 @@ fn util_name_double() {
6551
// input invalid utf8 to cause an error
6652
child.stdin.take().unwrap().write_all(&[255]).unwrap();
6753
let output = child.wait_with_output().unwrap();
54+
println!("output.stderr = {:?}", output.stderr);
6855
assert!(String::from_utf8(output.stderr).unwrap().contains("sort: "));
6956
}
7057

7158
#[test]
7259
#[cfg(feature = "sort")]
73-
#[cfg(any(unix, windows))]
60+
#[cfg(unix)]
7461
fn util_name_single() {
7562
use std::{
7663
io::Write,
7764
process::{Command, Stdio},
7865
};
7966

8067
let scenario = TestScenario::new("sort");
68+
if !scenario.bin_path.exists() {
69+
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
70+
return;
71+
}
72+
8173
symlink_file(&scenario.bin_path, scenario.fixtures.plus("uu-sort")).unwrap();
8274
let mut child = Command::new(scenario.fixtures.plus("uu-sort"))
8375
.stdin(Stdio::piped())
@@ -94,14 +86,15 @@ fn util_name_single() {
9486
}
9587

9688
#[test]
97-
#[cfg(any(unix, windows))]
89+
#[cfg(unix)]
9890
fn util_invalid_name_help() {
99-
use std::{
100-
io::Write,
101-
process::{Command, Stdio},
102-
};
91+
use std::process::{Command, Stdio};
10392

10493
let scenario = TestScenario::new("invalid_name");
94+
if !scenario.bin_path.exists() {
95+
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
96+
return;
97+
}
10598
symlink_file(&scenario.bin_path, scenario.fixtures.plus("invalid_name")).unwrap();
10699
let child = Command::new(scenario.fixtures.plus("invalid_name"))
107100
.arg("--help")
@@ -130,14 +123,17 @@ fn util_non_utf8_name_help() {
130123
// Make sure we don't crash even if the util name is invalid UTF-8.
131124
use std::{
132125
ffi::OsStr,
133-
io::Write,
134126
os::unix::ffi::OsStrExt,
135-
path::Path,
136127
process::{Command, Stdio},
137128
};
138129

139130
let scenario = TestScenario::new("invalid_name");
140131
let non_utf8_path = scenario.fixtures.plus(OsStr::from_bytes(b"\xff"));
132+
if !scenario.bin_path.exists() {
133+
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
134+
return;
135+
}
136+
141137
symlink_file(&scenario.bin_path, &non_utf8_path).unwrap();
142138
let child = Command::new(&non_utf8_path)
143139
.arg("--help")
@@ -158,15 +154,17 @@ fn util_non_utf8_name_help() {
158154
}
159155

160156
#[test]
161-
#[cfg(any(unix, windows))]
157+
#[cfg(unix)]
162158
fn util_invalid_name_invalid_command() {
163-
use std::{
164-
io::Write,
165-
process::{Command, Stdio},
166-
};
159+
use std::process::{Command, Stdio};
167160

168161
let scenario = TestScenario::new("invalid_name");
169162
symlink_file(&scenario.bin_path, scenario.fixtures.plus("invalid_name")).unwrap();
163+
if !scenario.bin_path.exists() {
164+
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
165+
return;
166+
}
167+
170168
let child = Command::new(scenario.fixtures.plus("invalid_name"))
171169
.arg("definitely_invalid")
172170
.stdin(Stdio::piped())
@@ -186,12 +184,15 @@ fn util_invalid_name_invalid_command() {
186184
#[test]
187185
#[cfg(feature = "true")]
188186
fn util_completion() {
189-
use std::{
190-
io::Write,
191-
process::{Command, Stdio},
192-
};
187+
use std::process::{Command, Stdio};
193188

194189
let scenario = TestScenario::new("completion");
190+
println!("scenario.bin_path: {:?}", scenario.bin_path);
191+
if !scenario.bin_path.exists() {
192+
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
193+
return;
194+
}
195+
195196
let child = Command::new(&scenario.bin_path)
196197
.arg("completion")
197198
.arg("true")
@@ -214,12 +215,15 @@ fn util_completion() {
214215
#[test]
215216
#[cfg(feature = "true")]
216217
fn util_manpage() {
217-
use std::{
218-
io::Write,
219-
process::{Command, Stdio},
220-
};
218+
use std::process::{Command, Stdio};
221219

222220
let scenario = TestScenario::new("completion");
221+
println!("scenario.bin_path: {:?}", scenario.bin_path);
222+
if !scenario.bin_path.exists() {
223+
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
224+
return;
225+
}
226+
223227
let child = Command::new(&scenario.bin_path)
224228
.arg("manpage")
225229
.arg("true")

0 commit comments

Comments
 (0)