diff --git a/src/output.rs b/src/output.rs index af8ec6a..f9f4ab0 100644 --- a/src/output.rs +++ b/src/output.rs @@ -17,13 +17,13 @@ pub(crate) fn output(mut command: Command) -> Result { } match str::from_utf8(&output.stdout) { Err(error) => Err(OutputError::Utf8(error)), - Ok(utf8) => Ok( - if utf8.ends_with('\n') { - &utf8[0..utf8.len() - 1] - } else if utf8.ends_with("\r\n") { - &utf8[0..utf8.len() - 2] + Ok(output) => Ok( + if output.ends_with("\r\n") { + &output[0..output.len() - 2] + } else if output.ends_with('\n') { + &output[0..output.len() - 1] } else { - utf8 + output } .to_owned(), ), diff --git a/tests/backticks.rs b/tests/backticks.rs new file mode 100644 index 0000000..026cfbf --- /dev/null +++ b/tests/backticks.rs @@ -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(); +} diff --git a/tests/lib.rs b/tests/lib.rs index b501b7e..bcd1b1a 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -36,6 +36,7 @@ mod allow_duplicate_recipes; mod assert_stdout; mod assert_success; mod attributes; +mod backticks; mod byte_order_mark; mod changelog; mod choose;