1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
// Copyright (c) 2018 Toby Smith <toby@tismith.id.au>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/license/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate assert_cmd;
extern crate predicates;
use assert_cmd::prelude::*;
use predicates::prelude::*;
fn get_cwd() -> String {
std::env::current_dir()
.unwrap()
.to_str()
.unwrap()
.to_string()
}
macro_rules! test_body {
($name:expr, $matcher:expr) => {
let bin = format!("{}/target/debug/examples/{}", get_cwd(), $name);
let pred = predicates::str::contains($matcher).from_utf8();
std::process::Command::new(&bin)
.assert()
.failure()
.stderr(pred);
};
($name:expr) => {
test_body!(
$name,
"Error: this is some context\nInfo: caused by root cause failure"
)
};
}
#[test]
fn test_example() {
test_body!("example");
}
#[test]
fn test_context() {
test_body!("context");
}
#[test]
fn test_display() {
test_body!("display", "Error: this is an error message");
}
#[test]
fn test_no_backtrace() {
let bin = format!("{}/target/debug/examples/example", get_cwd());
let pred = predicates::str::contains("stack backtrace").from_utf8();
std::process::Command::new(&bin)
.env_remove("RUST_BACKTRACE")
.assert()
.failure()
.stderr(pred.not());
}
#[test]
fn test_backtrace() {
let bin = format!("{}/target/debug/examples/example", get_cwd());
let pred = predicates::str::contains("stack backtrace").from_utf8();
std::process::Command::new(&bin)
.env("RUST_BACKTRACE", "1")
.assert()
.failure()
.stderr(pred);
}
|