Skip to content

Commit ffdcb7f

Browse files
authored
Merge pull request #167 from phansch/rustfix_coverage
Add support for rustfix coverage tracking
2 parents b58e624 + de5d264 commit ffdcb7f

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ pub struct Config {
215215
/// where to find the remote test client process, if we're using it
216216
pub remote_test_client: Option<PathBuf>,
217217

218+
/// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
219+
/// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
220+
/// created in `/<build_base>/rustfix_missing_coverage.txt`
221+
pub rustfix_coverage: bool,
222+
218223
// Configuration for various run-make tests frobbing things like C compilers
219224
// or querying about various LLVM component information.
220225
pub cc: String,
@@ -358,6 +363,7 @@ impl Default for Config {
358363
host: platform.clone(),
359364
#[cfg(feature = "norustc")]
360365
host: env!("HOST").to_string(),
366+
rustfix_coverage: false,
361367
gdb: None,
362368
gdb_version: None,
363369
gdb_native_rust: false,

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub fn run_tests(config: &Config) {
7575
env::set_var("RUST_TEST_TASKS", "1");
7676
}
7777

78+
// If we want to collect rustfix coverage information,
79+
// we first make sure that the coverage file does not exist.
80+
// It will be created later on.
81+
if config.rustfix_coverage {
82+
let mut coverage_file_path = config.build_base.clone();
83+
coverage_file_path.push("rustfix_missing_coverage.txt");
84+
if coverage_file_path.exists() {
85+
if let Err(e) = fs::remove_file(&coverage_file_path) {
86+
panic!("Could not delete {} due to {}", coverage_file_path.display(), e)
87+
}
88+
}
89+
}
7890
let opts = test_opts(config);
7991
let tests = make_tests(config);
8092
// sadly osx needs some file descriptor limits raised for running tests in

src/runtest.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::collections::HashMap;
2626
use std::collections::HashSet;
2727
use std::env;
2828
use std::ffi::OsString;
29-
use std::fs::{self, File, create_dir_all};
29+
use std::fs::{self, File, create_dir_all, OpenOptions};
3030
use std::fmt;
3131
use std::io::prelude::*;
3232
use std::io::{self, BufReader};
@@ -2268,6 +2268,36 @@ actual:\n\
22682268
errors += self.compare_output(UI_STDERR, &normalized_stderr, &expected_stderr);
22692269

22702270

2271+
if self.config.rustfix_coverage {
2272+
// Find out which tests have `MachineApplicable` suggestions but are missing
2273+
// `run-rustfix` or `run-rustfix-only-machine-applicable` headers.
2274+
//
2275+
// This will return an empty `Vec` in case the executed test file has a
2276+
// `compile-flags: --error-format=xxxx` header with a value other than `json`.
2277+
let suggestions = get_suggestions_from_json(
2278+
&proc_res.stderr,
2279+
&HashSet::new(),
2280+
Filter::MachineApplicableOnly
2281+
).unwrap_or_default();
2282+
if suggestions.len() > 0
2283+
&& !self.props.run_rustfix
2284+
&& !self.props.rustfix_only_machine_applicable {
2285+
let mut coverage_file_path = self.config.build_base.clone();
2286+
coverage_file_path.push("rustfix_missing_coverage.txt");
2287+
debug!("coverage_file_path: {}", coverage_file_path.display());
2288+
2289+
let mut file = OpenOptions::new()
2290+
.create(true)
2291+
.append(true)
2292+
.open(coverage_file_path.as_path())
2293+
.expect("could not create or open file");
2294+
2295+
if let Err(_) = writeln!(file, "{}", self.testpaths.file.display()) {
2296+
panic!("couldn't write to {}", coverage_file_path.display());
2297+
}
2298+
}
2299+
}
2300+
22712301
if self.props.run_rustfix {
22722302
// Apply suggestions from lints to the code itself
22732303
let unfixed_code = self

0 commit comments

Comments
 (0)