This repository was archived by the owner on Dec 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
fix: Remove unrelated output in main_binary #50
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use environment::Environment; | ||
use error_chain::ChainedError; | ||
use errors::*; | ||
use output::{OutputAssertion, OutputKind}; | ||
use std::default; | ||
|
@@ -25,7 +26,7 @@ impl default::Default for Assert { | |
/// Defaults to asserting _successful_ execution. | ||
fn default() -> Self { | ||
Assert { | ||
cmd: vec!["cargo", "run", "--"] | ||
cmd: vec!["cargo", "run", "--quiet", "--"] | ||
.into_iter() | ||
.map(String::from) | ||
.collect(), | ||
|
@@ -52,7 +53,7 @@ impl Assert { | |
/// Defaults to asserting _successful_ execution. | ||
pub fn cargo_binary(name: &str) -> Self { | ||
Assert { | ||
cmd: vec!["cargo", "run", "--bin", name, "--"] | ||
cmd: vec!["cargo", "run", "--quiet", "--bin", name, "--"] | ||
.into_iter() | ||
.map(String::from) | ||
.collect(), | ||
|
@@ -332,7 +333,9 @@ impl Assert { | |
None => command, | ||
}; | ||
|
||
let mut spawned = command.spawn()?; | ||
let mut spawned = command | ||
.spawn() | ||
.chain_err(|| ErrorKind::SpawnFailed(self.cmd.clone()))?; | ||
|
||
if let Some(ref contents) = self.stdin_contents { | ||
spawned | ||
|
@@ -389,7 +392,7 @@ impl Assert { | |
/// ``` | ||
pub fn unwrap(self) { | ||
if let Err(err) = self.execute() { | ||
panic!("{}", err); | ||
panic!("{}", err.display_chain()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#[macro_use] | ||
extern crate error_chain; | ||
|
||
use std::env; | ||
use std::process; | ||
|
||
error_chain! { | ||
foreign_links { | ||
Env(env::VarError); | ||
ParseInt(std::num::ParseIntError); | ||
} | ||
} | ||
|
||
fn run() -> Result<()> { | ||
if let Ok(text) = env::var("stdout") { | ||
println!("{}", text); | ||
} | ||
if let Ok(text) = env::var("stderr") { | ||
eprintln!("{}", text); | ||
} | ||
|
||
let code = env::var("exit") | ||
.ok() | ||
.map(|v| v.parse::<i32>()) | ||
.map_or(Ok(None), |r| r.map(Some)) | ||
.chain_err(|| "Invalid exit code")? | ||
.unwrap_or(0); | ||
process::exit(code); | ||
} | ||
|
||
quick_main!(run); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
extern crate assert_cli; | ||
|
||
#[test] | ||
fn main_binary() { | ||
assert_cli::Assert::main_binary() | ||
.with_env(assert_cli::Environment::inherit().insert("stdout", "42")) | ||
.stdout() | ||
.is("42") | ||
.stderr() | ||
.is("") | ||
.unwrap(); | ||
} | ||
|
||
#[test] | ||
fn cargo_binary() { | ||
assert_cli::Assert::cargo_binary("assert_fixture") | ||
.with_env(assert_cli::Environment::inherit().insert("stdout", "42")) | ||
.stdout() | ||
.is("42") | ||
.stderr() | ||
.is("") | ||
.unwrap(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This binary is built only when building assert_cli itself, right? I.e., not when using it as a dependency. Is there any chance people might
cargo install
this? We could add ainternal-tests
feature and specifyrequired-features
for the bin. Or, can we add bins depending on cfg(test) in some other way?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've heard depending on something doesn't pull in the bins.
If they did, it wouldn't do them much good.
The problem with relying on features is
main_binary
can't enable the feature.