Skip to content

Commit b874810

Browse files
authored
Merge pull request #204 from bjorn3/fix_proc_macro_deps
Support proc macro test dependencies
2 parents 0e7aa42 + dda7650 commit b874810

File tree

11 files changed

+60
-29
lines changed

11 files changed

+60
-29
lines changed

src/dependencies.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,11 @@ pub(crate) fn build_dependencies(config: &Config) -> Result<Dependencies> {
100100
continue;
101101
};
102102
if let cargo_metadata::Message::CompilerArtifact(artifact) = message {
103-
if artifact
104-
.filenames
105-
.iter()
106-
.any(|f| f.ends_with("build-script-build"))
107-
{
108-
continue;
109-
}
110-
// Check that we only collect rmeta and rlib crates, not build script crates
111-
if artifact
112-
.filenames
113-
.iter()
114-
.any(|f| !matches!(f.extension(), Some("rlib" | "rmeta")))
115-
{
116-
continue;
103+
for ctype in artifact.target.crate_types {
104+
match ctype.as_str() {
105+
"proc-macro" | "lib" => {}
106+
_ => continue,
107+
}
117108
}
118109
for filename in &artifact.filenames {
119110
import_paths.insert(filename.parent().unwrap().into());

src/rustc_stderr.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub(crate) fn process(file: &Path, stderr: &[u8]) -> Diagnostics {
173173
let mut rendered = Vec::new();
174174
let mut messages = vec![];
175175
let mut messages_from_unknown_file_or_line = vec![];
176-
for (line_number, line) in stderr.lines_with_terminator().enumerate() {
176+
for line in stderr.lines_with_terminator() {
177177
if line.starts_with_str(b"{") {
178178
match serde_json::from_slice::<RustcMessage>(line) {
179179
Ok(msg) => {
@@ -187,11 +187,9 @@ pub(crate) fn process(file: &Path, stderr: &[u8]) -> Diagnostics {
187187
None,
188188
);
189189
}
190-
Err(err) => {
191-
panic!(
192-
"failed to parse rustc JSON output at line {line_number}: {err}: {}",
193-
line.to_str_lossy()
194-
)
190+
Err(_) => {
191+
// FIXME: add a way to swap out the `process` function, so that cargo can use a different one from rustc
192+
// The RustcMessage json just happens to match between the two
195193
}
196194
}
197195
} else {

tests/integration.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ fn main() -> Result<()> {
3232
.envs
3333
.push(("BLESS".into(), (!args.check).then(|| String::new().into())));
3434

35+
config
36+
.program
37+
.envs
38+
.push(("RUST_BACKTRACE".into(), Some("0".into())));
39+
3540
config.stdout_filter("in ([0-9]m )?[0-9\\.]+s", "");
3641
config.stdout_filter(r#""--out-dir"(,)? "[^"]+""#, r#""--out-dir"$1 "$$TMP"#);
3742
config.filter("\\.exe", b"");

tests/integrations/basic-bin/tests/actual_tests/foomp.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
//@normalize-stderr-test: "(file name should be).*" -> "$1"
2+
13
use basic_bin::add;
2-
//~^ ERROR: unresolved import `basic_bin`
4+
//~^ ERROR: can't find crate for `basic_bin`
5+
//~| ERROR: file name should be
6+
//~| ERROR: extern location for basic_bin is of an unknown type
37

48
fn main() {
59
add("42", 3);
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
error[E0432]: unresolved import `basic_bin`
2-
--> tests/actual_tests/foomp.rs:1:5
1+
error: extern location for basic_bin is of an unknown type: $DIR/tests/integrations/basic-bin/../../../target/$TMP/$TRIPLE/debug/basic_bin
2+
--> tests/actual_tests/foomp.rs:3:5
33
|
4-
1 | use basic_bin::add;
5-
| ^^^^^^^^^ use of undeclared crate or module `basic_bin`
4+
3 | use basic_bin::add;
5+
| ^^^^^^^^^
66

7-
error: aborting due to 1 previous error
7+
error: file name should be
8+
--> tests/actual_tests/foomp.rs:3:5
9+
|
10+
3 | use basic_bin::add;
11+
| ^^^^^^^^^
12+
13+
error[E0463]: can't find crate for `basic_bin`
14+
--> tests/actual_tests/foomp.rs:3:5
15+
|
16+
3 | use basic_bin::add;
17+
| ^^^^^^^^^ can't find crate
18+
19+
error: aborting due to 3 previous errors
820

9-
For more information about this error, try `rustc --explain E0432`.
21+
For more information about this error, try `rustc --explain E0463`.

tests/integrations/basic-fail/Cargo.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ error: internal compiler error: no errors reported for args
373373

374374
thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:
375375
aborting due to `-Z treat-err-as-bug=1`
376-
stack backtrace:
376+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
377377

378378
error: the compiler unexpectedly panicked. this is a bug.
379379

tests/integrations/basic/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/basic/Cargo.stdout

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Building aux file tests/actual_tests/auxiliary/derive_proc_macro.rs ... ok
1313
tests/actual_tests/aux_derive.rs ... ok
1414
Building aux file tests/actual_tests/auxiliary/the_proc_macro.rs ... ok
1515
tests/actual_tests/aux_proc_macro.rs ... ok
16+
tests/actual_tests/dep_derive.rs ... ok
1617
tests/actual_tests/error_above.rs ... ok
1718
tests/actual_tests/executable.rs ... ok
1819
tests/actual_tests/foomp-rustfix.rs ... ok
@@ -28,7 +29,7 @@ tests/actual_tests/unicode.rs ... ok
2829
tests/actual_tests/windows_paths.rs ... ok
2930
tests/actual_tests/subdir/aux_proc_macro.rs ... ok
3031

31-
test result: ok. 16 passed;
32+
test result: ok. 17 passed;
3233

3334

3435
running 0 tests

tests/integrations/basic/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

8+
[dependencies]
9+
serde_derive = "1.0"
10+
811
[dev-dependencies]
912
ui_test = { path = "../../.."}
1013
tempfile = "3.3.0"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@run
2+
3+
#[macro_use]
4+
extern crate serde_derive;
5+
6+
fn main() {}

0 commit comments

Comments
 (0)