Skip to content

Commit 1de26fd

Browse files
committed
make failing test output useful
1 parent 27fa804 commit 1de26fd

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

tests/buildtest/runner.rs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,23 @@ macro_rules! test_prepare_error {
9595
rustwide::cmd::SandboxBuilder::new().enable_networking(false),
9696
|_| Ok(()),
9797
);
98-
if let Some(rustwide::PrepareError::$expected) =
99-
res.err().and_then(|err| err.downcast().ok())
100-
{
101-
// Everything is OK!
102-
} else {
103-
panic!("didn't get the error {}", stringify!($expected));
98+
match res.err().and_then(|err| err.downcast().ok()) {
99+
Some(rustwide::PrepareError::$expected) => {
100+
// Everything is OK!
101+
}
102+
Some(other) => {
103+
panic!(
104+
"expected PrepareError::{} error, got {:?} instead",
105+
stringify!($expected),
106+
other
107+
);
108+
}
109+
None => {
110+
panic!(
111+
"expected PrepareError::{} error, but did get None instead",
112+
stringify!($expected)
113+
);
114+
}
104115
}
105116
Ok(())
106117
});
@@ -117,12 +128,23 @@ macro_rules! test_prepare_error_stderr {
117128
rustwide::cmd::SandboxBuilder::new().enable_networking(false),
118129
|_| Ok(()),
119130
);
120-
if let Some(rustwide::PrepareError::$expected(output)) =
121-
res.err().and_then(|err| err.downcast().ok())
122-
{
123-
assert!(output.contains($expected_output), "output: {:?}", output);
124-
} else {
125-
panic!("didn't get the error {}", stringify!($expected));
131+
match res.err().and_then(|err| err.downcast().ok()) {
132+
Some(rustwide::PrepareError::$expected(output)) => {
133+
assert!(output.contains($expected_output), "output: {:?}", output);
134+
}
135+
Some(other) => {
136+
panic!(
137+
"expected PrepareError::{} error, got {:?} instead",
138+
stringify!($expected),
139+
other
140+
);
141+
}
142+
None => {
143+
panic!(
144+
"expected PrepareError::{} error, but did get None instead",
145+
stringify!($expected)
146+
);
147+
}
126148
}
127149
Ok(())
128150
});

0 commit comments

Comments
 (0)