mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
hostname: fix -d flag (#8657)
* hostname: fix -d flag * tests/hostname: test -d when no domain
This commit is contained in:
@@ -177,8 +177,10 @@ fn display_hostname(matches: &ArgMatches) -> UResult<()> {
|
||||
} else {
|
||||
println!("{}", &hostname[ci.0 + 1..]);
|
||||
}
|
||||
return Ok(());
|
||||
} else if matches.get_flag(OPT_SHORT) {
|
||||
println!("{hostname}");
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
println!("{hostname}");
|
||||
|
||||
@@ -37,3 +37,16 @@ fn test_hostname_full() {
|
||||
fn test_invalid_arg() {
|
||||
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hostname_domain_empty() {
|
||||
let fqdn = new_ucmd!().arg("-f").succeeds();
|
||||
let short = new_ucmd!().arg("-s").succeeds();
|
||||
let domain = new_ucmd!().arg("-d").succeeds();
|
||||
let domain_short = new_ucmd!().arg("-sd").succeeds();
|
||||
|
||||
if fqdn.stdout() == short.stdout() {
|
||||
assert!(domain.stdout().is_empty());
|
||||
assert!(domain_short.stdout().is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user