assert_that(process(&p.bin("foo")),
execs().with_stdout("hello\n"));
- assert_that(p.cargo("bench"),
+ // Force libtest into serial execution so that the test header will be printed.
+ assert_that(p.cargo("bench").arg("--").arg("--test-threads=1"),
execs().with_stdout_contains("test bench_hello ... ")
- .with_stderr_contains(format!("\
+ .with_either_contains(format!("\
[COMPILING] foo v0.5.0 ({})
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target[/]release[/]deps[/]foo-[..][EXE]
thread '[..]' panicked at 'assertion failed: \
`(left == right)`[..]", p.url()))
- .with_stderr_contains("[..]left: `\"hello\"`[..]")
- .with_stderr_contains("[..]right: `\"nope\"`[..]")
- .with_stderr_contains("[..]src[/]main.rs:15[..]")
+ .with_either_contains("[..]left: `\"hello\"`[..]")
+ .with_either_contains("[..]right: `\"nope\"`[..]")
+ .with_either_contains("[..]src[/]main.rs:15[..]")
.with_status(101));
}
}"#)
.build();
- assert_that(p.cargo("bench").arg("--no-fail-fast"),
+ assert_that(p.cargo("bench").arg("--no-fail-fast").arg("--").arg("--test-threads=1"),
execs().with_status(101)
.with_stderr_contains("\
[RUNNING] target[/]release[/]deps[/]foo-[..][EXE]")
expect_exit_code: Option<i32>,
expect_stdout_contains: Vec<String>,
expect_stderr_contains: Vec<String>,
+ expect_either_contains: Vec<String>,
expect_stdout_contains_n: Vec<(String, usize)>,
expect_stdout_not_contains: Vec<String>,
expect_stderr_not_contains: Vec<String>,
+ expect_neither_contains: Vec<String>,
expect_json: Option<Vec<Value>>,
}
self
}
+ pub fn with_either_contains<S: ToString>(mut self, expected: S) -> Execs {
+ self.expect_either_contains.push(expected.to_string());
+ self
+ }
+
pub fn with_stdout_contains_n<S: ToString>(mut self, expected: S, number: usize) -> Execs {
self.expect_stdout_contains_n.push((expected.to_string(), number));
self
self
}
+ pub fn with_neither_contains<S: ToString>(mut self, expected: S) -> Execs {
+ self.expect_neither_contains.push(expected.to_string());
+ self
+ }
+
pub fn with_json(mut self, expected: &str) -> Execs {
self.expect_json = Some(expected.split("\n\n").map(|obj| {
obj.parse().unwrap()
self.match_std(Some(expect), &actual.stderr, "stderr",
&actual.stdout, MatchKind::NotPresent)?;
}
+ for expect in self.expect_neither_contains.iter() {
+ self.match_std(Some(expect), &actual.stdout, "stdout",
+ &actual.stdout, MatchKind::NotPresent)?;
+
+ self.match_std(Some(expect), &actual.stderr, "stderr",
+ &actual.stderr, MatchKind::NotPresent)?;
+ }
+
+ for expect in self.expect_either_contains.iter() {
+ let match_std = self.match_std(Some(expect), &actual.stdout, "stdout",
+ &actual.stdout, MatchKind::Partial);
+ let match_err = self.match_std(Some(expect), &actual.stderr, "stderr",
+ &actual.stderr, MatchKind::Partial);
+
+ if let (Err(_), Err(_)) = (match_std, match_err) {
+ Err(format!("expected to find:\n\
+ {}\n\n\
+ did not find in either output.", expect))?;
+ }
+ }
if let Some(ref objects) = self.expect_json {
let stdout = str::from_utf8(&actual.stdout)
expect_exit_code: None,
expect_stdout_contains: Vec::new(),
expect_stderr_contains: Vec::new(),
+ expect_either_contains: Vec::new(),
expect_stdout_contains_n: Vec::new(),
expect_stdout_not_contains: Vec::new(),
expect_stderr_not_contains: Vec::new(),
+ expect_neither_contains: Vec::new(),
expect_json: None,
}
}