Skip to content
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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,17 @@ jobs:
flags: ${{ steps.vars.outputs.CODECOV_FLAGS }}
name: codecov-umbrella
fail_ci_if_error: false

wrapper-tests:
name: wrapper binaries integration tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- name: Run wrapper binary tests
run: |
# Run only the wrapper integration tests to validate wrapper behavior
cargo test --test test_wrapper_binaries -- --nocapture
64 changes: 64 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ rand = { workspace = true }
uutests = { workspace = true }
ctor = { workspace = true }
uucore = { workspace = true, features = ["entries", "process", "signals"] }
assert_cmd = "2.0"

[target.'cfg(unix)'.dev-dependencies]
xattr = { workspace = true }
Expand Down
12 changes: 12 additions & 0 deletions src/bin/dnsdomainname.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Wrapper binary: dnsdomainname -> hostname -d
fn main() {
uucore::panic::mute_sigpipe_panic();

use std::ffi::OsString;
use std::process;

let args = std::env::args_os().skip(1);
let iter = (vec![OsString::from("hostname"), OsString::from("-d")].into_iter()).chain(args);

process::exit(hostname::uumain(iter));
}
12 changes: 12 additions & 0 deletions src/bin/domainname.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Wrapper binary: domainname -> hostname -d
fn main() {
uucore::panic::mute_sigpipe_panic();

use std::ffi::OsString;
use std::process;

let args = std::env::args_os().skip(1);
let iter = (vec![OsString::from("hostname"), OsString::from("-d")].into_iter()).chain(args);

process::exit(hostname::uumain(iter));
}
12 changes: 12 additions & 0 deletions src/bin/nisdomainname.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Wrapper binary: nisdomainname -> hostname -y (visible alias)
fn main() {
uucore::panic::mute_sigpipe_panic();

use std::ffi::OsString;
use std::process;

let args = std::env::args_os().skip(1);
let iter = (vec![OsString::from("hostname"), OsString::from("-y")].into_iter()).chain(args);

process::exit(hostname::uumain(iter));
}
12 changes: 12 additions & 0 deletions src/bin/ypdomainname.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Wrapper binary: ypdomainname -> hostname -y
fn main() {
uucore::panic::mute_sigpipe_panic();

use std::ffi::OsString;
use std::process;

let args = std::env::args_os().skip(1);
let iter = (vec![OsString::from("hostname"), OsString::from("-y")].into_iter()).chain(args);

process::exit(hostname::uumain(iter));
}
94 changes: 94 additions & 0 deletions tests/test_wrapper_binaries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use assert_cmd::Command as AssertCommand;

// Note: use `cargo::cargo_bin_cmd!` macro to obtain the built binary to run.
// We avoid `Command::cargo_bin` (deprecated) and prefer the macro which is
// compatible with custom Cargo build directories.
fn run_output_from_cmd(cmd: &mut AssertCommand) -> (i32, String, String) {
let output = cmd.output().unwrap();
(
output.status.code().unwrap_or(-1),
String::from_utf8_lossy(&output.stdout).to_string(),
String::from_utf8_lossy(&output.stderr).to_string(),
)
}

fn normalize_output(output: &(i32, String, String)) -> (i32, String, String) {
use regex::Regex;

// Normalize CRLF to LF so comparisons succeed across platforms.
let mut stdout = output.1.replace("\r\n", "\n");
let mut stderr = output.2.replace("\r\n", "\n");

// Replace absolute/relative paths to the built binaries (handles both
// POSIX and Windows path separators and optional .exe suffix).
let path_re = Regex::new(r"[A-Za-z]:[\\/][^\s]*target(?:[\\/](?:debug|release))[\\/][^\s]+|/.*/target/(?:debug|release)/[^\s]+").unwrap();
stdout = path_re.replace_all(&stdout, "hostname").to_string();
stderr = path_re.replace_all(&stderr, "hostname").to_string();

// Replace any bare wrapper binary name occurrences (e.g., 'domainname' or 'domainname.exe') with 'hostname'
let name_re =
Regex::new(r"\b(?:dnsdomainname|domainname|ypdomainname|nisdomainname)\b(?:\.exe)?")
.unwrap();
stdout = name_re.replace_all(&stdout, "hostname").to_string();
stderr = name_re.replace_all(&stderr, "hostname").to_string();

(output.0, stdout, stderr)
}

#[test]
fn dnsdomainname_matches_hostname_d() {
let a = normalize_output(&run_output_from_cmd(
&mut assert_cmd::cargo::cargo_bin_cmd!("dnsdomainname").arg("--help"),
));
let b = normalize_output(&run_output_from_cmd(
&mut assert_cmd::cargo::cargo_bin_cmd!("hostname")
.arg("-d")
.arg("--help"),
));
assert_eq!(a, b);
}

#[test]
fn domainname_matches_hostname_y() {
let a = normalize_output(&run_output_from_cmd(
&mut assert_cmd::cargo::cargo_bin_cmd!("domainname").arg("--help"),
));
let b = normalize_output(&run_output_from_cmd(
&mut assert_cmd::cargo::cargo_bin_cmd!("hostname")
.arg("-y")
.arg("--help"),
));
assert_eq!(a, b);
}

#[test]
fn nisdomainname_matches_hostname_y() {
let a = normalize_output(&run_output_from_cmd(
&mut assert_cmd::cargo::cargo_bin_cmd!("nisdomainname").arg("--help"),
));
let b = normalize_output(&run_output_from_cmd(
&mut assert_cmd::cargo::cargo_bin_cmd!("hostname")
.arg("-y")
.arg("--help"),
));
assert_eq!(a, b);
}

#[test]
fn ypdomainname_matches_hostname_y() {
let a = normalize_output(&run_output_from_cmd(
&mut assert_cmd::cargo::cargo_bin_cmd!("ypdomainname").arg("--help"),
));
let b = normalize_output(&run_output_from_cmd(
&mut assert_cmd::cargo::cargo_bin_cmd!("hostname")
.arg("-y")
.arg("--help"),
));
assert_eq!(a, b);
}

#[test]
fn ping_wrapper_tests() {
// sanity test to ensure this test file is discovered by the harness
assert!(true);
}