Skip to content

Commit bee5d09

Browse files
estebankcuviper
authored andcommitted
Move the crate-loading test to use diff output
(cherry picked from commit 998ff2f)
1 parent 2fb0b16 commit bee5d09

File tree

3 files changed

+138
-70
lines changed

3 files changed

+138
-70
lines changed

src/tools/run-make-support/src/external_deps/rustc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ impl Rustc {
227227
self
228228
}
229229

230+
/// Normalize the line number in the stderr output
231+
pub fn ui_testing(&mut self) -> &mut Self {
232+
self.cmd.arg(format!("-Zui-testing"));
233+
self
234+
}
235+
230236
/// Specify the target triple, or a path to a custom target json spec file.
231237
pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self {
232238
let target = target.as_ref();
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied because the trait comes from a different crate version
2+
--> replaced
3+
|
4+
LL | do_something(Type);
5+
| ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type`
6+
|
7+
note: there are multiple different versions of crate `dependency` in the dependency graph
8+
--> replaced
9+
|
10+
LL | pub struct Type(pub i32);
11+
| --------------- this type implements the required trait
12+
LL | pub trait Trait {
13+
| ^^^^^^^^^^^^^^^ this is the required trait
14+
|
15+
::: replaced
16+
|
17+
LL | extern crate dep_2_reexport;
18+
| ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
19+
LL | extern crate dependency;
20+
| ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate
21+
|
22+
::: replaced
23+
|
24+
LL | pub struct Type;
25+
| --------------- this type doesn't implement the required trait
26+
LL | pub trait Trait {
27+
| --------------- this is the found trait
28+
= note: two types coming from two different versions of the same crate are different types even if they look the same
29+
= help: you can use `cargo tree` to explore your dependency tree
30+
31+
error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope
32+
--> replaced
33+
|
34+
LL | Type.foo();
35+
| ^^^ method not found in `Type`
36+
|
37+
note: there are multiple different versions of crate `dependency` in the dependency graph
38+
--> replaced
39+
|
40+
LL | pub trait Trait {
41+
| ^^^^^^^^^^^^^^^ this is the trait that is needed
42+
LL | fn foo(&self);
43+
| -------------- the method is available for `dep_2_reexport::Type` here
44+
|
45+
::: replaced
46+
|
47+
LL | use dependency::{Trait, do_something};
48+
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`
49+
|
50+
::: replaced
51+
|
52+
LL | pub trait Trait {
53+
| --------------- this is the trait that was imported
54+
55+
error[E0599]: no function or associated item named `bar` found for struct `dep_2_reexport::Type` in the current scope
56+
--> replaced
57+
|
58+
LL | Type::bar();
59+
| ^^^ function or associated item not found in `Type`
60+
|
61+
note: there are multiple different versions of crate `dependency` in the dependency graph
62+
--> replaced
63+
|
64+
LL | pub trait Trait {
65+
| ^^^^^^^^^^^^^^^ this is the trait that is needed
66+
LL | fn foo(&self);
67+
LL | fn bar();
68+
| --------- the associated function is available for `dep_2_reexport::Type` here
69+
|
70+
::: replaced
71+
|
72+
LL | use dependency::{Trait, do_something};
73+
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`
74+
|
75+
::: replaced
76+
|
77+
LL | pub trait Trait {
78+
| --------------- this is the trait that was imported
79+
80+
error[E0277]: the trait bound `OtherType: Trait` is not satisfied because the trait comes from a different crate version
81+
--> replaced
82+
|
83+
LL | do_something(OtherType);
84+
| ^^^^^^^^^ the trait `Trait` is not implemented for `OtherType`
85+
|
86+
note: there are multiple different versions of crate `dependency` in the dependency graph
87+
--> replaced
88+
|
89+
LL | pub trait Trait {
90+
| ^^^^^^^^^^^^^^^ this is the required trait
91+
|
92+
::: replaced
93+
|
94+
LL | extern crate dep_2_reexport;
95+
| ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
96+
LL | extern crate dependency;
97+
| ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate
98+
|
99+
::: replaced
100+
|
101+
LL | pub struct OtherType;
102+
| -------------------- this type doesn't implement the required trait
103+
|
104+
::: replaced
105+
|
106+
LL | pub trait Trait {
107+
| --------------- this is the found trait
108+
= help: you can use `cargo tree` to explore your dependency tree
109+
110+
error: aborting due to 4 previous errors
111+
112+
Some errors have detailed explanations: E0277, E0599.
113+
For more information about an error, try `rustc --explain E0277`.

tests/run-make/crate-loading/rmake.rs

Lines changed: 19 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ ignore-wasm64
44
// ignore-tidy-linelength
55

6-
use run_make_support::{rust_lib_name, rustc};
6+
use run_make_support::{diff, rust_lib_name, rustc};
77

88
fn main() {
99
rustc().input("multiple-dep-versions-1.rs").run();
@@ -13,77 +13,26 @@ fn main() {
1313
.extern_("dependency", rust_lib_name("dependency2"))
1414
.run();
1515

16-
rustc()
16+
let out = rustc()
1717
.input("multiple-dep-versions.rs")
1818
.extern_("dependency", rust_lib_name("dependency"))
1919
.extern_("dep_2_reexport", rust_lib_name("foo"))
20+
.ui_testing()
2021
.run_fail()
21-
.assert_stderr_contains(r#"error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied because the trait comes from a different crate version
22-
--> multiple-dep-versions.rs:7:18
23-
|
24-
7 | do_something(Type);
25-
| ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type`
26-
|
27-
note: there are multiple different versions of crate `dependency` in the dependency graph"#)
28-
.assert_stderr_contains(r#"
29-
3 | pub struct Type(pub i32);
30-
| --------------- this type implements the required trait
31-
4 | pub trait Trait {
32-
| ^^^^^^^^^^^^^^^ this is the required trait
33-
"#)
34-
.assert_stderr_contains(r#"
35-
1 | extern crate dep_2_reexport;
36-
| ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
37-
2 | extern crate dependency;
38-
| ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate"#)
39-
.assert_stderr_contains(r#"
40-
3 | pub struct Type;
41-
| --------------- this type doesn't implement the required trait
42-
4 | pub trait Trait {
43-
| --------------- this is the found trait
44-
= note: two types coming from two different versions of the same crate are different types even if they look the same
45-
= help: you can use `cargo tree` to explore your dependency tree"#)
46-
.assert_stderr_contains(r#"error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope
47-
--> multiple-dep-versions.rs:8:10
48-
|
49-
8 | Type.foo();
50-
| ^^^ method not found in `Type`
51-
|
52-
note: there are multiple different versions of crate `dependency` in the dependency graph"#)
53-
.assert_stderr_contains(r#"
54-
4 | pub trait Trait {
55-
| ^^^^^^^^^^^^^^^ this is the trait that is needed
56-
5 | fn foo(&self);
57-
| -------------- the method is available for `dep_2_reexport::Type` here
58-
|
59-
::: multiple-dep-versions.rs:4:18
60-
|
61-
4 | use dependency::{Trait, do_something};
62-
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`"#)
63-
.assert_stderr_contains(r#"
64-
4 | pub trait Trait {
65-
| --------------- this is the trait that was imported"#)
66-
.assert_stderr_contains(r#"
67-
error[E0599]: no function or associated item named `bar` found for struct `dep_2_reexport::Type` in the current scope
68-
--> multiple-dep-versions.rs:9:11
69-
|
70-
9 | Type::bar();
71-
| ^^^ function or associated item not found in `Type`
72-
|
73-
note: there are multiple different versions of crate `dependency` in the dependency graph"#)
74-
.assert_stderr_contains(r#"
75-
4 | pub trait Trait {
76-
| ^^^^^^^^^^^^^^^ this is the trait that is needed
77-
5 | fn foo(&self);
78-
6 | fn bar();
79-
| --------- the associated function is available for `dep_2_reexport::Type` here
80-
|
81-
::: multiple-dep-versions.rs:4:18
82-
|
83-
4 | use dependency::{Trait, do_something};
84-
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`"#)
85-
.assert_stderr_contains(
86-
r#"
87-
6 | pub struct OtherType;
88-
| -------------------- this type doesn't implement the required trait"#);
22+
.stderr_utf8();
23+
24+
// We don't remap all the paths, so we remap it here.
25+
let mut lines: Vec<_> = out.lines().collect();
26+
for line in &mut lines {
27+
if line.starts_with(" --> ") {
28+
*line = " --> replaced";
29+
}
30+
if line.starts_with(" ::: ") {
31+
*line = " ::: replaced";
32+
}
33+
}
34+
diff()
35+
.expected_file("multiple-dep-versions.stderr")
36+
.actual_text("(rustc)", &lines.join("\n"))
37+
.run();
8938
}

0 commit comments

Comments
 (0)