2015-05-01 21:19:43 +00:00
|
|
|
use std::path::MAIN_SEPARATOR as SEP;
|
2015-12-17 18:10:59 +00:00
|
|
|
|
2015-05-02 22:49:58 +00:00
|
|
|
use support::{execs, project};
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2016-01-13 01:37:57 +00:00
|
|
|
use hamcrest::assert_that;
|
2015-05-01 21:19:43 +00:00
|
|
|
|
|
|
|
fn setup() {
|
|
|
|
}
|
|
|
|
|
2016-05-12 17:06:36 +00:00
|
|
|
const CARGO_RUSTC_ERROR: &'static str =
|
|
|
|
"[ERROR] extra arguments to `rustc` can only be passed to one target, consider filtering
|
|
|
|
the package by passing e.g. `--lib` or `--bin NAME` to specify a single target";
|
2015-05-06 10:08:43 +00:00
|
|
|
|
2015-05-01 21:19:43 +00:00
|
|
|
test!(build_lib_for_foo {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2015-05-02 22:49:58 +00:00
|
|
|
authors = []
|
2015-05-01 21:19:43 +00:00
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#" "#);
|
|
|
|
|
2015-05-02 10:19:55 +00:00
|
|
|
assert_that(p.cargo_process("rustc").arg("--lib").arg("-v"),
|
2015-05-01 21:19:43 +00:00
|
|
|
execs()
|
|
|
|
.with_status(0)
|
2016-05-15 21:17:56 +00:00
|
|
|
.with_stderr(format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({url})
|
|
|
|
[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
|
2015-05-02 22:49:58 +00:00
|
|
|
--out-dir {dir}{sep}target{sep}debug \
|
|
|
|
--emit=dep-info,link \
|
|
|
|
-L dependency={dir}{sep}target{sep}debug \
|
|
|
|
-L dependency={dir}{sep}target{sep}debug{sep}deps`
|
2016-05-11 16:55:43 +00:00
|
|
|
", sep = SEP,
|
2015-05-02 22:49:58 +00:00
|
|
|
dir = p.root().display(), url = p.url())));
|
2015-05-01 23:01:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test!(build_lib_and_allow_unstable_options {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2015-05-02 22:49:58 +00:00
|
|
|
authors = []
|
2015-05-01 23:01:30 +00:00
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#" "#);
|
|
|
|
|
2015-05-02 10:19:55 +00:00
|
|
|
assert_that(p.cargo_process("rustc").arg("--lib").arg("-v")
|
2015-05-01 23:01:30 +00:00
|
|
|
.arg("--").arg("-Z").arg("unstable-options"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
2016-05-15 21:17:56 +00:00
|
|
|
.with_stderr(format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({url})
|
|
|
|
[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
|
2015-05-02 22:49:58 +00:00
|
|
|
-Z unstable-options \
|
|
|
|
--out-dir {dir}{sep}target{sep}debug \
|
|
|
|
--emit=dep-info,link \
|
|
|
|
-L dependency={dir}{sep}target{sep}debug \
|
|
|
|
-L dependency={dir}{sep}target{sep}debug{sep}deps`
|
2016-05-11 16:55:43 +00:00
|
|
|
", sep = SEP,
|
2015-05-02 22:49:58 +00:00
|
|
|
dir = p.root().display(), url = p.url())))
|
2015-05-01 23:01:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test!(build_main_and_allow_unstable_options {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2015-05-02 22:49:58 +00:00
|
|
|
authors = []
|
2015-05-01 23:01:30 +00:00
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
2015-05-02 16:18:05 +00:00
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#" "#);
|
2015-05-01 23:01:30 +00:00
|
|
|
|
2015-05-02 16:18:05 +00:00
|
|
|
assert_that(p.cargo_process("rustc").arg("-v").arg("--bin").arg("foo")
|
2015-05-01 23:01:30 +00:00
|
|
|
.arg("--").arg("-Z").arg("unstable-options"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
2016-05-15 21:26:24 +00:00
|
|
|
.with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] {name} v{version} ({url})
|
|
|
|
[RUNNING] `rustc src{sep}lib.rs --crate-name {name} --crate-type lib -g \
|
2015-05-02 16:18:05 +00:00
|
|
|
--out-dir {dir}{sep}target{sep}debug \
|
|
|
|
--emit=dep-info,link \
|
|
|
|
-L dependency={dir}{sep}target{sep}debug \
|
|
|
|
-L dependency={dir}{sep}target{sep}debug{sep}deps`
|
2016-05-11 16:55:43 +00:00
|
|
|
[RUNNING] `rustc src{sep}main.rs --crate-name {name} --crate-type bin -g \
|
2015-05-02 16:18:05 +00:00
|
|
|
-Z unstable-options \
|
|
|
|
--out-dir {dir}{sep}target{sep}debug \
|
|
|
|
--emit=dep-info,link \
|
|
|
|
-L dependency={dir}{sep}target{sep}debug \
|
|
|
|
-L dependency={dir}{sep}target{sep}debug{sep}deps \
|
|
|
|
--extern {name}={dir}{sep}target{sep}debug{sep}lib{name}.rlib`
|
2016-05-11 16:55:43 +00:00
|
|
|
", sep = SEP,
|
2015-05-02 16:18:05 +00:00
|
|
|
dir = p.root().display(), url = p.url(),
|
|
|
|
name = "foo", version = "0.0.1")));
|
2015-05-01 21:19:43 +00:00
|
|
|
});
|
2015-05-02 14:30:16 +00:00
|
|
|
|
|
|
|
test!(fails_when_trying_to_build_main_and_lib_with_args {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2015-05-02 22:49:58 +00:00
|
|
|
authors = []
|
2015-05-02 14:30:16 +00:00
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#" "#);
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("rustc").arg("-v")
|
|
|
|
.arg("--").arg("-Z").arg("unstable-options"),
|
|
|
|
execs()
|
|
|
|
.with_status(101)
|
2016-05-12 17:06:36 +00:00
|
|
|
.with_stderr(CARGO_RUSTC_ERROR));
|
2015-05-02 14:30:16 +00:00
|
|
|
});
|
2015-05-02 23:11:46 +00:00
|
|
|
|
|
|
|
test!(build_with_args_to_one_of_multiple_binaries {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/bin/foo.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/bin/bar.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/bin/baz.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#" "#);
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("rustc").arg("-v").arg("--bin").arg("bar")
|
|
|
|
.arg("--").arg("-Z").arg("unstable-options"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
2016-05-15 21:26:24 +00:00
|
|
|
.with_stderr(format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({url})
|
|
|
|
[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
|
2015-05-02 23:11:46 +00:00
|
|
|
--out-dir {dir}{sep}target{sep}debug [..]`
|
2016-05-11 16:55:43 +00:00
|
|
|
[RUNNING] `rustc src{sep}bin{sep}bar.rs --crate-name bar --crate-type bin -g \
|
2015-05-02 23:11:46 +00:00
|
|
|
-Z unstable-options [..]`
|
2016-05-11 16:55:43 +00:00
|
|
|
", sep = SEP,
|
2015-05-02 23:11:46 +00:00
|
|
|
dir = p.root().display(), url = p.url())));
|
|
|
|
});
|
|
|
|
|
|
|
|
test!(fails_with_args_to_all_binaries {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/bin/foo.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/bin/bar.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/bin/baz.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#" "#);
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("rustc").arg("-v")
|
|
|
|
.arg("--").arg("-Z").arg("unstable-options"),
|
|
|
|
execs()
|
|
|
|
.with_status(101)
|
2016-05-12 17:06:36 +00:00
|
|
|
.with_stderr(CARGO_RUSTC_ERROR));
|
2015-05-02 23:11:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test!(build_with_args_to_one_of_multiple_tests {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("tests/foo.rs", r#" "#)
|
|
|
|
.file("tests/bar.rs", r#" "#)
|
|
|
|
.file("tests/baz.rs", r#" "#)
|
|
|
|
.file("src/lib.rs", r#" "#);
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("rustc").arg("-v").arg("--test").arg("bar")
|
|
|
|
.arg("--").arg("-Z").arg("unstable-options"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
2016-05-15 21:26:24 +00:00
|
|
|
.with_stderr(format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({url})
|
|
|
|
[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
|
2015-05-02 23:11:46 +00:00
|
|
|
--out-dir {dir}{sep}target{sep}debug [..]`
|
2016-05-11 16:55:43 +00:00
|
|
|
[RUNNING] `rustc tests{sep}bar.rs --crate-name bar --crate-type bin -g \
|
2015-05-02 23:11:46 +00:00
|
|
|
-Z unstable-options [..]--test[..]`
|
2016-05-11 16:55:43 +00:00
|
|
|
", sep = SEP,
|
2015-05-02 23:11:46 +00:00
|
|
|
dir = p.root().display(), url = p.url())));
|
|
|
|
});
|
|
|
|
|
|
|
|
test!(build_foo_with_bar_dependency {
|
|
|
|
let foo = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
extern crate bar;
|
|
|
|
fn main() {
|
|
|
|
bar::baz()
|
|
|
|
}
|
|
|
|
"#);
|
|
|
|
let bar = project("bar")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
pub fn baz() {}
|
|
|
|
"#);
|
|
|
|
bar.build();
|
|
|
|
|
|
|
|
assert_that(foo.cargo_process("rustc").arg("-v").arg("--").arg("-Z").arg("unstable-options"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
2016-05-15 21:17:56 +00:00
|
|
|
.with_stderr(format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] bar v0.1.0 ([..])
|
|
|
|
[RUNNING] `[..] -g -C [..]`
|
|
|
|
[COMPILING] foo v0.0.1 ({url})
|
|
|
|
[RUNNING] `[..] -g -Z unstable-options [..]`
|
2015-05-02 23:11:46 +00:00
|
|
|
",
|
|
|
|
url = foo.url())));
|
|
|
|
});
|
|
|
|
|
|
|
|
test!(build_only_bar_dependency {
|
|
|
|
let foo = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
extern crate bar;
|
|
|
|
fn main() {
|
|
|
|
bar::baz()
|
|
|
|
}
|
|
|
|
"#);
|
|
|
|
let bar = project("bar")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
pub fn baz() {}
|
|
|
|
"#);
|
|
|
|
bar.build();
|
|
|
|
|
|
|
|
assert_that(foo.cargo_process("rustc").arg("-v").arg("-p").arg("bar")
|
|
|
|
.arg("--").arg("-Z").arg("unstable-options"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
2016-05-14 21:15:22 +00:00
|
|
|
.with_stderr("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] bar v0.1.0 ([..])
|
|
|
|
[RUNNING] `[..]--crate-name bar --crate-type lib [..] -Z unstable-options [..]`
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2015-05-02 23:11:46 +00:00
|
|
|
});
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2015-09-15 23:02:37 +00:00
|
|
|
test!(fail_with_multiple_packages {
|
2015-09-12 21:32:35 +00:00
|
|
|
let foo = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
|
|
|
|
|
|
|
[dependencies.baz]
|
|
|
|
path = "../baz"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#);
|
|
|
|
foo.build();
|
2015-09-15 23:02:37 +00:00
|
|
|
|
2015-09-12 21:32:35 +00:00
|
|
|
let bar = project("bar")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {
|
|
|
|
if cfg!(flag = "1") { println!("Yeah from bar!"); }
|
|
|
|
}
|
|
|
|
"#);
|
|
|
|
bar.build();
|
2015-09-15 23:02:37 +00:00
|
|
|
|
2015-09-12 21:32:35 +00:00
|
|
|
let baz = project("baz")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "baz"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {
|
|
|
|
if cfg!(flag = "1") { println!("Yeah from baz!"); }
|
|
|
|
}
|
|
|
|
"#);
|
|
|
|
baz.build();
|
|
|
|
|
2015-09-15 23:02:37 +00:00
|
|
|
assert_that(foo.cargo("rustc").arg("-v").arg("-p").arg("bar")
|
|
|
|
.arg("-p").arg("baz"),
|
2016-05-12 17:06:36 +00:00
|
|
|
execs().with_status(1).with_stderr("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] Invalid arguments.
|
2015-09-12 21:32:35 +00:00
|
|
|
|
2015-09-15 23:02:37 +00:00
|
|
|
Usage:
|
2016-05-12 17:06:36 +00:00
|
|
|
cargo rustc [options] [--] [<opts>...]"));
|
2015-09-12 21:32:35 +00:00
|
|
|
});
|
2015-12-17 18:10:59 +00:00
|
|
|
|
|
|
|
test!(rustc_with_other_profile {
|
|
|
|
let foo = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
a = { path = "a" }
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
#[cfg(test)] extern crate a;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn foo() {}
|
|
|
|
"#)
|
|
|
|
.file("a/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("a/src/lib.rs", "");
|
|
|
|
foo.build();
|
|
|
|
|
|
|
|
assert_that(foo.cargo("rustc").arg("--profile").arg("test"),
|
|
|
|
execs().with_status(0));
|
|
|
|
});
|