Skip to content

Commit

Permalink
Merge pull request #50 from oli-obk/target_specific_dependencies
Browse files Browse the repository at this point in the history
Only consider dependencies that are enabled on the current target
  • Loading branch information
oli-obk authored Apr 12, 2023
2 parents ba1ef75 + 46959d3 commit 5f34031
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 23 deletions.
3 changes: 2 additions & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ui_test"
version = "0.6.0"
version = "0.6.1"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A test framework for testing rustc diagnostics output"
Expand All @@ -23,6 +23,7 @@ crossbeam-channel = "0.5.6"
tempfile = "3.3.0"
bstr = "1.0.1"
rustfix = "0.6.1"
cargo-platform = "0.1.2"

[dependencies.regex]
version = "1.5.5"
Expand Down
40 changes: 38 additions & 2 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use cargo_metadata::{camino::Utf8PathBuf, DependencyKind};
use cargo_platform::Cfg;
use color_eyre::eyre::{bail, Result};
use std::{
collections::{HashMap, HashSet},
path::PathBuf,
process::Command,
str::FromStr,
};

use crate::{Config, DependencyBuilder, OutputConflictHandling};
Expand All @@ -17,12 +19,39 @@ pub struct Dependencies {
pub dependencies: Vec<(String, Vec<Utf8PathBuf>)>,
}

fn cfgs(config: &Config) -> Result<Vec<Cfg>> {
let mut cmd = Command::new(&config.program);
cmd.arg("--print")
.arg("cfg")
.arg("--target")
.arg(config.target.as_ref().unwrap());
let output = cmd.output()?;
let stdout = String::from_utf8(output.stdout)?;

if !output.status.success() {
let stderr = String::from_utf8(output.stderr)?;
bail!(
"failed to obtain `cfg` information from {}:\nstderr:\n{stderr}\n\nstdout:{stdout}",
config.program.display()
);
}
let mut cfgs = vec![];

for line in stdout.lines() {
cfgs.push(Cfg::from_str(line)?);
}

Ok(cfgs)
}

/// Compiles dependencies and returns the crate names and corresponding rmeta files.
pub fn build_dependencies(config: &Config) -> Result<Dependencies> {
pub fn build_dependencies(config: &mut Config) -> Result<Dependencies> {
let manifest_path = match &config.dependencies_crate_manifest_path {
Some(path) => path,
Some(path) => path.to_owned(),
None => return Ok(Default::default()),
};
let manifest_path = &manifest_path;
config.fill_host_and_target()?;
eprintln!(" Building test dependencies...");
let DependencyBuilder {
program,
Expand Down Expand Up @@ -92,6 +121,8 @@ pub fn build_dependencies(config: &Config) -> Result<Dependencies> {
let output = output.stdout;
let output = String::from_utf8(output)?;

let cfg = cfgs(config)?;

for line in output.lines() {
if !line.starts_with('{') {
continue;
Expand All @@ -114,6 +145,11 @@ pub fn build_dependencies(config: &Config) -> Result<Dependencies> {
.dependencies
.iter()
.filter(|dep| matches!(dep.kind, DependencyKind::Normal))
// Only consider dependencies that are enabled on the current target
.filter(|dep| match &dep.target {
Some(platform) => platform.matches(config.target.as_ref().unwrap(), &cfg),
None => true,
})
.map(|dep| {
let package = metadata
.packages
Expand Down
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,23 @@ impl Config {
}

/// Make sure we have the host and target triples.
pub fn fill_host_and_target(&mut self) {
pub fn fill_host_and_target(&mut self) -> Result<()> {
if self.host.is_none() {
self.host = Some(
rustc_version::VersionMeta::for_command(std::process::Command::new(&self.program))
.expect("failed to parse rustc version info")
.map_err(|err| {
color_eyre::eyre::Report::new(err).wrap_err(format!(
"failed to parse rustc version info: {}",
self.program.display()
))
})?
.host,
);
}
if self.target.is_none() {
self.target = Some(self.host.clone().unwrap());
}
Ok(())
}

fn has_asm_support(&self) -> bool {
Expand Down Expand Up @@ -336,7 +342,7 @@ pub fn run_tests_generic(
file_filter: impl Fn(&Path) -> bool + Sync,
per_file_config: impl Fn(&Config, &Path) -> Option<Config> + Sync,
) -> Result<()> {
config.fill_host_and_target();
config.fill_host_and_target()?;

// A channel for files to process
let (submit, receive) = unbounded();
Expand Down
3 changes: 2 additions & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ fn run(name: &str, mode: Mode) -> Result<()> {
.insert(0, (Match::Exact(b"\\\\".iter().copied().collect()), b"\\"));
config.stderr_filter("\\.exe", b"");
config.stderr_filter(r#"(panic.*)\.rs:[0-9]+:[0-9]+"#, "$1.rs");
config.stderr_filter("failed to parse rustc version info.*", "");
config.stderr_filter(" [0-9]: .*", "");
config.stderr_filter("/target/[^/]+/debug", "/target/$$TRIPLE/debug");

run_tests_generic(
config,
Expand Down
3 changes: 2 additions & 1 deletion tests/integrations/basic-bin/Cargo.lock

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: extern location for basic_bin is of an unknown type: $DIR/tests/integrations/basic-bin/../../../target/debug/basic_bin
error: extern location for basic_bin is of an unknown type: $DIR/tests/integrations/basic-bin/../../../target/$TRIPLE/debug/basic_bin
--> $DIR/foomp.rs:1:5
|
1 | use basic_bin::add;
Expand Down
1 change: 1 addition & 0 deletions tests/integrations/basic-bin/tests/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn main() -> ui_test::color_eyre::Result<()> {
config.stdout_filter("in ([0-9]m )?[0-9\\.]+s", "");
config.stderr_filter(r"[^ ]*/\.?cargo/registry/.*/", "$$CARGO_REGISTRY");
config.stderr_filter(r"\.exe", "");
config.stderr_filter("/target/[^/]+/debug", "/target/$$TRIPLE/debug");
config.path_stderr_filter(&std::path::Path::new(path), "$DIR");
ui_test::run_tests(config)
}
3 changes: 2 additions & 1 deletion tests/integrations/basic-fail-mode/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-fail/Cargo.lock

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

29 changes: 19 additions & 10 deletions tests/integrations/basic-fail/Cargo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/actual_tests/filters.rs ... FAILED
tests/actual_tests/foomp.rs ... FAILED

tests/actual_tests/bad_pattern.rs FAILED:
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/debug" "-L" "$DIR/$DIR/../../../target/debug" "tests/actual_tests/bad_pattern.rs" "--edition" "2021"
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "tests/actual_tests/bad_pattern.rs" "--edition" "2021"

substring `miesmätsched types` not found in stderr output
expected because of pattern here: tests/actual_tests/bad_pattern.rs:5
Expand Down Expand Up @@ -36,7 +36,7 @@ For more information about this error, try `rustc --explain E0308`.


tests/actual_tests/exit_code_fail.rs FAILED:
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/debug" "-L" "$DIR/$DIR/../../../target/debug" "tests/actual_tests/exit_code_fail.rs" "--edition" "2021"
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "tests/actual_tests/exit_code_fail.rs" "--edition" "2021"

fail test got exit status: 0, but expected 1

Expand All @@ -57,7 +57,7 @@ full stderr:


tests/actual_tests/foomp.rs FAILED:
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/debug" "-L" "$DIR/$DIR/../../../target/debug" "tests/actual_tests/foomp.rs" "--edition" "2021"
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "tests/actual_tests/foomp.rs" "--edition" "2021"

actual output differed from expected
--- tests/actual_tests/foomp.stderr
Expand Down Expand Up @@ -136,7 +136,7 @@ tests/actual_tests_bless/revisions_same_everywhere.rs (foo) ... ok
tests/actual_tests_bless/revisions_same_everywhere.rs (bar) ... ok

tests/actual_tests_bless/aux_proc_macro_misuse.rs FAILED:
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/debug" "-L" "$DIR/$DIR/../../../target/debug" "tests/actual_tests_bless/auxiliary/the_proc_macro.rs" "--edition" "2021" "--crate-type" "lib" "--emit=link"
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "tests/actual_tests_bless/auxiliary/the_proc_macro.rs" "--edition" "2021" "--crate-type" "lib" "--emit=link"

auxiliary build for `tests/actual_tests_bless/aux_proc_macro_misuse.rs` failed with exit status: 1

Expand All @@ -153,7 +153,7 @@ error: aborting due to previous error


tests/actual_tests_bless/foomp-rustfix-fail-revisions.rs (revision `a`) FAILED:
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/debug" "-L" "$DIR/$DIR/../../../target/debug" "tests/actual_tests_bless/foomp-rustfix-fail-revisions.a.fixed" "--cfg=a" "--edition" "2021" "--crate-name" "foomp_rustfix_fail_revisions"
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "tests/actual_tests_bless/foomp-rustfix-fail-revisions.a.fixed" "--cfg=a" "--edition" "2021" "--crate-name" "foomp_rustfix_fail_revisions"

rustfix failed with exit status: 1

Expand All @@ -174,7 +174,7 @@ For more information about this error, try `rustc --explain E0308`.


tests/actual_tests_bless/foomp-rustfix-fail-revisions.rs (revision `b`) FAILED:
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/debug" "-L" "$DIR/$DIR/../../../target/debug" "tests/actual_tests_bless/foomp-rustfix-fail-revisions.b.fixed" "--cfg=b" "--edition" "2021" "--crate-name" "foomp_rustfix_fail_revisions"
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "tests/actual_tests_bless/foomp-rustfix-fail-revisions.b.fixed" "--cfg=b" "--edition" "2021" "--crate-name" "foomp_rustfix_fail_revisions"

rustfix failed with exit status: 1

Expand All @@ -195,7 +195,7 @@ For more information about this error, try `rustc --explain E0308`.


tests/actual_tests_bless/foomp-rustfix-fail.rs FAILED:
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/debug" "-L" "$DIR/$DIR/../../../target/debug" "tests/actual_tests_bless/foomp-rustfix-fail.fixed" "--edition" "2021" "--crate-name" "foomp_rustfix_fail"
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "tests/actual_tests_bless/foomp-rustfix-fail.fixed" "--edition" "2021" "--crate-name" "foomp_rustfix_fail"

rustfix failed with exit status: 1

Expand Down Expand Up @@ -243,7 +243,7 @@ full stderr:


tests/actual_tests_bless/revisions_bad.rs (revision `bar`) FAILED:
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/debug" "-L" "$DIR/$DIR/../../../target/debug" "tests/actual_tests_bless/revisions_bad.rs" "--cfg=bar" "--edition" "2021"
command: "rustc" "--out-dir" "$TMP "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TRIPLE/debug" "tests/actual_tests_bless/revisions_bad.rs" "--cfg=bar" "--edition" "2021"

substring ``main` function not found in crate `revisions_bad`` not found in stderr output
expected because of pattern here: tests/actual_tests_bless/revisions_bad.rs:4
Expand Down Expand Up @@ -278,9 +278,18 @@ error: test failed, to rerun pass `--test ui_tests_bless`
Caused by:
process didn't exit successfully: `$DIR/target/debug/ui_tests_bless-HASH --test-threads 1` (exit status: 1)
Compiler flags: []
thread 'main' panicked at '
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: failed to parse rustc version info: invalid_foobarlaksdfalsdfj

Caused by:



Location:
$DIR/src/lib.rs:180:25
error: test failed, to rerun pass `--test ui_tests_invalid_program`

Caused by:
process didn't exit successfully: `$DIR/target/debug/ui_tests_invalid_program-HASH --test-threads 1` (exit status: 1)
Compiler flags: []
thread '<unnamed>' panicked at 'could not execute "invalid_foobarlaksdfalsdfj" "tests/actual_tests/bad_pattern.rs" "--edition" "2021"', $DIR/src/lib.rs
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
3 changes: 2 additions & 1 deletion tests/integrations/basic/Cargo.lock

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

0 comments on commit 5f34031

Please sign in to comment.