Skip to content

Commit 7b4e430

Browse files
committed
Merge branch 'sylvestre-main'
2 parents 9c0ff86 + 2aa196b commit 7b4e430

File tree

117 files changed

+1496
-920
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1496
-920
lines changed

.vscode/cspell.dictionaries/workspace.wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,15 @@ libc
325325
libstdbuf
326326
musl
327327
tmpd
328+
uchild
328329
ucmd
329330
ucommand
330331
utmpx
331332
uucore
332333
uucore_procs
333334
uudoc
334335
uumain
336+
uutests
335337
uutil
336338
uutils
337339

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ parts for getting started:
3131

3232
- [`src/uu`](./src/uu/): The code for all utilities
3333
- [`src/uucore`](./src/uucore/): Crate containing all the shared code between
34-
the utilities.
34+
the utilities. This crate is also used outside of the Coreutils.
3535
- [`tests/by-util`](./tests/by-util/): The tests for all utilities.
3636
- [`src/bin/coreutils.rs`](./src/bin/coreutils.rs): Code for the multicall
3737
binary.
3838
- [`docs`](./docs/src): the documentation for the website
39+
- [`tests/uutests/`](./tests/uutests/): Crate implementing
40+
the various functions to test uutils commands.
3941

4042
Each utility is defined as a separate crate. The structure of each of these
4143
crates is as follows:
@@ -62,6 +64,8 @@ We have the following goals with our development:
6264
- **Reliable**: The utilities should never unexpectedly fail.
6365
- **Performant**: Our utilities should be written in fast idiomatic Rust. We aim
6466
to match or exceed the performance of the GNU utilities.
67+
[hyperfine](https://github.com/sharkdp/hyperfine) is the recommended tool for
68+
this task.
6569
- **Well-tested**: We should have a lot of tests to be able to guarantee
6670
reliability and compatibility.
6771

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

@@ -363,6 +367,7 @@ uucore = { version = "0.0.29", package = "uucore", path = "src/uucore" }
363367
uucore_procs = { version = "0.0.29", package = "uucore_procs", path = "src/uucore_procs" }
364368
uu_ls = { version = "0.0.29", path = "src/uu/ls" }
365369
uu_base32 = { version = "0.0.29", path = "src/uu/base32" }
370+
uutests = { version = "0.0.29", package = "uutests", path = "tests/uutests/" }
366371

367372
[dependencies]
368373
clap = { workspace = true }
@@ -491,6 +496,7 @@ yes = { optional = true, version = "0.0.29", package = "uu_yes", path = "src/uu/
491496
#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()`)
492497

493498
[dev-dependencies]
499+
uutests = { workspace = true }
494500
chrono = { workspace = true }
495501
filetime = { workspace = true }
496502
glob = { workspace = true }
@@ -503,6 +509,7 @@ sha1 = { workspace = true, features = ["std"] }
503509
tempfile = { workspace = true }
504510
time = { workspace = true, features = ["local-offset"] }
505511
unindent = "0.2.3"
512+
#uutests = { workspace = true }
506513
uucore = { workspace = true, features = [
507514
"mode",
508515
"entries",
@@ -514,17 +521,17 @@ walkdir = { workspace = true }
514521
hex-literal = "0.4.1"
515522
rstest = { workspace = true }
516523

517-
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dev-dependencies]
524+
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
518525
procfs = { version = "0.17", default-features = false }
519526

520-
[target.'cfg(unix)'.dev-dependencies]
527+
[target.'cfg(unix)'.dependencies]
521528
nix = { workspace = true, features = ["process", "signal", "user", "term"] }
522529
rlimit = "0.10.1"
523530
xattr = { workspace = true }
524531

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

tests/by-util/test_arch.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5-
use crate::common::util::TestScenario;
5+
use uutests::new_ucmd;
6+
use uutests::util::TestScenario;
7+
use uutests::util_name;
68

79
#[test]
810
fn test_arch() {

tests/by-util/test_base32.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// file that was distributed with this source code.
55
//
66

7-
use crate::common::util::TestScenario;
7+
use uutests::new_ucmd;
8+
use uutests::util::TestScenario;
9+
use uutests::util_name;
810

911
#[test]
1012
fn test_encode() {

tests/by-util/test_base64.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5-
use crate::common::util::TestScenario;
5+
use uutests::new_ucmd;
6+
use uutests::util::TestScenario;
7+
use uutests::util_name;
68

79
#[test]
810
fn test_encode() {

tests/by-util/test_basename.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
// file that was distributed with this source code.
55
// spell-checker:ignore (words) reallylongexecutable nbaz
66

7-
use crate::common::util::TestScenario;
87
#[cfg(any(unix, target_os = "redox"))]
98
use std::ffi::OsStr;
9+
use uutests::new_ucmd;
10+
use uutests::util::TestScenario;
11+
use uutests::util_name;
1012

1113
#[test]
1214
fn test_help() {

tests/by-util/test_basenc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
// spell-checker: ignore (encodings) lsbf msbf
77

8-
use crate::common::util::TestScenario;
8+
use uutests::new_ucmd;
9+
use uutests::util::TestScenario;
10+
use uutests::util_name;
911

1012
#[test]
1113
fn test_z85_not_padded_decode() {

tests/by-util/test_cat.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
// file that was distributed with this source code.
55
// spell-checker:ignore NOFILE nonewline cmdline
66

7-
#[cfg(not(windows))]
8-
use crate::common::util::vec_of_size;
9-
use crate::common::util::TestScenario;
107
#[cfg(any(target_os = "linux", target_os = "android"))]
118
use rlimit::Resource;
12-
#[cfg(target_os = "linux")]
9+
#[cfg(unix)]
1310
use std::fs::File;
1411
use std::fs::OpenOptions;
15-
#[cfg(not(windows))]
1612
use std::process::Stdio;
13+
use uutests::at_and_ucmd;
14+
use uutests::new_ucmd;
15+
#[cfg(not(windows))]
16+
use uutests::util::vec_of_size;
17+
use uutests::util::TestScenario;
18+
use uutests::util_name;
1719

1820
#[test]
1921
fn test_output_simple() {
@@ -668,3 +670,40 @@ fn test_appending_same_input_output() {
668670
.no_stdout()
669671
.stderr_contains("input file is output file");
670672
}
673+
674+
#[cfg(unix)]
675+
#[test]
676+
fn test_uchild_when_no_capture_reading_from_infinite_source() {
677+
use regex::Regex;
678+
679+
let ts = TestScenario::new("cat");
680+
681+
let expected_stdout = b"\0".repeat(12345);
682+
let mut child = ts
683+
.ucmd()
684+
.set_stdin(Stdio::from(File::open("/dev/zero").unwrap()))
685+
.set_stdout(Stdio::piped())
686+
.run_no_wait();
687+
688+
child
689+
.make_assertion()
690+
.with_exact_output(12345, 0)
691+
.stdout_only_bytes(expected_stdout);
692+
693+
child
694+
.kill()
695+
.make_assertion()
696+
.with_current_output()
697+
.stdout_matches(&Regex::new("[\0].*").unwrap())
698+
.no_stderr();
699+
}
700+
701+
#[test]
702+
fn test_child_when_pipe_in() {
703+
let ts = TestScenario::new("cat");
704+
let mut child = ts.ucmd().set_stdin(Stdio::piped()).run_no_wait();
705+
child.pipe_in("content");
706+
child.wait().unwrap().stdout_only("content").success();
707+
708+
ts.ucmd().pipe_in("content").run().stdout_is("content");
709+
}

0 commit comments

Comments
 (0)