Adding release flag to cargo test

This commit is contained in:
Prabhjyot Singh Sodhi 2015-03-25 02:13:30 +05:30
parent 3499c8ec8e
commit 1f99ed0b6a
2 changed files with 51 additions and 1 deletions

View file

@ -15,6 +15,7 @@ struct Options {
flag_package: Option<String>,
flag_target: Option<String>,
flag_verbose: bool,
flag_release: bool,
}
pub const USAGE: &'static str = "
@ -30,6 +31,7 @@ Options:
--no-run Compile, but don't run tests
-p SPEC, --package SPEC Package to run tests for
-j N, --jobs N The number of jobs to run in parallel
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
@ -72,7 +74,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| &s[..]),
exec_engine: None,
release: false,
release: options.flag_release,
mode: ops::CompileMode::Test,
filter: if tests.is_empty() && bins.is_empty() {
ops::CompileFilter::Everything

View file

@ -46,6 +46,54 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
RUNNING)));
});
test!(cargo_test_release {
let p = project("foo")
.file("src/lib.rs", r#"
extern crate bar as the_bar;
pub fn bar() { the_bar::baz(); }
#[test]
fn foo() { bar(); }
"#)
.file("tests/test.rs", r#"
extern crate foo as the_foo;
#[test]
fn foo() { the_foo::bar(); }
"#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[lib]
name = "bar"
crate_type = ["dylib"]
"#)
.file("bar/src/lib.rs", "
pub fn baz() {}
");
assert_that(p.cargo_process("test").arg("-v").arg("--release"),
execs().with_stdout(format!("\
{compiling} bar v0.0.1 ({dir})
{running} [..] -C opt-level=3 [..]
{compiling} foo v0.0.1 ({dir})
{running} [..] -C opt-level=3 [..]
{running} [..] -C opt-level=3 [..]
{running} `[..]target[..]foo-[..]`
running 1 test
test test_hello ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
",
compiling = COMPILING, dir = p.url(), running = RUNNING)));
});
test!(cargo_test_verbose {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))