Fix output \r\n
stripping (#2035)
Test if output ends with `\r\n` before `\n`, since the test for `\n` will succeed if output is terminated with `\r\n`, so `\r\n` is properly stripped from output text.
This commit is contained in:
parent
b7c284972d
commit
ad212c77bf
@ -17,13 +17,13 @@ pub(crate) fn output(mut command: Command) -> Result<String, OutputError> {
|
|||||||
}
|
}
|
||||||
match str::from_utf8(&output.stdout) {
|
match str::from_utf8(&output.stdout) {
|
||||||
Err(error) => Err(OutputError::Utf8(error)),
|
Err(error) => Err(OutputError::Utf8(error)),
|
||||||
Ok(utf8) => Ok(
|
Ok(output) => Ok(
|
||||||
if utf8.ends_with('\n') {
|
if output.ends_with("\r\n") {
|
||||||
&utf8[0..utf8.len() - 1]
|
&output[0..output.len() - 2]
|
||||||
} else if utf8.ends_with("\r\n") {
|
} else if output.ends_with('\n') {
|
||||||
&utf8[0..utf8.len() - 2]
|
&output[0..output.len() - 1]
|
||||||
} else {
|
} else {
|
||||||
utf8
|
output
|
||||||
}
|
}
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
),
|
),
|
||||||
|
17
tests/backticks.rs
Normal file
17
tests/backticks.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn trailing_newlines_are_stripped() {
|
||||||
|
Test::new()
|
||||||
|
.shell(false)
|
||||||
|
.args(["--evaluate", "foos"])
|
||||||
|
.justfile(
|
||||||
|
"
|
||||||
|
set shell := ['python3', '-c']
|
||||||
|
|
||||||
|
foos := `print('foo' * 4)`
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.stdout("foofoofoofoo")
|
||||||
|
.run();
|
||||||
|
}
|
@ -36,6 +36,7 @@ mod allow_duplicate_recipes;
|
|||||||
mod assert_stdout;
|
mod assert_stdout;
|
||||||
mod assert_success;
|
mod assert_success;
|
||||||
mod attributes;
|
mod attributes;
|
||||||
|
mod backticks;
|
||||||
mod byte_order_mark;
|
mod byte_order_mark;
|
||||||
mod changelog;
|
mod changelog;
|
||||||
mod choose;
|
mod choose;
|
||||||
|
Loading…
Reference in New Issue
Block a user