2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for whether or not warnings are displayed for build scripts.
|
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::registry::Package;
|
|
|
|
use cargo_test_support::{project, Project};
|
2017-03-19 02:33:09 +00:00
|
|
|
|
2019-07-14 22:19:33 +00:00
|
|
|
static WARNING1: &str = "Hello! I'm a warning. :)";
|
|
|
|
static WARNING2: &str = "And one more!";
|
2017-03-19 02:33:09 +00:00
|
|
|
|
|
|
|
fn make_lib(lib_src: &str) {
|
2018-07-20 17:41:44 +00:00
|
|
|
Package::new("bar", "0.0.1")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
authors = []
|
|
|
|
version = "0.0.1"
|
|
|
|
build = "build.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"build.rs",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {{
|
|
|
|
use std::io::Write;
|
2023-06-11 08:02:03 +00:00
|
|
|
println!("cargo::warning={{}}", "{}");
|
2020-09-27 00:59:58 +00:00
|
|
|
println!("hidden stdout");
|
|
|
|
write!(&mut ::std::io::stderr(), "hidden stderr");
|
2023-06-11 08:02:03 +00:00
|
|
|
println!("cargo::warning={{}}", "{}");
|
2020-09-27 00:59:58 +00:00
|
|
|
}}
|
|
|
|
"#,
|
2018-03-14 15:17:44 +00:00
|
|
|
WARNING1, WARNING2
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", &format!("fn f() {{ {} }}", lib_src))
|
2017-03-19 02:33:09 +00:00
|
|
|
.publish();
|
|
|
|
}
|
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
fn make_upstream(main_src: &str) -> Project {
|
2018-07-20 17:41:44 +00:00
|
|
|
project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2017-03-19 02:33:09 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = "*"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", &format!("fn main() {{ {} }}", main_src))
|
2017-07-22 03:12:21 +00:00
|
|
|
.build()
|
2017-03-19 02:33:09 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-03-19 02:33:09 +00:00
|
|
|
fn no_warning_on_success() {
|
|
|
|
make_lib("");
|
|
|
|
let upstream = make_upstream("");
|
2018-08-28 09:20:03 +00:00
|
|
|
upstream
|
|
|
|
.cargo("build")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 09:23:57 +00:00
|
|
|
[UPDATING] `[..]` index
|
2018-09-14 20:33:18 +00:00
|
|
|
[DOWNLOADING] crates ...
|
|
|
|
[DOWNLOADED] bar v0.0.1 ([..])
|
2018-07-20 17:41:44 +00:00
|
|
|
[COMPILING] bar v0.0.1
|
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-03-19 02:33:09 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-03-19 02:33:09 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-03-19 02:33:09 +00:00
|
|
|
fn no_warning_on_bin_failure() {
|
|
|
|
make_lib("");
|
|
|
|
let upstream = make_upstream("hi()");
|
2018-08-28 09:20:03 +00:00
|
|
|
upstream
|
|
|
|
.cargo("build")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stdout_does_not_contain("hidden stdout")
|
|
|
|
.with_stderr_does_not_contain("hidden stderr")
|
|
|
|
.with_stderr_does_not_contain(&format!("[WARNING] {}", WARNING1))
|
|
|
|
.with_stderr_does_not_contain(&format!("[WARNING] {}", WARNING2))
|
2018-09-08 09:23:57 +00:00
|
|
|
.with_stderr_contains("[UPDATING] `[..]` index")
|
2018-09-14 20:33:18 +00:00
|
|
|
.with_stderr_contains("[DOWNLOADED] bar v0.0.1 ([..])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[COMPILING] bar v0.0.1")
|
|
|
|
.with_stderr_contains("[COMPILING] foo v0.0.1 ([..])")
|
|
|
|
.run();
|
2017-03-19 02:33:09 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-03-19 02:33:09 +00:00
|
|
|
fn warning_on_lib_failure() {
|
|
|
|
make_lib("err()");
|
|
|
|
let upstream = make_upstream("");
|
2018-08-28 09:20:03 +00:00
|
|
|
upstream
|
|
|
|
.cargo("build")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stdout_does_not_contain("hidden stdout")
|
|
|
|
.with_stderr_does_not_contain("hidden stderr")
|
|
|
|
.with_stderr_does_not_contain("[COMPILING] foo v0.0.1 ([..])")
|
2018-09-08 09:23:57 +00:00
|
|
|
.with_stderr_contains("[UPDATING] `[..]` index")
|
2018-09-14 20:33:18 +00:00
|
|
|
.with_stderr_contains("[DOWNLOADED] bar v0.0.1 ([..])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[COMPILING] bar v0.0.1")
|
2023-10-10 01:41:18 +00:00
|
|
|
.with_stderr_contains(&format!("[WARNING] bar@0.0.1: {}", WARNING1))
|
|
|
|
.with_stderr_contains(&format!("[WARNING] bar@0.0.1: {}", WARNING2))
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-03-19 02:33:09 +00:00
|
|
|
}
|