Skip to content

Commit 4ba518d

Browse files
authored
Merge pull request #7446 from cakebaker/true_false_remove_newline_in_version_string
true,false: remove unnecessary newline from version string
2 parents 5b649f4 + 10fc96a commit 4ba518d

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

src/uu/false/src/false.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
2828
let error = match e.kind() {
2929
clap::error::ErrorKind::DisplayHelp => command.print_help(),
3030
clap::error::ErrorKind::DisplayVersion => {
31-
writeln!(std::io::stdout(), "{}", command.render_version())
31+
write!(std::io::stdout(), "{}", command.render_version())
3232
}
3333
_ => Ok(()),
3434
};

src/uu/true/src/true.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
2222
let error = match e.kind() {
2323
clap::error::ErrorKind::DisplayHelp => command.print_help(),
2424
clap::error::ErrorKind::DisplayVersion => {
25-
writeln!(std::io::stdout(), "{}", command.render_version())
25+
write!(std::io::stdout(), "{}", command.render_version())
2626
}
2727
_ => Ok(()),
2828
};

tests/by-util/test_false.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5+
56
use crate::common::util::TestScenario;
7+
use regex::Regex;
8+
69
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
710
use std::fs::OpenOptions;
811

912
#[test]
10-
fn test_exit_code() {
11-
new_ucmd!().fails();
13+
fn test_no_args() {
14+
new_ucmd!().fails().no_output();
1215
}
1316

1417
#[test]
1518
fn test_version() {
16-
new_ucmd!()
17-
.args(&["--version"])
18-
.fails()
19-
.stdout_contains("false");
19+
let re = Regex::new(r"^false .*\d+\.\d+\.\d+\n$").unwrap();
20+
21+
new_ucmd!().args(&["--version"]).fails().stdout_matches(&re);
2022
}
2123

2224
#[test]
@@ -30,7 +32,7 @@ fn test_help() {
3032
#[test]
3133
fn test_short_options() {
3234
for option in ["-h", "-V"] {
33-
new_ucmd!().arg(option).fails().stdout_is("");
35+
new_ucmd!().arg(option).fails().no_output();
3436
}
3537
}
3638

@@ -39,7 +41,7 @@ fn test_conflict() {
3941
new_ucmd!()
4042
.args(&["--help", "--version"])
4143
.fails()
42-
.stdout_is("");
44+
.no_output();
4345
}
4446

4547
#[test]

tests/by-util/test_true.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5+
56
use crate::common::util::TestScenario;
7+
use regex::Regex;
8+
69
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
710
use std::fs::OpenOptions;
811

912
#[test]
10-
fn test_exit_code() {
11-
new_ucmd!().succeeds();
13+
fn test_no_args() {
14+
new_ucmd!().succeeds().no_output();
1215
}
1316

1417
#[test]
1518
fn test_version() {
19+
let re = Regex::new(r"^true .*\d+\.\d+\.\d+\n$").unwrap();
20+
1621
new_ucmd!()
1722
.args(&["--version"])
1823
.succeeds()
19-
.stdout_contains("true");
24+
.stdout_matches(&re);
2025
}
2126

2227
#[test]
@@ -30,7 +35,7 @@ fn test_help() {
3035
#[test]
3136
fn test_short_options() {
3237
for option in ["-h", "-V"] {
33-
new_ucmd!().arg(option).succeeds().stdout_is("");
38+
new_ucmd!().arg(option).succeeds().no_output();
3439
}
3540
}
3641

@@ -39,7 +44,7 @@ fn test_conflict() {
3944
new_ucmd!()
4045
.args(&["--help", "--version"])
4146
.succeeds()
42-
.stdout_is("");
47+
.no_output();
4348
}
4449

4550
#[test]

0 commit comments

Comments
 (0)