cargo/tests/testsuite/build_lib.rs
Alex Crichton 2a063798eb Drop outdated hamcrest dependency
This hasn't been updated in awhile and in general we've been barely using it.
This drops the outdated dependency and vendors a small amount of the
functionality that it provided. I think eventually we'll want to transition away
from this method of assertions but I wanted to get this piece in to avoid too
much churn in one commit.
2018-03-01 11:03:54 -08:00

86 lines
2.2 KiB
Rust

use cargotest::support::{basic_bin_manifest, execs, project, Project};
use hamcrest::{assert_that};
fn verbose_output_for_lib(p: &Project) -> String {
format!("\
[COMPILING] {name} v{version} ({url})
[RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
dir = p.root().display(), url = p.url(),
name = "foo", version = "0.0.1")
}
#[test]
fn build_lib_only() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = ["wycats@example.com"]
"#)
.file("src/main.rs", r#"
fn main() {}
"#)
.file("src/lib.rs", r#" "#)
.build();
assert_that(p.cargo("build").arg("--lib").arg("-v"),
execs()
.with_status(0)
.with_stderr(verbose_output_for_lib(&p)));
}
#[test]
fn build_with_no_lib() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", r#"
fn main() {}
"#)
.build();
assert_that(p.cargo("build").arg("--lib"),
execs().with_status(101)
.with_stderr("[ERROR] no library targets found"));
}
#[test]
fn build_with_relative_cargo_home_path() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = ["wycats@example.com"]
[dependencies]
"test-dependency" = { path = "src/test_dependency" }
"#)
.file("src/main.rs", r#"
fn main() {}
"#)
.file("src/test_dependency/src/lib.rs", r#" "#)
.file("src/test_dependency/Cargo.toml", r#"
[package]
name = "test-dependency"
version = "0.0.1"
authors = ["wycats@example.com"]
"#)
.build();
assert_that(p.cargo("build").env("CARGO_HOME", "./cargo_home/"),
execs()
.with_status(0));
}