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

Commit d3daabb

Browse files
authored
Merge pull request #97 from azriel91/feature/86/run-using-active-compilation-profile
Feature/86/run using active compilation profile
2 parents 712c738 + 141f59e commit d3daabb

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

src/assert.rs

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ impl default::Default for Assert {
3131
/// Defaults to asserting _successful_ execution.
3232
fn default() -> Self {
3333
Assert {
34-
cmd: vec!["cargo", "run", "--quiet", "--"]
35-
.into_iter()
34+
cmd: vec![
35+
"cargo",
36+
"run",
37+
#[cfg(not(debug_assertions))]
38+
"--release",
39+
"--quiet",
40+
"--",
41+
].into_iter()
3642
.map(OsString::from)
3743
.collect(),
3844
env: Environment::inherit(),
@@ -61,6 +67,8 @@ impl Assert {
6167
cmd: vec![
6268
OsStr::new("cargo"),
6369
OsStr::new("run"),
70+
#[cfg(not(debug_assertions))]
71+
OsStr::new("--release"),
6472
OsStr::new("--quiet"),
6573
OsStr::new("--bin"),
6674
name.as_ref(),
@@ -530,6 +538,52 @@ mod test {
530538
Assert::command(&["printenv"])
531539
}
532540

541+
#[test]
542+
fn main_binary_default_uses_active_profile() {
543+
let assert = Assert::main_binary();
544+
545+
let expected = if cfg!(debug_assertions) {
546+
OsString::from("cargo run --quiet -- ")
547+
} else {
548+
OsString::from("cargo run --release --quiet -- ")
549+
};
550+
551+
assert_eq!(
552+
expected,
553+
assert
554+
.cmd
555+
.into_iter()
556+
.fold(OsString::from(""), |mut cmd, token| {
557+
cmd.push(token);
558+
cmd.push(" ");
559+
cmd
560+
})
561+
);
562+
}
563+
564+
#[test]
565+
fn cargo_binary_default_uses_active_profile() {
566+
let assert = Assert::cargo_binary("hello");
567+
568+
let expected = if cfg!(debug_assertions) {
569+
OsString::from("cargo run --quiet --bin hello -- ")
570+
} else {
571+
OsString::from("cargo run --release --quiet --bin hello -- ")
572+
};
573+
574+
assert_eq!(
575+
expected,
576+
assert
577+
.cmd
578+
.into_iter()
579+
.fold(OsString::from(""), |mut cmd, token| {
580+
cmd.push(token);
581+
cmd.push(" ");
582+
cmd
583+
})
584+
);
585+
}
586+
533587
#[test]
534588
fn take_ownership() {
535589
let x = Environment::inherit();

src/bin/assert_fixture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
extern crate failure;
22

3+
use std::env;
34
use std::io;
45
use std::io::Write;
5-
use std::env;
66
use std::process;
77

88
use failure::ResultExt;

src/output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::rc;
55
use difference::Changeset;
66
use failure;
77

8-
use errors::*;
98
use diff;
9+
use errors::*;
1010

1111
#[derive(Clone, PartialEq, Eq)]
1212
pub enum Content {

0 commit comments

Comments
 (0)