Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore extra crate types as long as the required crate types are there #233

Merged
merged 12 commits into from
May 22, 2024
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [Unrealeased]

### Added

### Fixed

### Changed

* Split up `Revisioned::mode` into `Revisioned::exit_status` and `Revisioned::require_annotations`
* `Config::output_conflict_handling` is now `Error` instead of `Bless`

### Removed


## [0.23.0] - 2024-05-02

### Added

Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "ui_test"
version = "0.23.0"
version = "0.24.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A test framework for testing rustc diagnostics output"
repository = "https://github.com/oli-obk/ui_test"
rust-version = "1.63"
rust-version = "1.70"

[lib]
test = true # we have unit tests
Expand All @@ -29,7 +29,7 @@ indicatif = "0.17.6"
prettydiff = { version = "0.6.4", default_features = false }
annotate-snippets = { version = "0.11.2" }
levenshtein = "1.0.5"
spanned = "0.2"
spanned = "0.2.1"

[dependencies.regex]
version = "1.5.5"
Expand Down
2 changes: 1 addition & 1 deletion src/aux_builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Build for AuxBuilder {

match CrateType::from_file_contents(&file_contents) {
// Proc macros must be run on the host
CrateType::ProcMacro => config.target = config.host.clone(),
CrateType::ProcMacro => config.target.clone_from(&config.host),
CrateType::Test | CrateType::Bin | CrateType::Lib => {}
}

Expand Down
8 changes: 7 additions & 1 deletion src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ impl CommandBuilder {
pub fn cargo() -> Self {
Self {
program: PathBuf::from(std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into())),
args: vec!["build".into()],
args: vec![
"build".into(),
"--color=never".into(),
"--quiet".into(),
"--jobs".into(),
"1".into(),
],
out_dir_flag: Some("--target-dir".into()),
input_file_flag: Some("--manifest-path".into()),
envs: vec![],
Expand Down
23 changes: 10 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use spanned::Spanned;
use crate::{
aux_builds::AuxBuilder, build_manager::BuildManager, custom_flags::run::Run,
custom_flags::rustfix::RustfixMode, custom_flags::Flag, filter::Match,
per_test_config::TestConfig, rustc_stderr, Errored, Mode,
per_test_config::TestConfig, rustc_stderr, Errored,
};
use crate::{
diagnostics::Diagnostics,
Expand Down Expand Up @@ -127,18 +127,19 @@ impl Config {
#[cfg(windows)]
(Match::Exact(br"\\?\".to_vec()), b"".to_vec()),
];
comment_defaults.base().normalize_stderr = filters.clone();
comment_defaults
.base()
.normalize_stderr
.clone_from(&filters);
comment_defaults.base().normalize_stdout = filters;
comment_defaults.base().mode = Spanned::dummy(Mode::Fail {
require_patterns: true,
})
.into();
comment_defaults.base().exit_status = Spanned::dummy(1).into();
comment_defaults.base().require_annotations = Spanned::dummy(true).into();
let mut config = Self {
host: None,
target: None,
root_dir: root_dir.into(),
program: CommandBuilder::rustc(),
output_conflict_handling: OutputConflictHandling::Bless,
output_conflict_handling: OutputConflictHandling::Error,
bless_command: None,
out_dir: std::env::var_os("CARGO_TARGET_DIR")
.map(PathBuf::from)
Expand Down Expand Up @@ -175,14 +176,10 @@ impl Config {
});

config.custom_comments.insert("run", |parser, args, span| {
parser.check(
span.clone(),
parser.mode.is_none(),
"cannot specify test mode changes twice",
);
let set = |exit_code| {
parser.set_custom_once("run", Run { exit_code }, args.span());
parser.mode = Spanned::new(Mode::Pass, args.span()).into();
parser.exit_status = Spanned::new(0, span.clone()).into();
parser.require_annotations = Spanned::new(false, span.clone()).into();

let prev = parser
.custom
Expand Down
1 change: 0 additions & 1 deletion src/custom_flags/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl Flag for Run {
let status = output.status;
if status.code() != Some(exit_code) {
errors.push(Error::ExitStatus {
mode: format!("run({exit_code})"),
status,
expected: exit_code,
reason: match (exit_code, status.code()) {
Expand Down
14 changes: 8 additions & 6 deletions src/custom_flags/rustfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
build_manager::BuildManager,
parser::OptWithLine,
per_test_config::{Comments, Revisioned, TestConfig},
Error, Errored, Mode,
Error, Errored,
};

use super::Flag;
Expand Down Expand Up @@ -47,9 +47,11 @@ impl Flag for RustfixMode {
output: &Output,
build_manager: &BuildManager<'_>,
) -> Result<Option<Command>, Errored> {
let global_rustfix = match *config.mode()? {
Mode::Pass | Mode::Panic => RustfixMode::Disabled,
Mode::Fail { .. } | Mode::Yolo => *self,
let global_rustfix = match config.exit_status()? {
Some(Spanned {
content: 101 | 0, ..
}) => RustfixMode::Disabled,
_ => *self,
};

let output = output.clone();
Expand Down Expand Up @@ -120,9 +122,10 @@ impl Flag for RustfixMode {
error_in_other_files: vec![],
error_matches: vec![],
require_annotations_for_level: Default::default(),
mode: OptWithLine::new(Mode::Pass, Span::default()),
diagnostic_code_prefix: OptWithLine::new(String::new(), Span::default()),
custom: config.comments().flat_map(|r| r.custom.clone()).collect(),
exit_status: OptWithLine::new(0, Span::default()),
require_annotations: OptWithLine::default(),
},
))
.collect(),
Expand Down Expand Up @@ -182,7 +185,6 @@ impl Flag for RustfixMode {
Err(Errored {
command: cmd,
errors: vec![Error::ExitStatus {
mode: "rustfix".into(),
expected: 0,
status: output.status,
reason: Spanned::new(
Expand Down
Loading