Skip to content

Commit

Permalink
Merge pull request #204 from bjorn3/fix_proc_macro_deps
Browse files Browse the repository at this point in the history
Support proc macro test dependencies
  • Loading branch information
oli-obk authored Mar 20, 2024
2 parents 0e7aa42 + dda7650 commit b874810
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 29 deletions.
19 changes: 5 additions & 14 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,11 @@ pub(crate) fn build_dependencies(config: &Config) -> Result<Dependencies> {
continue;
};
if let cargo_metadata::Message::CompilerArtifact(artifact) = message {
if artifact
.filenames
.iter()
.any(|f| f.ends_with("build-script-build"))
{
continue;
}
// Check that we only collect rmeta and rlib crates, not build script crates
if artifact
.filenames
.iter()
.any(|f| !matches!(f.extension(), Some("rlib" | "rmeta")))
{
continue;
for ctype in artifact.target.crate_types {
match ctype.as_str() {
"proc-macro" | "lib" => {}
_ => continue,
}
}
for filename in &artifact.filenames {
import_paths.insert(filename.parent().unwrap().into());
Expand Down
10 changes: 4 additions & 6 deletions src/rustc_stderr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub(crate) fn process(file: &Path, stderr: &[u8]) -> Diagnostics {
let mut rendered = Vec::new();
let mut messages = vec![];
let mut messages_from_unknown_file_or_line = vec![];
for (line_number, line) in stderr.lines_with_terminator().enumerate() {
for line in stderr.lines_with_terminator() {
if line.starts_with_str(b"{") {
match serde_json::from_slice::<RustcMessage>(line) {
Ok(msg) => {
Expand All @@ -187,11 +187,9 @@ pub(crate) fn process(file: &Path, stderr: &[u8]) -> Diagnostics {
None,
);
}
Err(err) => {
panic!(
"failed to parse rustc JSON output at line {line_number}: {err}: {}",
line.to_str_lossy()
)
Err(_) => {
// FIXME: add a way to swap out the `process` function, so that cargo can use a different one from rustc
// The RustcMessage json just happens to match between the two
}
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ fn main() -> Result<()> {
.envs
.push(("BLESS".into(), (!args.check).then(|| String::new().into())));

config
.program
.envs
.push(("RUST_BACKTRACE".into(), Some("0".into())));

config.stdout_filter("in ([0-9]m )?[0-9\\.]+s", "");
config.stdout_filter(r#""--out-dir"(,)? "[^"]+""#, r#""--out-dir"$1 "$$TMP"#);
config.filter("\\.exe", b"");
Expand Down
6 changes: 5 additions & 1 deletion tests/integrations/basic-bin/tests/actual_tests/foomp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//@normalize-stderr-test: "(file name should be).*" -> "$1"

use basic_bin::add;
//~^ ERROR: unresolved import `basic_bin`
//~^ ERROR: can't find crate for `basic_bin`
//~| ERROR: file name should be
//~| ERROR: extern location for basic_bin is of an unknown type

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

error: aborting due to 1 previous error
error: file name should be
--> tests/actual_tests/foomp.rs:3:5
|
3 | use basic_bin::add;
| ^^^^^^^^^

error[E0463]: can't find crate for `basic_bin`
--> tests/actual_tests/foomp.rs:3:5
|
3 | use basic_bin::add;
| ^^^^^^^^^ can't find crate

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0432`.
For more information about this error, try `rustc --explain E0463`.
2 changes: 1 addition & 1 deletion tests/integrations/basic-fail/Cargo.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ error: internal compiler error: no errors reported for args

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

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

Expand Down
1 change: 1 addition & 0 deletions tests/integrations/basic/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/integrations/basic/Cargo.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Building aux file tests/actual_tests/auxiliary/derive_proc_macro.rs ... ok
tests/actual_tests/aux_derive.rs ... ok
Building aux file tests/actual_tests/auxiliary/the_proc_macro.rs ... ok
tests/actual_tests/aux_proc_macro.rs ... ok
tests/actual_tests/dep_derive.rs ... ok
tests/actual_tests/error_above.rs ... ok
tests/actual_tests/executable.rs ... ok
tests/actual_tests/foomp-rustfix.rs ... ok
Expand All @@ -28,7 +29,7 @@ tests/actual_tests/unicode.rs ... ok
tests/actual_tests/windows_paths.rs ... ok
tests/actual_tests/subdir/aux_proc_macro.rs ... ok

test result: ok. 16 passed;
test result: ok. 17 passed;


running 0 tests
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/basic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition = "2021"

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

[dependencies]
serde_derive = "1.0"

[dev-dependencies]
ui_test = { path = "../../.."}
tempfile = "3.3.0"
Expand Down
6 changes: 6 additions & 0 deletions tests/integrations/basic/tests/actual_tests/dep_derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@run

#[macro_use]
extern crate serde_derive;

fn main() {}
10 changes: 10 additions & 0 deletions tests/integrations/basic/tests/actual_tests/dep_derive.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
warning: unused `#[macro_use]` import
--> tests/actual_tests/dep_derive.rs:3:1
|
3 | #[macro_use]
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

0 comments on commit b874810

Please sign in to comment.