cargo-mend 0.21.2

Opinionated visibility auditing for Rust crates and workspaces
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
use std::fmt::Write as _;

use super::ColorMode;
use super::CompilerStats;
use super::color;
use crate::reporting::constants::ANSI_BOLD_RED;
use crate::reporting::constants::CARGO_MEND_FIX;
use crate::reporting::constants::CARGO_MEND_FIX_ALL;
use crate::reporting::constants::CARGO_MEND_FIX_COMPILER;
use crate::reporting::constants::CARGO_MEND_FIX_PUB_USE;
use crate::reporting::constants::SUMMARY_LABEL;
use crate::reporting::diagnostics;
use crate::reporting::diagnostics::FixSummaryBucket;
use crate::reporting::diagnostics::Report;
use crate::reporting::diagnostics::Severity;

struct SummaryRow {
    count:       usize,
    description: String,
    /// One entry per applicable fix flag. The first renders inline with the
    /// row; later entries render as continuation lines under the same row.
    fixables:    Vec<SummaryFixable>,
}

struct SummaryFixable {
    count:   usize,
    command: &'static str,
}

#[derive(Clone, Copy, Default)]
struct MendFixableCounts {
    standard: usize,
    pub_use:  usize,
}

impl MendFixableCounts {
    const fn total(self) -> usize { self.standard + self.pub_use }
}

const fn pluralize<'a>(count: usize, singular: &'a str, plural: &'a str) -> &'a str {
    if count == 1 { singular } else { plural }
}

pub(super) fn errors_block(report: &Report, color_mode: ColorMode) -> Option<String> {
    if report.summary.errors == 0 {
        return None;
    }
    let n = report.summary.errors;
    let label = pluralize(n, "mend error", "mend errors");
    let fixables = mend_fixable_counts(report, Severity::Error);
    if fixables.total() == 0 {
        return Some(format!(
            "{} {n} {label} (not auto-fixable; fix manually)",
            color::paint("errors:", ANSI_BOLD_RED, color_mode)
        ));
    }

    let mut details = Vec::new();
    if fixables.standard > 0 {
        details.push(format!(
            "{} fixable with `{CARGO_MEND_FIX}`",
            fixables.standard
        ));
    }
    if fixables.pub_use > 0 {
        details.push(format!(
            "{} fixable with `{CARGO_MEND_FIX_PUB_USE}`",
            fixables.pub_use
        ));
    }
    let manual = n.saturating_sub(fixables.total());
    if manual == 1 {
        details.push("1 requires a manual fix".to_string());
    } else if manual > 1 {
        details.push(format!("{manual} require manual fixes"));
    }
    Some(format!(
        "{} {n} {label} ({})",
        color::paint("errors:", ANSI_BOLD_RED, color_mode),
        details.join("; ")
    ))
}

fn mend_fixable_counts(report: &Report, severity: Severity) -> MendFixableCounts {
    let mut counts = MendFixableCounts::default();
    for finding in report
        .findings
        .iter()
        .filter(|finding| diagnostics::effective_severity(finding) == severity)
    {
        match diagnostics::effective_fixability(finding).summary_bucket() {
            Some(FixSummaryBucket::Standard) => counts.standard += 1,
            Some(FixSummaryBucket::PubUse) => counts.pub_use += 1,
            None => {},
        }
    }
    counts
}

/// How many fix categories have at least one fixable item.
const fn fixable_category_count(
    mend_fixables: MendFixableCounts,
    compiler_stats: &CompilerStats,
) -> usize {
    let mut n = 0;
    if mend_fixables.standard > 0 {
        n += 1;
    }
    if mend_fixables.pub_use > 0 {
        n += 1;
    }
    if compiler_stats.fixable > 0 {
        n += 1;
    }
    n
}

/// The roll-up printed under the findings, or `None` when there is nothing to
/// roll up.
///
/// Errors are reported by [`errors_block`] above this line and deliberately
/// never appear here, so a run whose only findings are errors leaves `rows`
/// empty. Saying "no issues found" there contradicts the block directly above
/// it, so that run gets no summary line at all.
pub(super) fn summary_line(
    report: &Report,
    compiler_stats: &CompilerStats,
    color_mode: ColorMode,
) -> Option<String> {
    let mut rows = Vec::new();
    let mend_fixables = mend_fixable_counts(report, Severity::Warning);
    let categories = fixable_category_count(mend_fixables, compiler_stats);
    let total_fixable = mend_fixables.total() + compiler_stats.fixable;

    if compiler_stats.warnings > 0 {
        let n = compiler_stats.warnings;
        let mut fixables = Vec::new();
        if compiler_stats.fixable > 0 {
            fixables.push(SummaryFixable {
                count:   compiler_stats.fixable,
                command: CARGO_MEND_FIX_COMPILER,
            });
        }
        rows.push(SummaryRow {
            count: n,
            description: pluralize(n, "compiler warning", "compiler warnings").to_string(),
            fixables,
        });
    }
    if report.summary.warnings > 0 {
        let n = report.summary.warnings;
        let mut fixables = Vec::new();
        if mend_fixables.standard > 0 {
            fixables.push(SummaryFixable {
                count:   mend_fixables.standard,
                command: CARGO_MEND_FIX,
            });
        }
        if mend_fixables.pub_use > 0 {
            fixables.push(SummaryFixable {
                count:   mend_fixables.pub_use,
                command: CARGO_MEND_FIX_PUB_USE,
            });
        }
        rows.push(SummaryRow {
            count: n,
            description: pluralize(n, "mend warning", "mend warnings").to_string(),
            fixables,
        });
    }

    if rows.is_empty() {
        if report.summary.errors > 0 {
            return None;
        }
        return Some(format!(
            "{} no issues found",
            color::dim(SUMMARY_LABEL, color_mode)
        ));
    }

    // When fixables span multiple flag categories, append a `--fix-all` entry
    // to the last warning row so the single-command convergent option is
    // always one click away.
    if categories > 1
        && let Some(last) = rows.last_mut()
    {
        last.fixables.push(SummaryFixable {
            count:   total_fixable,
            command: CARGO_MEND_FIX_ALL,
        });
    }

    Some(render_summary_rows(&rows, color_mode))
}

fn render_summary_rows(rows: &[SummaryRow], color_mode: ColorMode) -> String {
    let count_width = rows.iter().map(|r| digit_count(r.count)).max().unwrap_or(1);
    let desc_width = rows.iter().map(|r| r.description.len()).max().unwrap_or(0);
    let fixable_count_width = rows
        .iter()
        .flat_map(|r| r.fixables.iter())
        .map(|f| digit_count(f.count))
        .max()
        .unwrap_or(0);
    let prefix = color::dim(SUMMARY_LABEL, color_mode);
    let indent = " ".repeat(SUMMARY_LABEL.len());
    // Continuation indent fills the count + description columns so the dash
    // aligns with the inline fixable on the parent row.
    let cont_indent = format!("{indent} {:>count_width$} {:<desc_width$}", "", "");

    let mut result = String::new();
    let mut first = true;
    for (i, row) in rows.iter().enumerate() {
        let leader = if i == 0 { &prefix } else { &indent };
        let inline = row.fixables.first();
        let inline_part = inline.map_or_else(String::new, |f| {
            format!(
                " - {:>width$} fixable with `{}`",
                f.count,
                f.command,
                width = fixable_count_width
            )
        });
        if !first {
            result.push('\n');
        }
        first = false;
        let _ = write!(
            result,
            "{leader} {:>count_width$} {:<desc_width$}{inline_part}",
            row.count, row.description,
        );
        for f in row.fixables.iter().skip(1) {
            result.push('\n');
            let _ = write!(
                result,
                "{cont_indent} - {:>width$} fixable with `{}`",
                f.count,
                f.command,
                width = fixable_count_width
            );
        }
    }
    result
}

fn digit_count(n: usize) -> usize { n.to_string().len() }

#[cfg(test)]
#[allow(
    clippy::expect_used,
    reason = "tests should panic on unexpected values"
)]
mod tests {
    use crate::config::DiagnosticCode;
    use crate::reporting;
    use crate::reporting::ColorMode;
    use crate::reporting::CompilerStats;
    use crate::reporting::ItemVisibility;
    use crate::reporting::constants::CARGO_MEND_FIX;
    use crate::reporting::constants::CARGO_MEND_FIX_ALL;
    use crate::reporting::constants::CARGO_MEND_FIX_COMPILER;
    use crate::reporting::constants::CARGO_MEND_FIX_PUB_USE;
    use crate::reporting::constants::SUMMARY_LABEL;
    use crate::reporting::diagnostics::Finding;
    use crate::reporting::diagnostics::FixSupport;
    use crate::reporting::diagnostics::Report;
    use crate::reporting::diagnostics::ReportSummary;
    use crate::reporting::diagnostics::Severity;

    fn compiler_stats(warnings: usize, fixable: usize) -> CompilerStats {
        CompilerStats { warnings, fixable }
    }

    fn mend_warning_report() -> Report {
        Report {
            root: ".".to_string(),
            summary: ReportSummary {
                warnings: 1,
                fixable_with_fix: 1,
                ..ReportSummary::default()
            },
            findings: vec![Finding {
                severity:        Severity::Warning,
                diagnostic_code: DiagnosticCode::NarrowToPubCrate,
                path:            "src/lib.rs".to_string(),
                line:            1,
                column:          1,
                highlight_len:   3,
                source_line:     "pub fn example() {}".to_string(),
                item:            Some("example".to_string()),
                message:         "example warning".to_string(),
                suggestion:      Some("pub(crate) fn example() {}".to_string()),
                fix_support:     FixSupport::NarrowToPubCrate,
                related:         None,
                item_visibility: ItemVisibility::default(),
            }],
            ..Report::default()
        }
    }

    #[test]
    fn render_human_report_prints_no_findings_when_empty() {
        let output = reporting::render_human_report(
            &Report::default(),
            &compiler_stats(0, 0),
            ColorMode::Disabled,
        );

        assert_eq!(output, "No findings.\n");
    }

    #[test]
    fn render_human_report_shows_summary_for_compiler_only_output() {
        let output = reporting::render_human_report(
            &Report::default(),
            &compiler_stats(3, 1),
            ColorMode::Disabled,
        );

        assert!(output.contains(&format!("{SUMMARY_LABEL} 3 compiler warnings")));
        assert!(!output.contains("warning:"));
    }

    #[test]
    fn render_human_report_shows_mend_summary_without_compiler_row() {
        let output = reporting::render_human_report(
            &mend_warning_report(),
            &compiler_stats(0, 0),
            ColorMode::Disabled,
        );

        assert!(output.contains("warning:"));
        assert!(output.contains(&format!("{SUMMARY_LABEL} 1 mend warning")));
        assert!(!output.contains("compiler warning"));
    }

    #[test]
    fn render_human_report_shows_combined_summary_for_mend_and_compiler_findings() {
        let output = reporting::render_human_report(
            &mend_warning_report(),
            &compiler_stats(3, 1),
            ColorMode::Disabled,
        );

        assert!(output.contains(&format!("{SUMMARY_LABEL} 3 compiler warnings")));
        assert!(output.contains("1 mend warning"));
        assert!(
            !output.contains("total warnings"),
            "total-warnings action row should not appear; --fix-all is suggested per row instead"
        );
    }

    #[test]
    fn render_human_report_aligns_summary_count_column_across_rows() {
        let output = reporting::render_human_report(
            &mend_warning_report(),
            &compiler_stats(3, 1),
            ColorMode::Disabled,
        );

        // Compiler row gets `--fix-compiler`; mend row gets `--fix` plus the
        // continuation `--fix-all` line because two categories are fixable.
        assert!(
            output.contains(&format!(
                "{SUMMARY_LABEL} 3 compiler warnings - 1 fixable with `{CARGO_MEND_FIX_COMPILER}`\n"
            )),
            "compiler row missing/misaligned:\n{output}"
        );
        assert!(
            output.contains(&format!(
                "{} 1 mend warning      - 1 fixable with `{CARGO_MEND_FIX}`\n",
                " ".repeat(SUMMARY_LABEL.len())
            )),
            "mend row missing/misaligned:\n{output}"
        );
        // The `--fix-all` continuation line aligns under the inline fixable
        // (its dash sits in the same column as the mend row's dash).
        let mend_row_dash = output
            .lines()
            .find(|line| line.contains("mend warning"))
            .and_then(|line| line.find(" - "))
            .expect("mend row missing dash");
        let fix_all_row_dash = output
            .lines()
            .find(|line| line.contains(CARGO_MEND_FIX_ALL))
            .and_then(|line| line.find(" - "))
            .expect("--fix-all continuation row missing dash");
        assert_eq!(
            fix_all_row_dash, mend_row_dash,
            "--fix-all continuation row misaligned:\n{output}"
        );
    }

    fn pub_use_warning_report() -> Report {
        Report {
            root: ".".to_string(),
            summary: ReportSummary {
                warnings: 1,
                fixable_with_fix_pub_use: 1,
                ..ReportSummary::default()
            },
            findings: vec![Finding {
                severity:        Severity::Warning,
                diagnostic_code: DiagnosticCode::InternalParentPubUseFacade,
                path:            "src/lib.rs".to_string(),
                line:            1,
                column:          1,
                highlight_len:   3,
                source_line:     "pub use child::Foo;".to_string(),
                item:            None,
                message:         "example".to_string(),
                suggestion:      None,
                fix_support:     FixSupport::PubUse,
                related:         None,
                item_visibility: ItemVisibility::default(),
            }],
            ..Report::default()
        }
    }

    fn errors_only_report() -> Report {
        Report {
            root: ".".to_string(),
            summary: ReportSummary {
                errors: 3,
                ..ReportSummary::default()
            },
            findings: vec![Finding {
                severity:        Severity::Error,
                diagnostic_code: DiagnosticCode::ForbiddenPubInCrate,
                path:            "src/lib.rs".to_string(),
                line:            1,
                column:          1,
                highlight_len:   3,
                source_line:     "pub(in crate::internal) fn x() {}".to_string(),
                item:            Some("x".to_string()),
                message:         "forbidden".to_string(),
                suggestion:      None,
                fix_support:     FixSupport::None,
                related:         None,
                item_visibility: ItemVisibility::default(),
            }],
            ..Report::default()
        }
    }

    fn fixable_error_report() -> Report {
        let mut report = Report {
            root: ".".to_string(),
            findings: vec![Finding {
                severity:        Severity::Error,
                diagnostic_code: DiagnosticCode::ForbiddenPubInCrate,
                path:            "src/lib.rs".to_string(),
                line:            1,
                column:          1,
                highlight_len:   23,
                source_line:     "pub(in crate::internal) fn x() {}".to_string(),
                item:            Some("x".to_string()),
                message:         "restricted visibility does not match the required boundary"
                    .to_string(),
                suggestion:      Some("consider using: `pub(in crate::panel)`".to_string()),
                fix_support:     FixSupport::RestrictedAnnotation,
                related:         None,
                item_visibility: ItemVisibility::default(),
            }],
            ..Report::default()
        };
        report.refresh_summary();
        report
    }

    #[test]
    fn summary_never_emits_combined_fix_pub_use_string() {
        // Both mend and pub-use have fixables; each flag should render on its
        // own line plus `--fix-all`, never `cargo mend --fix --fix-pub-use`.
        let report = Report {
            summary: ReportSummary {
                warnings: 2,
                fixable_with_fix: 1,
                fixable_with_fix_pub_use: 1,
                ..ReportSummary::default()
            },
            findings: vec![
                mend_warning_report().findings[0].clone(),
                pub_use_warning_report().findings[0].clone(),
            ],
            ..Report::default()
        };
        let output =
            reporting::render_human_report(&report, &compiler_stats(0, 0), ColorMode::Disabled);

        assert!(
            !output.contains("--fix --fix-pub-use"),
            "combined flag string must never appear:\n{output}"
        );
        assert!(
            output.contains(&format!("`{CARGO_MEND_FIX}`")),
            "expected dedicated `--fix` line:\n{output}"
        );
        assert!(
            output.contains(&format!("`{CARGO_MEND_FIX_PUB_USE}`")),
            "expected dedicated `--fix-pub-use` line:\n{output}"
        );
        assert!(
            output.contains(&format!("`{CARGO_MEND_FIX_ALL}`")),
            "expected `--fix-all` continuation line:\n{output}"
        );
    }

    #[test]
    fn summary_lists_one_line_per_fix_flag_plus_fix_all_aggregate() {
        // Bug-report scenario: 213 mend warnings split 1-and-1 across `--fix`
        // and `--fix-pub-use`. Three lines required.
        let report = Report {
            summary: ReportSummary {
                warnings: 213,
                fixable_with_fix: 1,
                fixable_with_fix_pub_use: 1,
                ..ReportSummary::default()
            },
            findings: vec![
                mend_warning_report().findings[0].clone(),
                pub_use_warning_report().findings[0].clone(),
            ],
            ..Report::default()
        };
        let output =
            reporting::render_human_report(&report, &compiler_stats(0, 0), ColorMode::Disabled);

        let fix_idx = output
            .find(&format!("1 fixable with `{CARGO_MEND_FIX}`"))
            .expect("missing --fix line");
        let pub_use_idx = output
            .find(&format!("1 fixable with `{CARGO_MEND_FIX_PUB_USE}`"))
            .expect("missing --fix-pub-use line");
        let fix_all_idx = output
            .find(&format!("2 fixable with `{CARGO_MEND_FIX_ALL}`"))
            .expect("missing --fix-all aggregate line");
        assert!(
            fix_idx < pub_use_idx && pub_use_idx < fix_all_idx,
            "expected order --fix -> --fix-pub-use -> --fix-all:\n{output}"
        );
    }

    #[test]
    fn summary_suggests_pub_use_alone_when_only_pub_use_is_fixable() {
        let output = reporting::render_human_report(
            &pub_use_warning_report(),
            &compiler_stats(0, 0),
            ColorMode::Disabled,
        );

        assert!(output.contains(&format!("`{CARGO_MEND_FIX_PUB_USE}`")));
        // Single category means no `--fix-all` line.
        assert!(!output.contains("--fix-all"));
    }

    #[test]
    fn summary_emits_per_flag_lines_when_compiler_and_mend_are_fixable() {
        let output = reporting::render_human_report(
            &mend_warning_report(),
            &compiler_stats(2, 2),
            ColorMode::Disabled,
        );

        assert!(
            output.contains(&format!("`{CARGO_MEND_FIX_COMPILER}`")),
            "compiler row should still suggest --fix-compiler:\n{output}"
        );
        assert!(
            output.contains(&format!("`{CARGO_MEND_FIX}`")),
            "mend row should suggest --fix:\n{output}"
        );
        assert!(
            output.contains(&format!("`{CARGO_MEND_FIX_ALL}`")),
            "multi-category aggregate should appear:\n{output}"
        );
    }

    #[test]
    fn errors_render_in_their_own_block_above_summary() {
        let output = reporting::render_human_report(
            &errors_only_report(),
            &compiler_stats(0, 0),
            ColorMode::Disabled,
        );

        let errors_idx = output.find("errors:").expect("errors header should appear");
        let summary_idx = output.find(SUMMARY_LABEL);
        if let Some(s) = summary_idx {
            assert!(
                errors_idx < s,
                "errors block must precede summary block:\n{output}"
            );
        }
        assert!(
            output.contains("not auto-fixable"),
            "errors block must say errors are not auto-fixable:\n{output}"
        );
        // Errors must never show up in the "X fixable" summary count.
        assert!(!output.contains("mend errors -"));
    }

    /// A run whose only findings are errors must not report itself clean.
    /// `summary_line` rolls up warnings and `errors_block` reports errors, so
    /// an errors-only run leaves the summary's row set empty — which used to
    /// print "no issues found" directly beneath the block that had just
    /// reported 25 of them.
    #[test]
    fn errors_only_report_does_not_claim_no_issues_found() {
        let output = reporting::render_human_report(
            &errors_only_report(),
            &compiler_stats(0, 0),
            ColorMode::Disabled,
        );

        assert!(
            output.contains("3 mend errors"),
            "the errors block must still report the errors:\n{output}"
        );
        assert!(
            !output.contains("no issues found"),
            "a run with errors must not report itself clean:\n{output}"
        );
    }

    /// Severity is stored per finding, and only two sites write
    /// `Severity::Error` — the ones whose findings need a person to decide
    /// something. The cross-crate pass can later resolve one of those to an
    /// exact boundary and mark it fixable, and the stored severity does not
    /// follow. Reporting derives it instead, so one rule holds everywhere:
    /// anything mend can fix on its own is a warning, and an error is work only
    /// a person can do.
    #[test]
    fn a_fixable_finding_reports_as_a_warning_whatever_severity_it_carries() {
        let output = reporting::render_human_report(
            &fixable_error_report(),
            &compiler_stats(0, 0),
            ColorMode::Disabled,
        );

        assert!(
            output.contains("this warning is auto-fixable with `cargo mend --fix`"),
            "a fixable finding must advertise its command as a warning:\n{output}"
        );
        assert!(
            output.contains("1 mend warning"),
            "a fixable finding belongs in the warning summary:\n{output}"
        );
        assert!(
            !output.contains("errors:"),
            "no error block when every finding is fixable:\n{output}"
        );
        assert!(!output.contains("not auto-fixable"));
    }

    #[test]
    fn warning_summary_counts_a_fixable_error_finding_among_the_fixable_warnings() {
        let mut report = mend_warning_report();
        report.findings.extend(fixable_error_report().findings);
        report.refresh_summary();

        let output =
            reporting::render_human_report(&report, &compiler_stats(0, 0), ColorMode::Disabled);
        let warning_row = output
            .lines()
            .find(|line| line.contains("mend warning"))
            .expect("missing mend warning summary row");

        assert!(
            warning_row.contains("2 mend warnings"),
            "a fixable finding recorded as an error still reports as a warning:\n{output}"
        );
        assert!(
            warning_row.contains("2 fixable with `cargo mend --fix`"),
            "both fixable findings belong in the warning row's fixable count:\n{output}"
        );
    }

    #[test]
    fn errors_block_omitted_when_no_errors_present() {
        let output = reporting::render_human_report(
            &mend_warning_report(),
            &compiler_stats(0, 0),
            ColorMode::Disabled,
        );

        assert!(!output.contains("errors:"));
    }
}