Skip to content

Commit db62c24

Browse files
committed
make sudo --help and sudo --version print on stdout
1 parent b239c27 commit db62c24

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/sudo/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ fn sudo_process() -> Result<(), Error> {
8181
match SudoAction::from_env() {
8282
Ok(action) => match action {
8383
SudoAction::Help(_) => {
84-
eprintln_ignore_io_error!("{}", long_help());
84+
println_ignore_io_error!("{}", long_help());
8585
std::process::exit(0);
8686
}
8787
SudoAction::Version(_) => {
88-
eprintln_ignore_io_error!("sudo-rs {VERSION}");
88+
println_ignore_io_error!("sudo-rs {VERSION}");
8989
std::process::exit(0);
9090
}
9191
SudoAction::RemoveTimestamp(_) => {

test-framework/sudo-compliance-tests/src/sudo/flag_help.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,22 @@ fn does_not_panic_on_io_errors() -> Result<()> {
1616

1717
Ok(())
1818
}
19+
20+
#[test]
21+
fn prints_on_stdout() -> Result<()> {
22+
let env = Env("").build();
23+
24+
let output = Command::new("sudo").args(["--version"]).output(&env);
25+
26+
let output = output.stdout();
27+
assert_starts_with!(
28+
output,
29+
if sudo_test::is_original_sudo() {
30+
"sudo - execute a command as another user"
31+
} else {
32+
"sudo - run commands as another user"
33+
}
34+
);
35+
36+
Ok(())
37+
}

test-framework/sudo-compliance-tests/src/sudo/flag_version.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ fn does_not_panic_on_io_errors() -> Result<()> {
1919

2020
Ok(())
2121
}
22+
23+
#[test]
24+
fn prints_on_stdout() -> Result<()> {
25+
let env = Env("").build();
26+
27+
let output = Command::new("sudo").args(["--version"]).output(&env);
28+
29+
let output = output.stdout();
30+
assert_starts_with!(
31+
output,
32+
if sudo_test::is_original_sudo() {
33+
"Sudo version"
34+
} else {
35+
"sudo-rs"
36+
}
37+
);
38+
39+
Ok(())
40+
}

0 commit comments

Comments
 (0)