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

Commit

Permalink
Merge pull request #97 from azriel91/feature/86/run-using-active-comp…
Browse files Browse the repository at this point in the history
…ilation-profile

Feature/86/run using active compilation profile
  • Loading branch information
epage authored Mar 27, 2018
2 parents 712c738 + 141f59e commit d3daabb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
58 changes: 56 additions & 2 deletions src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ impl default::Default for Assert {
/// Defaults to asserting _successful_ execution.
fn default() -> Self {
Assert {
cmd: vec!["cargo", "run", "--quiet", "--"]
.into_iter()
cmd: vec![
"cargo",
"run",
#[cfg(not(debug_assertions))]
"--release",
"--quiet",
"--",
].into_iter()
.map(OsString::from)
.collect(),
env: Environment::inherit(),
Expand Down Expand Up @@ -61,6 +67,8 @@ impl Assert {
cmd: vec![
OsStr::new("cargo"),
OsStr::new("run"),
#[cfg(not(debug_assertions))]
OsStr::new("--release"),
OsStr::new("--quiet"),
OsStr::new("--bin"),
name.as_ref(),
Expand Down Expand Up @@ -530,6 +538,52 @@ mod test {
Assert::command(&["printenv"])
}

#[test]
fn main_binary_default_uses_active_profile() {
let assert = Assert::main_binary();

let expected = if cfg!(debug_assertions) {
OsString::from("cargo run --quiet -- ")
} else {
OsString::from("cargo run --release --quiet -- ")
};

assert_eq!(
expected,
assert
.cmd
.into_iter()
.fold(OsString::from(""), |mut cmd, token| {
cmd.push(token);
cmd.push(" ");
cmd
})
);
}

#[test]
fn cargo_binary_default_uses_active_profile() {
let assert = Assert::cargo_binary("hello");

let expected = if cfg!(debug_assertions) {
OsString::from("cargo run --quiet --bin hello -- ")
} else {
OsString::from("cargo run --release --quiet --bin hello -- ")
};

assert_eq!(
expected,
assert
.cmd
.into_iter()
.fold(OsString::from(""), |mut cmd, token| {
cmd.push(token);
cmd.push(" ");
cmd
})
);
}

#[test]
fn take_ownership() {
let x = Environment::inherit();
Expand Down
2 changes: 1 addition & 1 deletion src/bin/assert_fixture.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extern crate failure;

use std::env;
use std::io;
use std::io::Write;
use std::env;
use std::process;

use failure::ResultExt;
Expand Down
2 changes: 1 addition & 1 deletion src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::rc;
use difference::Changeset;
use failure;

use errors::*;
use diff;
use errors::*;

#[derive(Clone, PartialEq, Eq)]
pub enum Content {
Expand Down

0 comments on commit d3daabb

Please sign in to comment.