Skip to content

Commit 8f7fb51

Browse files
committed
Merge branch 'sylvestre-main'
2 parents 1983b57 + ab9e506 commit 8f7fb51

File tree

117 files changed

+1498
-926
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

+1498
-926
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

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

0 commit comments

Comments
 (0)