Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Commit 230ecac

Browse files
committed
feat(output): Support byte predicates
If you pass a `&str` into the predicates, the programs output is assumed to be UTF-8 and will be converted accordingly. If you pass `&[u8]` into the predicates, the program output is treated as raw binary. Fixes #80
1 parent 67d2f6d commit 230ecac

File tree

2 files changed

+157
-57
lines changed

2 files changed

+157
-57
lines changed

src/assert.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
use environment::Environment;
2-
use error_chain::ChainedError;
3-
use errors::*;
4-
use output::{Output, OutputKind, OutputPredicate};
51
use std::default;
62
use std::ffi::{OsStr, OsString};
73
use std::io::Write;
84
use std::path::PathBuf;
95
use std::process::{Command, Stdio};
106
use std::vec::Vec;
117

8+
use environment::Environment;
9+
use error_chain::ChainedError;
10+
11+
use errors::*;
12+
use output::{Content, Output, OutputKind, OutputPredicate};
13+
1214
/// Assertions for a specific command.
1315
#[derive(Debug)]
1416
#[must_use]
@@ -375,7 +377,7 @@ impl Assert {
375377

376378
self.expect_output
377379
.iter()
378-
.map(|a| a.verify_output(&output).chain_err(|| ErrorKind::AssertionFailed(self.cmd.clone())))
380+
.map(|a| a.verify(&output).chain_err(|| ErrorKind::AssertionFailed(self.cmd.clone())))
379381
.collect::<Result<Vec<()>>>()?;
380382

381383
Ok(())
@@ -419,7 +421,7 @@ impl OutputAssertionBuilder {
419421
/// .stdout().contains("42")
420422
/// .unwrap();
421423
/// ```
422-
pub fn contains<O: Into<String>>(mut self, output: O) -> Assert {
424+
pub fn contains<O: Into<Content>>(mut self, output: O) -> Assert {
423425
let pred = OutputPredicate::new(self.kind, Output::contains(output));
424426
self.assertion.expect_output.push(pred);
425427
self.assertion
@@ -436,7 +438,7 @@ impl OutputAssertionBuilder {
436438
/// .stdout().is("42")
437439
/// .unwrap();
438440
/// ```
439-
pub fn is<O: Into<String>>(mut self, output: O) -> Assert {
441+
pub fn is<O: Into<Content>>(mut self, output: O) -> Assert {
440442
let pred = OutputPredicate::new(self.kind, Output::is(output));
441443
self.assertion.expect_output.push(pred);
442444
self.assertion
@@ -453,7 +455,7 @@ impl OutputAssertionBuilder {
453455
/// .stdout().doesnt_contain("73")
454456
/// .unwrap();
455457
/// ```
456-
pub fn doesnt_contain<O: Into<String>>(mut self, output: O) -> Assert {
458+
pub fn doesnt_contain<O: Into<Content>>(mut self, output: O) -> Assert {
457459
let pred = OutputPredicate::new(self.kind, Output::doesnt_contain(output));
458460
self.assertion.expect_output.push(pred);
459461
self.assertion
@@ -470,7 +472,7 @@ impl OutputAssertionBuilder {
470472
/// .stdout().isnt("73")
471473
/// .unwrap();
472474
/// ```
473-
pub fn isnt<O: Into<String>>(mut self, output: O) -> Assert {
475+
pub fn isnt<O: Into<Content>>(mut self, output: O) -> Assert {
474476
let pred = OutputPredicate::new(self.kind, Output::isnt(output));
475477
self.assertion.expect_output.push(pred);
476478
self.assertion

0 commit comments

Comments
 (0)