Skip to content

Commit 5f05987

Browse files
committed
Use rustfmt.toml when running self_tests
1 parent d560049 commit 5f05987

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/config/config_type.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ macro_rules! create_config {
322322
///
323323
/// Returns the `Config` to use, and the path of the project file if there was
324324
/// one.
325-
pub(super) fn from_resolved_toml_path(dir: &Path) -> Result<(Config, Option<PathBuf>), Error> {
326-
325+
pub(super) fn from_resolved_toml_path(
326+
dir: &Path,
327+
) -> Result<(Config, Option<PathBuf>), Error> {
327328
/// Try to find a project file in the given directory and its parents.
328329
/// Returns the path of a the nearest project file if one exists,
329330
/// or `None` if no project file was found.

src/test/mod.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn write_message(msg: &str) {
111111
fn system_tests() {
112112
// Get all files in the tests/source directory.
113113
let files = get_test_files(Path::new("tests/source"), true);
114-
let (_reports, count, fails) = check_files(files);
114+
let (_reports, count, fails) = check_files(files, None);
115115

116116
// Display results.
117117
println!("Ran {} system tests.", count);
@@ -123,7 +123,7 @@ fn system_tests() {
123123
#[test]
124124
fn coverage_tests() {
125125
let files = get_test_files(Path::new("tests/coverage/source"), true);
126-
let (_reports, count, fails) = check_files(files);
126+
let (_reports, count, fails) = check_files(files, None);
127127

128128
println!("Ran {} tests in coverage mode.", count);
129129
assert_eq!(fails, 0, "{} tests failed", fails);
@@ -192,7 +192,7 @@ fn assert_output(source: &Path, expected_filename: &Path) {
192192
fn idempotence_tests() {
193193
// Get all files in the tests/target directory.
194194
let files = get_test_files(Path::new("tests/target"), true);
195-
let (_reports, count, fails) = check_files(files);
195+
let (_reports, count, fails) = check_files(files, None);
196196

197197
// Display results.
198198
println!("Ran {} idempotent tests.", count);
@@ -213,7 +213,7 @@ fn self_tests() {
213213
}
214214
files.push(PathBuf::from("src/lib.rs"));
215215

216-
let (reports, count, fails) = check_files(files);
216+
let (reports, count, fails) = check_files(files, Some(PathBuf::from("rustfmt.toml")));
217217
let mut warnings = 0;
218218

219219
// Display results.
@@ -298,15 +298,15 @@ fn format_lines_errors_are_reported_with_tabs() {
298298

299299
// For each file, run rustfmt and collect the output.
300300
// Returns the number of files checked and the number of failures.
301-
fn check_files(files: Vec<PathBuf>) -> (Vec<FormatReport>, u32, u32) {
301+
fn check_files(files: Vec<PathBuf>, opt_config: Option<PathBuf>) -> (Vec<FormatReport>, u32, u32) {
302302
let mut count = 0;
303303
let mut fails = 0;
304304
let mut reports = vec![];
305305

306306
for file_name in files {
307307
debug!("Testing '{}'...", file_name.display());
308308

309-
match idempotent_check(&file_name) {
309+
match idempotent_check(&file_name, &opt_config) {
310310
Ok(ref report) if report.has_warnings() => {
311311
print!("{}", report);
312312
fails += 1;
@@ -385,9 +385,16 @@ pub enum IdempotentCheckError {
385385
Parse,
386386
}
387387

388-
pub fn idempotent_check(filename: &PathBuf) -> Result<FormatReport, IdempotentCheckError> {
388+
pub fn idempotent_check(
389+
filename: &PathBuf,
390+
opt_config: &Option<PathBuf>,
391+
) -> Result<FormatReport, IdempotentCheckError> {
389392
let sig_comments = read_significant_comments(filename);
390-
let config = read_config(filename);
393+
let config = if let Some(ref config_file_path) = opt_config {
394+
Config::from_toml_path(config_file_path).expect("rustfmt.toml not found")
395+
} else {
396+
read_config(filename)
397+
};
391398
let (error_summary, file_map, format_report) = format_file(filename, &config);
392399
if error_summary.has_parsing_errors() {
393400
return Err(IdempotentCheckError::Parse);

0 commit comments

Comments
 (0)