1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-16 19:56:17 +00:00

Merge branch 'master' into ls_selinux

This commit is contained in:
Jan Scheer 2021-09-17 14:14:47 +02:00
commit 79d838b1c3
No known key found for this signature in database
GPG key ID: C62AD4C29E2B9828
70 changed files with 685 additions and 182 deletions

View file

@ -9,7 +9,7 @@ use std::os::unix::fs;
#[cfg(unix)]
use std::os::unix::fs::symlink as symlink_file;
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "freebsd")))]
use std::os::unix::fs::PermissionsExt;
#[cfg(windows)]
use std::os::windows::fs::symlink_file;

View file

@ -373,6 +373,7 @@ fn test_ls_long_format() {
/// This test does not really test anything provided by `-l` but the file names and symlinks.
#[cfg(all(feature = "ln", feature = "mkdir", feature = "touch"))]
#[test]
#[cfg(all(feature = "ln", feature = "mkdir", feature = "touch"))]
fn test_ls_long_symlink_color() {
// If you break this test after breaking mkdir, touch, or ln, do not be alarmed!
// This test is made for ls, but it attempts to run those utils in the process.

View file

@ -1,4 +1,5 @@
use crate::common::util::*;
use std::io::Read;
#[test]
fn test_rejects_nan() {
@ -176,3 +177,50 @@ fn test_width_negative_zero() {
.stdout_is("-0\n01\n")
.no_stderr();
}
// TODO This is duplicated from `test_yes.rs`; refactor them.
/// Run `seq`, capture some of the output, close the pipe, and verify it.
fn run(args: &[&str], expected: &[u8]) {
let mut cmd = new_ucmd!();
let mut child = cmd.args(args).run_no_wait();
let mut stdout = child.stdout.take().unwrap();
let mut buf = vec![0; expected.len()];
stdout.read_exact(&mut buf).unwrap();
drop(stdout);
assert!(child.wait().unwrap().success());
assert_eq!(buf.as_slice(), expected);
}
#[test]
fn test_neg_inf() {
run(&["--", "-inf", "0"], b"-inf\n-inf\n-inf\n");
}
#[test]
fn test_inf() {
run(&["inf"], b"1\n2\n3\n");
}
#[test]
fn test_ignore_leading_whitespace() {
new_ucmd!()
.arg(" 1")
.succeeds()
.stdout_is("1\n")
.no_stderr();
}
#[test]
fn test_trailing_whitespace_error() {
// In some locales, the GNU error message has curly quotes ()
// instead of straight quotes ('). We just test the straight single
// quotes.
new_ucmd!()
.arg("1 ")
.fails()
.no_stdout()
.stderr_contains("seq: invalid floating point argument: '1 '")
// FIXME The second line of the error message is "Try 'seq
// --help' for more information."
.stderr_contains("for more information.");
}

View file

@ -1,4 +1,4 @@
// spell-checker:ignore axxbxx bxxaxx axxx axxxx xxaxx xxax xxxxa
// spell-checker:ignore axxbxx bxxaxx axxx axxxx xxaxx xxax xxxxa axyz zyax zyxa
use crate::common::util::*;
#[test]
@ -205,3 +205,67 @@ fn test_null_separator() {
.succeeds()
.stdout_is("b\0a\0");
}
#[test]
fn test_regex() {
new_ucmd!()
.args(&["-r", "-s", "[xyz]+"])
.pipe_in("axyz")
.succeeds()
.no_stderr()
.stdout_is("zyax");
new_ucmd!()
.args(&["-r", "-s", ":+"])
.pipe_in("a:b::c:::d::::")
.succeeds()
.no_stderr()
.stdout_is(":::d:::c::b:a:");
new_ucmd!()
.args(&["-r", "-s", r"[\+]+[-]+[\+]+"])
// line 0 1 2
// |--||-----||--------|
.pipe_in("a+-+b++--++c+d-e+---+")
.succeeds()
.no_stderr()
// line 2 1 0
// |--------||-----||--|
.stdout_is("c+d-e+---+b++--++a+-+");
}
#[test]
fn test_regex_before() {
new_ucmd!()
.args(&["-b", "-r", "-s", "[xyz]+"])
.pipe_in("axyz")
.succeeds()
.no_stderr()
.stdout_is("zyxa");
new_ucmd!()
.args(&["-b", "-r", "-s", ":+"])
.pipe_in(":a::b:::c::::d")
.succeeds()
.stdout_is(":d::::c:::b::a");
// Because `tac` searches for matches of the regular expression from
// right to left, the second to last line is
//
// +--++b
//
// not
//
// ++--++b
//
new_ucmd!()
.args(&["-b", "-r", "-s", r"[\+]+[-]+[\+]+"])
// line 0 1 2
// |---||----||--------|
.pipe_in("+-+a++--++b+---+c+d-e")
.succeeds()
.no_stderr()
// line 2 1 0
// |--------||----||---|
.stdout_is("+---+c+d-e+--++b+-+a+");
}

View file

@ -3,7 +3,7 @@
// * For the full copyright and license information, please view the LICENSE
// * file that was distributed with this source code.
//spell-checker: ignore (linux) rlimit prlimit Rlim coreutil
//spell-checker: ignore (linux) rlimit prlimit Rlim coreutil ggroups
#![allow(dead_code)]
@ -1081,7 +1081,14 @@ pub fn host_name_for(util_name: &str) -> Cow<str> {
// In some environments, e.g. macOS/freebsd, the GNU coreutils are prefixed with "g"
// to not interfere with the BSD counterparts already in `$PATH`.
#[cfg(not(target_os = "linux"))]
return format!("g{}", util_name).into();
{
// make call to `host_name_for` idempotent
if util_name.starts_with('g') && util_name != "groups" {
return util_name.into();
} else {
return format!("g{}", util_name).into();
}
}
#[cfg(target_os = "linux")]
return util_name.into();
}
@ -1195,8 +1202,8 @@ pub fn check_coreutil_version(
///```
#[cfg(unix)]
pub fn expected_result(ts: &TestScenario, args: &[&str]) -> std::result::Result<CmdResult, String> {
println!("{}", check_coreutil_version(&ts.util_name, VERSION_MIN)?);
let util_name = &host_name_for(&ts.util_name);
println!("{}", check_coreutil_version(util_name, VERSION_MIN)?);
let result = ts
.cmd_keepenv(util_name.as_ref())
@ -1493,4 +1500,25 @@ mod tests {
let ts = TestScenario::new("no test name");
assert!(expected_result(&ts, &[]).is_err());
}
#[test]
#[cfg(unix)]
fn test_host_name_for() {
#[cfg(target_os = "linux")]
{
std::assert_eq!(host_name_for("id"), "id");
std::assert_eq!(host_name_for("groups"), "groups");
std::assert_eq!(host_name_for("who"), "who");
}
#[cfg(not(target_os = "linux"))]
{
// spell-checker:ignore (strings) ggroups gwho
std::assert_eq!(host_name_for("id"), "gid");
std::assert_eq!(host_name_for("groups"), "ggroups");
std::assert_eq!(host_name_for("who"), "gwho");
std::assert_eq!(host_name_for("gid"), "gid");
std::assert_eq!(host_name_for("ggroups"), "ggroups");
std::assert_eq!(host_name_for("gwho"), "gwho");
}
}
}