Skip to content

Commit 1c377d7

Browse files
authored
Merge pull request #4 from oli-obk/fmt
Rustfmt everything
2 parents 8ec2a44 + dbc0def commit 1c377d7

File tree

7 files changed

+277
-105
lines changed

7 files changed

+277
-105
lines changed

.github/workflows/rust.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,19 @@ env:
1010
CARGO_TERM_COLOR: always
1111

1212
jobs:
13-
build:
13+
style:
14+
name: style checks
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Format
20+
run: cargo fmt --check
21+
- name: Clippy
22+
run: cargo clippy -- -D warnings
1423

24+
build:
25+
1526
runs-on: ubuntu-latest
1627

1728
steps:

src/dependencies.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ pub fn build_dependencies(config: &Config) -> Result<Dependencies> {
4040
let setup_command = |cmd: &mut Command| {
4141
cmd.envs(envs.iter().map(|(k, v)| (k, v)));
4242
cmd.arg("--manifest-path").arg(manifest_path);
43-
if matches!(config.output_conflict_handling, OutputConflictHandling::Error) {
43+
if matches!(
44+
config.output_conflict_handling,
45+
OutputConflictHandling::Error
46+
) {
4447
cmd.arg("--locked");
4548
}
4649
};
@@ -124,13 +127,19 @@ pub fn build_dependencies(config: &Config) -> Result<Dependencies> {
124127
.id;
125128
// Return the name chosen in `Cargo.toml` and the path to the corresponding artifact
126129
(
127-
package.rename.clone().unwrap_or_else(|| package.name.clone()),
130+
package
131+
.rename
132+
.clone()
133+
.unwrap_or_else(|| package.name.clone()),
128134
artifacts.remove(id).expect("package without artifact"),
129135
)
130136
})
131137
.collect();
132138
let import_paths = import_paths.into_iter().collect();
133-
return Ok(Dependencies { dependencies, import_paths });
139+
return Ok(Dependencies {
140+
dependencies,
141+
import_paths,
142+
});
134143
}
135144

136145
bail!("no json found in cargo-metadata output")

src/lib.rs

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ pub fn run_tests(mut config: Config) -> Result<()> {
115115
if path.is_dir() {
116116
// Enqueue everything inside this directory.
117117
// We want it sorted, to have some control over scheduling of slow tests.
118-
let mut entries =
119-
std::fs::read_dir(path).unwrap().collect::<Result<Vec<_>, _>>().unwrap();
118+
let mut entries = std::fs::read_dir(path)
119+
.unwrap()
120+
.collect::<Result<Vec<_>, _>>()
121+
.unwrap();
120122
entries.sort_by_key(|e| e.file_name());
121123
for entry in entries {
122124
todo.push_back(entry.path());
@@ -178,7 +180,11 @@ pub fn run_tests(mut config: Config) -> Result<()> {
178180
for path in &receive {
179181
if !config.path_filter.is_empty() {
180182
let path_display = path.display().to_string();
181-
if !config.path_filter.iter().any(|filter| path_display.contains(filter)) {
183+
if !config
184+
.path_filter
185+
.iter()
186+
.any(|filter| path_display.contains(filter))
187+
{
182188
filtered.fetch_add(1, Ordering::Relaxed);
183189
continue;
184190
}
@@ -192,8 +198,10 @@ pub fn run_tests(mut config: Config) -> Result<()> {
192198
continue;
193199
}
194200
// Run the test for all revisions
195-
for revision in
196-
comments.revisions.clone().unwrap_or_else(|| vec![String::new()])
201+
for revision in comments
202+
.revisions
203+
.clone()
204+
.unwrap_or_else(|| vec![String::new()])
197205
{
198206
let (m, errors, stderr) =
199207
run_test(&path, &config, &target, &revision, &comments);
@@ -248,12 +256,17 @@ pub fn run_tests(mut config: Config) -> Result<()> {
248256
for error in errors {
249257
match error {
250258
Error::ExitStatus(mode, exit_status) => eprintln!("{mode:?} got {exit_status}"),
251-
Error::PatternNotFound { pattern, definition_line } => {
259+
Error::PatternNotFound {
260+
pattern,
261+
definition_line,
262+
} => {
252263
match pattern {
253-
Pattern::SubString(s) =>
254-
eprintln!("substring `{s}` {} in stderr output", "not found".red()),
255-
Pattern::Regex(r) =>
256-
eprintln!("`/{r}/` does {} stderr output", "not match".red()),
264+
Pattern::SubString(s) => {
265+
eprintln!("substring `{s}` {} in stderr output", "not found".red())
266+
}
267+
Pattern::Regex(r) => {
268+
eprintln!("`/{r}/` does {} stderr output", "not match".red())
269+
}
257270
}
258271
eprintln!(
259272
"expected because of pattern here: {}:{definition_line}",
@@ -263,11 +276,19 @@ pub fn run_tests(mut config: Config) -> Result<()> {
263276
Error::NoPatternsFound => {
264277
eprintln!("{}", "no error patterns found in failure test".red());
265278
}
266-
Error::PatternFoundInPassTest =>
267-
eprintln!("{}", "error pattern found in success test".red()),
268-
Error::OutputDiffers { path, actual, expected } => {
279+
Error::PatternFoundInPassTest => {
280+
eprintln!("{}", "error pattern found in success test".red())
281+
}
282+
Error::OutputDiffers {
283+
path,
284+
actual,
285+
expected,
286+
} => {
269287
eprintln!("actual output differed from expected {}", path.display());
270-
eprintln!("{}", pretty_assertions::StrComparison::new(expected, actual));
288+
eprintln!(
289+
"{}",
290+
pretty_assertions::StrComparison::new(expected, actual)
291+
);
271292
eprintln!()
272293
}
273294
Error::ErrorsWithoutPattern { path: None, msgs } => {
@@ -279,7 +300,10 @@ pub fn run_tests(mut config: Config) -> Result<()> {
279300
eprintln!(" {level:?}: {message}")
280301
}
281302
}
282-
Error::ErrorsWithoutPattern { path: Some((path, line)), msgs } => {
303+
Error::ErrorsWithoutPattern {
304+
path: Some((path, line)),
305+
msgs,
306+
} => {
283307
eprintln!(
284308
"There were {} unmatched diagnostics at {}:{line}",
285309
msgs.len(),
@@ -457,16 +481,24 @@ fn check_annotations(
457481
{
458482
messages_from_unknown_file_or_line.remove(i);
459483
} else {
460-
errors.push(Error::PatternNotFound { pattern: error_pattern.clone(), definition_line });
484+
errors.push(Error::PatternNotFound {
485+
pattern: error_pattern.clone(),
486+
definition_line,
487+
});
461488
}
462489
}
463490

464491
// The order on `Level` is such that `Error` is the highest level.
465492
// We will ensure that *all* diagnostics of level at least `lowest_annotation_level`
466493
// are matched.
467494
let mut lowest_annotation_level = Level::Error;
468-
for &ErrorMatch { ref pattern, revision: ref rev, definition_line, line, level } in
469-
&comments.error_matches
495+
for &ErrorMatch {
496+
ref pattern,
497+
revision: ref rev,
498+
definition_line,
499+
line,
500+
level,
501+
} in &comments.error_matches
470502
{
471503
if let Some(rev) = rev {
472504
if rev != revision {
@@ -480,22 +512,28 @@ fn check_annotations(
480512
lowest_annotation_level = std::cmp::min(lowest_annotation_level, level);
481513

482514
if let Some(msgs) = messages.get_mut(line) {
483-
let found =
484-
msgs.iter().position(|msg| pattern.matches(&msg.message) && msg.level == level);
515+
let found = msgs
516+
.iter()
517+
.position(|msg| pattern.matches(&msg.message) && msg.level == level);
485518
if let Some(found) = found {
486519
msgs.remove(found);
487520
continue;
488521
}
489522
}
490523

491-
errors.push(Error::PatternNotFound { pattern: pattern.clone(), definition_line });
524+
errors.push(Error::PatternNotFound {
525+
pattern: pattern.clone(),
526+
definition_line,
527+
});
492528
}
493529

494530
let filter = |msgs: Vec<Message>| -> Vec<_> {
495531
msgs.into_iter()
496532
.filter(|msg| {
497533
msg.level
498-
>= comments.require_annotations_for_level.unwrap_or(lowest_annotation_level)
534+
>= comments
535+
.require_annotations_for_level
536+
.unwrap_or(lowest_annotation_level)
499537
})
500538
.collect()
501539
};
@@ -511,12 +549,17 @@ fn check_annotations(
511549
for (line, msgs) in messages.into_iter().enumerate() {
512550
let msgs = filter(msgs);
513551
if !msgs.is_empty() {
514-
errors
515-
.push(Error::ErrorsWithoutPattern { path: Some((path.to_path_buf(), line)), msgs });
552+
errors.push(Error::ErrorsWithoutPattern {
553+
path: Some((path.to_path_buf(), line)),
554+
msgs,
555+
});
516556
}
517557
}
518558

519-
match (config.mode, comments.error_pattern.is_some() || !comments.error_matches.is_empty()) {
559+
match (
560+
config.mode,
561+
comments.error_pattern.is_some() || !comments.error_matches.is_empty(),
562+
) {
520563
(Mode::Pass, true) | (Mode::Panic, true) => errors.push(Error::PatternFoundInPassTest),
521564
(Mode::Fail, false) => errors.push(Error::NoPatternsFound),
522565
_ => {}
@@ -536,12 +579,13 @@ fn check_output(
536579
let output = normalize(path, output, filters, comments);
537580
let path = output_path(path, comments, kind, target);
538581
match config.output_conflict_handling {
539-
OutputConflictHandling::Bless =>
582+
OutputConflictHandling::Bless => {
540583
if output.is_empty() {
541584
let _ = std::fs::remove_file(path);
542585
} else {
543586
std::fs::write(path, &output).unwrap();
544-
},
587+
}
588+
}
545589
OutputConflictHandling::Error => {
546590
let expected_output = std::fs::read_to_string(&path).unwrap_or_default();
547591
if output != expected_output {
@@ -573,10 +617,17 @@ fn test_condition(condition: &Condition, target: &str, config: &Config) -> bool
573617

574618
/// Returns whether according to the in-file conditions, this file should be run.
575619
fn test_file_conditions(comments: &Comments, target: &str, config: &Config) -> bool {
576-
if comments.ignore.iter().any(|c| test_condition(c, target, config)) {
620+
if comments
621+
.ignore
622+
.iter()
623+
.any(|c| test_condition(c, target, config))
624+
{
577625
return false;
578626
}
579-
comments.only.iter().all(|c| test_condition(c, target, config))
627+
comments
628+
.only
629+
.iter()
630+
.all(|c| test_condition(c, target, config))
580631
}
581632

582633
// Taken 1:1 from compiletest-rs

0 commit comments

Comments
 (0)