Skip to content

Commit 21c3aa5

Browse files
committed
tests/runner.rs: use pretty-assertions crate
The workflow here involves looking for differences in output from the test programs between us and openssl. That is not very friendly because rust's default Debug format escapes newlines. Add a newtype for `Output` which doesn't do that.
1 parent 54d502a commit 21c3aa5

File tree

3 files changed

+66
-13
lines changed

3 files changed

+66
-13
lines changed

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ log = "0.4"
1515
openssl-probe = "0.1"
1616
openssl-sys = "0.9"
1717
rustls = "0.23.27"
18+
19+
[dev-dependencies]
20+
pretty_assertions = "1"

tests/runner.rs

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::io::Read;
2-
use std::ops::Add;
2+
use std::ops::{Add, Deref};
33
use std::process::{Child, Command, Output, Stdio};
44
use std::sync::atomic;
5-
use std::{fs, net, thread, time};
5+
use std::{fmt, fs, net, thread, time};
6+
7+
use pretty_assertions::assert_eq;
68

79
/* Note:
810
*
@@ -807,17 +809,42 @@ impl Drop for KillOnDrop {
807809
}
808810
}
809811

810-
fn print_output(out: Output) -> Output {
811-
println!("status: {:?}\n", out.status);
812-
println!(
813-
"stdout:\n{}\n",
814-
String::from_utf8(out.stdout.clone()).unwrap()
815-
);
816-
println!(
817-
"stderr:\n{}\n",
818-
String::from_utf8(out.stderr.clone()).unwrap()
819-
);
820-
out
812+
fn print_output(out: Output) -> PrettyOutput {
813+
let p = PrettyOutput(out);
814+
println!("output: {p:?}");
815+
p
816+
}
817+
818+
#[derive(PartialEq)]
819+
struct PrettyOutput(Output);
820+
821+
impl fmt::Debug for PrettyOutput {
822+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
823+
f.debug_struct("Output")
824+
.field("status", &self.0.status)
825+
.field("stdout", &"<follows>")
826+
.field("stderr", &"<follows>")
827+
.finish()?;
828+
829+
// ensure line endings in command output appear literally, so
830+
// pretty_assertions can make a nice diff.
831+
writeln!(f)?;
832+
for l in String::from_utf8(self.0.stdout.clone()).unwrap().lines() {
833+
writeln!(f, "stdout => {l}")?;
834+
}
835+
for l in String::from_utf8(self.0.stderr.clone()).unwrap().lines() {
836+
writeln!(f, "stderr => {l}")?;
837+
}
838+
Ok(())
839+
}
840+
}
841+
842+
impl Deref for PrettyOutput {
843+
type Target = Output;
844+
845+
fn deref(&self) -> &Self::Target {
846+
&self.0
847+
}
821848
}
822849

823850
/// Wait until we can connect to localhost:port.

0 commit comments

Comments
 (0)