Skip to content

Commit 9123040

Browse files
committed
test: cargo::error build script directive.
1 parent 4c603ef commit 9123040

File tree

1 file changed

+245
-6
lines changed

1 file changed

+245
-6
lines changed

tests/testsuite/build_script.rs

Lines changed: 245 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3871,14 +3871,105 @@ fn warnings_emitted() {
38713871
)
38723872
.build();
38733873

3874-
p.cargo("build -v")
3874+
p.cargo("build")
38753875
.with_stderr_data(str![[r#"
38763876
[COMPILING] foo v0.5.0 ([ROOT]/foo)
3877-
[RUNNING] `rustc --crate-name build_script_build [..]`
3878-
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
38793877
[WARNING] [email protected]: foo
38803878
[WARNING] [email protected]: bar
3881-
[RUNNING] `rustc --crate-name foo [..]`
3879+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3880+
3881+
"#]])
3882+
.run();
3883+
}
3884+
3885+
#[cargo_test]
3886+
fn errors_and_warnings_emitted_and_build_failed() {
3887+
let p = project()
3888+
.file(
3889+
"Cargo.toml",
3890+
r#"
3891+
[package]
3892+
name = "foo"
3893+
version = "0.5.0"
3894+
edition = "2015"
3895+
authors = []
3896+
build = "build.rs"
3897+
"#,
3898+
)
3899+
.file("src/lib.rs", "")
3900+
.file(
3901+
"build.rs",
3902+
r#"
3903+
fn main() {
3904+
println!("cargo::warning=foo");
3905+
println!("cargo::warning=bar");
3906+
println!("cargo::warning=foo err");
3907+
println!("cargo::warning=bar err");
3908+
}
3909+
"#,
3910+
)
3911+
.build();
3912+
3913+
p.cargo("build")
3914+
.with_stderr_data(str![[r#"
3915+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
3916+
[WARNING] [email protected]: foo
3917+
[WARNING] [email protected]: bar
3918+
[WARNING] [email protected]: foo err
3919+
[WARNING] [email protected]: bar err
3920+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3921+
3922+
"#]])
3923+
.run();
3924+
}
3925+
3926+
#[cargo_test]
3927+
fn warnings_emitted_from_path_dep() {
3928+
let p = project()
3929+
.file(
3930+
"Cargo.toml",
3931+
r#"
3932+
[package]
3933+
name = "foo"
3934+
version = "0.5.0"
3935+
edition = "2015"
3936+
authors = []
3937+
3938+
[dependencies]
3939+
a = { path = "a" }
3940+
"#,
3941+
)
3942+
.file("src/lib.rs", "")
3943+
.file(
3944+
"a/Cargo.toml",
3945+
r#"
3946+
[package]
3947+
name = "a"
3948+
version = "0.5.0"
3949+
edition = "2015"
3950+
authors = []
3951+
build = "build.rs"
3952+
"#,
3953+
)
3954+
.file("a/src/lib.rs", "")
3955+
.file(
3956+
"a/build.rs",
3957+
r#"
3958+
fn main() {
3959+
println!("cargo::warning=foo");
3960+
println!("cargo::warning=bar");
3961+
}
3962+
"#,
3963+
)
3964+
.build();
3965+
3966+
p.cargo("build")
3967+
.with_stderr_data(str![[r#"
3968+
[LOCKING] 2 packages to latest compatible versions
3969+
[COMPILING] a v0.5.0 ([ROOT]/foo/a)
3970+
[WARNING] [email protected]: foo
3971+
[WARNING] [email protected]: bar
3972+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
38823973
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
38833974
38843975
"#]])
@@ -3916,10 +4007,158 @@ fn warnings_emitted_when_build_script_panics() {
39164007
.with_status(101)
39174008
.with_stdout_data("")
39184009
.with_stderr_data(str![[r#"
3919-
...
4010+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
4011+
The following warnings were emitted during compilation:
4012+
39204013
[WARNING] [email protected]: foo
39214014
[WARNING] [email protected]: bar
3922-
...
4015+
4016+
[ERROR] failed to run custom build command for `foo v0.5.0 ([ROOT]/foo)`
4017+
4018+
Caused by:
4019+
process didn't exit successfully: `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` ([EXIT_STATUS]: 101)
4020+
--- stdout
4021+
cargo::warning=foo
4022+
cargo::warning=bar
4023+
4024+
--- stderr
4025+
thread 'main' panicked at build.rs:5:21:
4026+
explicit panic
4027+
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4028+
4029+
"#]])
4030+
.run();
4031+
}
4032+
4033+
#[cargo_test]
4034+
fn warnings_emitted_when_dependency_panics() {
4035+
Package::new("published", "0.1.0")
4036+
.file(
4037+
"build.rs",
4038+
r#"
4039+
fn main() {
4040+
println!("cargo::warning=foo");
4041+
println!("cargo::warning=bar");
4042+
panic!();
4043+
}
4044+
"#,
4045+
)
4046+
.file(
4047+
"Cargo.toml",
4048+
r#"
4049+
[package]
4050+
name = "published"
4051+
version = "0.1.0"
4052+
edition = "2015"
4053+
authors = []
4054+
build = "build.rs"
4055+
"#,
4056+
)
4057+
.file("src/lib.rs", "")
4058+
.publish();
4059+
4060+
let p = project()
4061+
.file(
4062+
"Cargo.toml",
4063+
r#"
4064+
[package]
4065+
name = "foo"
4066+
version = "0.5.0"
4067+
edition = "2015"
4068+
authors = []
4069+
4070+
[dependencies]
4071+
published = "*"
4072+
"#,
4073+
)
4074+
.file("src/lib.rs", "")
4075+
.build();
4076+
4077+
p.cargo("build")
4078+
.with_status(101)
4079+
.with_stderr_data(str![[r#"
4080+
[UPDATING] `dummy-registry` index
4081+
[LOCKING] 2 packages to latest compatible versions
4082+
[DOWNLOADING] crates ...
4083+
[DOWNLOADED] published v0.1.0 (registry `dummy-registry`)
4084+
[COMPILING] published v0.1.0
4085+
The following warnings were emitted during compilation:
4086+
4087+
[WARNING] [email protected]: foo
4088+
[WARNING] [email protected]: bar
4089+
4090+
[ERROR] failed to run custom build command for `published v0.1.0`
4091+
4092+
Caused by:
4093+
process didn't exit successfully: `[ROOT]/foo/target/debug/build/published-[HASH]/build-script-build` ([EXIT_STATUS]: 101)
4094+
--- stdout
4095+
cargo::warning=foo
4096+
cargo::warning=bar
4097+
4098+
--- stderr
4099+
thread 'main' panicked at [ROOT]/home/.cargo/registry/src/-[HASH]/published-0.1.0/build.rs:5:21:
4100+
explicit panic
4101+
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4102+
4103+
"#]])
4104+
.run();
4105+
}
4106+
4107+
#[cargo_test]
4108+
fn errors_and_warnings_emitted_when_dependency_logs_errors() {
4109+
Package::new("published", "0.1.0")
4110+
.file(
4111+
"build.rs",
4112+
r#"
4113+
fn main() {
4114+
println!("cargo::warning=foo");
4115+
println!("cargo::warning=bar");
4116+
println!("cargo::warning=foo err");
4117+
println!("cargo::warning=bar err");
4118+
}
4119+
"#,
4120+
)
4121+
.file(
4122+
"Cargo.toml",
4123+
r#"
4124+
[package]
4125+
name = "published"
4126+
version = "0.1.0"
4127+
edition = "2015"
4128+
authors = []
4129+
build = "build.rs"
4130+
"#,
4131+
)
4132+
.file("src/lib.rs", "")
4133+
.publish();
4134+
4135+
let p = project()
4136+
.file(
4137+
"Cargo.toml",
4138+
r#"
4139+
[package]
4140+
name = "foo"
4141+
version = "0.5.0"
4142+
edition = "2015"
4143+
authors = []
4144+
4145+
[dependencies]
4146+
published = "*"
4147+
"#,
4148+
)
4149+
.file("src/lib.rs", "")
4150+
.build();
4151+
4152+
p.cargo("build")
4153+
.with_stderr_data(str![[r#"
4154+
[UPDATING] `dummy-registry` index
4155+
[LOCKING] 2 packages to latest compatible versions
4156+
[DOWNLOADING] crates ...
4157+
[DOWNLOADED] published v0.1.0 (registry `dummy-registry`)
4158+
[COMPILING] published v0.1.0
4159+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
4160+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4161+
39234162
"#]])
39244163
.run();
39254164
}

0 commit comments

Comments
 (0)