cuno-toolchain 0.3.0

Compiler abstraction, detection, per-compiler implementations, and flag translation.
Documentation
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
693
694
695
696
697
698
699
700
701
//! What can go wrong while finding and preparing a toolchain. Every case is a
//! setup problem (exit code 3): the user's environment, not their code.

use std::fmt;
use std::path::PathBuf;

use cuno_core::{CunoError, ExitClass};

use crate::Version;

const BUILD_TOOLS_HELP: &str = "install Build Tools for Visual Studio with the \"Desktop development with C++\" workload: https://visualstudio.microsoft.com/visual-cpp-build-tools/";

/// A toolchain problem.
#[derive(Clone, Debug)]
pub enum ToolchainError {
    /// vswhere.exe is not where every Visual Studio 2017+ installer puts it.
    VswhereMissing {
        /// Where it was looked for.
        path: PathBuf,
    },
    /// vswhere.exe ran but failed, or printed something that is not its JSON.
    VswhereFailed {
        /// What went wrong, with vswhere's own output when it gave any.
        detail: String,
    },
    /// No Visual Studio or Build Tools installation has the C++ x64 tools.
    NoVisualStudio,
    /// cl.exe could not be run, or printed no version.
    ClVersionUnknown {
        /// The cl.exe that was run.
        path: PathBuf,
    },
    /// No Windows SDK with the x64 headers and libraries.
    NoWindowsSdk {
        /// The SDK directories looked in, in order.
        looked_in: Vec<PathBuf>,
    },
    /// A compiler name cuno does not know.
    UnknownCompiler {
        /// The name.
        name: String,
        /// Where it was given (`CUNO_COMPILER`, ...).
        source: String,
    },
    /// A compiler cuno does not support yet (`gcc`, `safec`).
    UnsupportedCompiler {
        /// The name.
        name: String,
        /// Where it was chosen.
        source: String,
    },
    /// No copy of the chosen compiler was found.
    CompilerNotFound {
        /// The compiler (`clang`).
        compiler: &'static str,
    },
    /// Copies were found, but none is eligible (a preview, a MinGW build, one
    /// that does not run).
    NoUsableCompiler {
        /// The compiler.
        compiler: &'static str,
        /// Each copy found, with why it was left out.
        excluded: Vec<String>,
    },
    /// Copies were found, but none satisfies the requirements.
    NoMatchingVersion {
        /// The compiler.
        compiler: &'static str,
        /// Each requirement, with where it comes from.
        requirements: Vec<String>,
        /// The versions found.
        found: Vec<Version>,
    },
    /// A `[toolchain.version]` value that is not a requirement.
    InvalidVersionRequirement {
        /// The compiler it is for.
        compiler: String,
        /// The value as written.
        text: String,
    },
    /// `[toolchain.paths] msvc` names a directory with no usable Visual Studio.
    VisualStudioNotAt {
        /// The directory.
        path: PathBuf,
    },
    /// The MSVC standard library rejects this Clang (STL1000).
    RejectedByStl {
        /// The compiler (`clang`, `clang-cl`).
        compiler: &'static str,
        /// Its version.
        version: Version,
        /// The Clang version the library asks for, as written, if it says.
        needed: Option<String>,
        /// The library's message.
        message: String,
    },
    /// The GCC selected did not say where its headers or libraries are
    /// (`toolchain.md`, "MinGW (GCC)"), which the build needs to know.
    GccUnreadable {
        /// The `gcc`.
        path: PathBuf,
        /// What it was asked.
        asked: &'static str,
        /// What it printed, or why it could not run.
        output: String,
    },
    /// The standard library probe failed for another reason, so no verdict.
    ProbeFailed {
        /// The compiler.
        compiler: &'static str,
        /// What it printed, or why it could not run.
        output: String,
    },
    /// The selected compiler is too old for the package's edition.
    EditionNotSupported {
        /// The compiler.
        compiler: &'static str,
        /// Its version.
        version: Version,
        /// The edition, as written.
        edition: &'static str,
        /// The oldest version that accepts it.
        needed: Version,
    },
    /// A tool path the user configured has no file.
    ConfiguredToolMissing {
        /// The setting, such as `[toolchain.paths] clang-tidy`.
        setting: String,
        /// The path it gives.
        path: PathBuf,
    },
    /// A tool path the user configured names a tool that cannot be used (it
    /// does not run, prints no version, is a preview, or targets MinGW).
    ConfiguredToolUnusable {
        /// The setting, such as `[toolchain.paths] clang-tidy`.
        setting: String,
        /// The path it gives.
        path: PathBuf,
        /// Why it cannot be used, such as `it did not run`.
        why: String,
    },
}

impl fmt::Display for ToolchainError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ToolchainError::VswhereMissing { path } => {
                write!(f, "vswhere.exe was not found at {}", path.display())
            }
            ToolchainError::VswhereFailed { detail } => {
                f.write_str(&with_output("vswhere.exe failed".to_owned(), detail))
            }
            ToolchainError::NoVisualStudio => {
                f.write_str("no Visual Studio or Build Tools with the C++ x64 tools was found")
            }
            ToolchainError::ClVersionUnknown { path } => {
                write!(f, "could not read the version of {}", path.display())
            }
            ToolchainError::NoWindowsSdk { looked_in } => {
                let places: Vec<String> =
                    looked_in.iter().map(|p| p.display().to_string()).collect();
                write!(
                    f,
                    "no Windows SDK with the x64 headers and libraries was found in {}",
                    places.join(" or ")
                )
            }
            ToolchainError::UnknownCompiler { name, source } => {
                write!(
                    f,
                    "{source} names `{name}`, which is not a compiler cuno knows"
                )
            }
            ToolchainError::UnsupportedCompiler { name, source } => {
                write!(f, "{name} is not supported yet (chosen by {source})")
            }
            ToolchainError::CompilerNotFound { compiler } => write!(f, "no {compiler} was found"),
            ToolchainError::NoUsableCompiler { compiler, excluded } => write!(
                f,
                "no usable {compiler} was found; left out: {}",
                excluded.join("; ")
            ),
            ToolchainError::NoMatchingVersion {
                compiler,
                requirements,
                found,
            } => {
                let found: Vec<String> = found.iter().map(Version::to_string).collect();
                write!(
                    f,
                    "no {compiler} found satisfies {}; found {}",
                    requirements.join(" and "),
                    found.join(", ")
                )
            }
            ToolchainError::InvalidVersionRequirement { compiler, text } => write!(
                f,
                "[toolchain.version] {compiler} = \"{text}\" is not a version requirement"
            ),
            ToolchainError::VisualStudioNotAt { path } => write!(
                f,
                "[toolchain.paths] msvc is {}, but no Visual Studio with the C++ x64 tools is installed there",
                path.display()
            ),
            ToolchainError::RejectedByStl {
                compiler, version, ..
            } => write!(
                f,
                "{compiler} {version} is not accepted by the MSVC standard library in use (STL1000)"
            ),
            ToolchainError::ProbeFailed { compiler, output } => f.write_str(&with_output(
                format!("could not tell whether {compiler} works with the MSVC standard library"),
                output,
            )),
            ToolchainError::GccUnreadable {
                path,
                asked,
                output,
            } => f.write_str(&with_output(
                format!("{} did not say {asked}", path.display()),
                output,
            )),
            ToolchainError::EditionNotSupported {
                compiler,
                version,
                edition,
                ..
            } => write!(
                f,
                "{compiler} {version} does not support edition = \"{edition}\""
            ),
            ToolchainError::ConfiguredToolUnusable { setting, path, why } => {
                write!(f, "{setting} is {}, but {why}", path.display())
            }
            ToolchainError::ConfiguredToolMissing { setting, path } => {
                write!(
                    f,
                    "{setting} is {}, but there is no file there",
                    path.display()
                )
            }
        }
    }
}

impl std::error::Error for ToolchainError {}

/// GCC's name, as the errors carry it.
const GCC: &str = crate::compiler::CompilerKind::Gcc.name();

/// How to install the GCC cuno uses: MSYS2's UCRT64 environment.
const MSYS2_GCC: &str = "https://www.msys2.org/, then `pacman -S mingw-w64-ucrt-x86_64-gcc`";

impl CunoError for ToolchainError {
    fn exit_class(&self) -> ExitClass {
        ExitClass::Setup
    }

    fn help(&self) -> Option<String> {
        match self {
            ToolchainError::UnknownCompiler { .. } | ToolchainError::UnsupportedCompiler { .. } => {
                Some(format!("choose {}", crate::compiler::CompilerKind::names()))
            }
            // GCC is MSYS2's UCRT64 one (`toolchain.md`, "MinGW (GCC)").
            ToolchainError::CompilerNotFound { compiler } if *compiler == GCC => Some(format!(
                "install MSYS2's UCRT64 GCC ({MSYS2_GCC}), or write where gcc is in [toolchain.paths] gcc"
            )),
            ToolchainError::NoUsableCompiler { compiler, .. } if *compiler == GCC => Some(format!(
                "install MSYS2's UCRT64 GCC ({MSYS2_GCC}), or write where a usable gcc is in [toolchain.paths] gcc"
            )),
            ToolchainError::CompilerNotFound { compiler } => Some(format!(
                "install LLVM (https://github.com/llvm/llvm-project/releases), or write where {compiler} is in [toolchain.paths] {compiler}"
            )),
            ToolchainError::NoUsableCompiler { compiler, .. } => Some(format!(
                "install a release of LLVM for Windows (https://github.com/llvm/llvm-project/releases), or write where a usable {compiler} is in [toolchain.paths] {compiler}"
            )),
            ToolchainError::NoMatchingVersion { compiler, .. } => Some(format!(
                "install a {compiler} that satisfies it, or change [toolchain.version] {compiler}"
            )),
            ToolchainError::InvalidVersionRequirement { .. } => Some(
                "write conditions such as \">=17\" or \">=19.29, <19.50\"".to_owned(),
            ),
            ToolchainError::VisualStudioNotAt { .. } => Some(
                "correct [toolchain.paths] msvc, or remove it to let cuno find Visual Studio"
                    .to_owned(),
            ),
            ToolchainError::RejectedByStl {
                compiler: "clang-tidy",
                needed: Some(needed),
                ..
            } => Some(format!("install clang-tidy {needed} or newer")),
            ToolchainError::RejectedByStl {
                needed, message, ..
            } => Some(match needed {
                Some(needed) => {
                    format!("install Clang {needed} or newer, or select another compiler")
                }
                None => format!("the standard library says: {message}"),
            }),
            ToolchainError::ProbeFailed { .. } => Some(
                "check `[build.<compiler>] flags` in Cuno.toml, and the Visual Studio and LLVM installations".to_owned(),
            ),
            ToolchainError::GccUnreadable { .. } => Some(format!(
                "reinstall MSYS2's UCRT64 GCC ({MSYS2_GCC}), or write where a working gcc is in [toolchain.paths] gcc"
            )),

            ToolchainError::EditionNotSupported {
                compiler, needed, ..
            } => Some(format!(
                "use {compiler} {needed} or newer, or choose another edition or compiler"
            )),
            ToolchainError::ConfiguredToolMissing { setting, .. }
            | ToolchainError::ConfiguredToolUnusable { setting, .. } => Some(format!(
                "correct {setting}, or remove it to let cuno find the tool"
            )),
            ToolchainError::VswhereMissing { .. } | ToolchainError::NoVisualStudio => {
                Some(BUILD_TOOLS_HELP.to_owned())
            }
            ToolchainError::NoWindowsSdk { .. } => Some(
                "add a Windows SDK in the Visual Studio Installer (a \"Windows 11 SDK\" component of the \"Desktop development with C++\" workload)".to_owned(),
            ),
            ToolchainError::VswhereFailed { .. } | ToolchainError::ClVersionUnknown { .. } => Some(
                "repair the Visual Studio installation with the Visual Studio Installer".to_owned(),
            ),
        }
    }
}

/// How many lines of a tool's output an error quotes before counting the
/// rest (`docs/en/specs/commands.md`, "Format").
const MAX_QUOTED_LINES: usize = 20;

/// `line`, then `output` quoted below it (`docs/en/specs/commands.md`,
/// "Format"): its trailing whitespace dropped; nothing, and no `:`, when
/// nothing is left; its first [`MAX_QUOTED_LINES`] lines and a count of the
/// rest when it is longer.
fn with_output(line: String, output: &str) -> String {
    let output = output.trim_end();
    if output.is_empty() {
        return line;
    }
    let lines: Vec<&str> = output.lines().collect();
    let shown = lines.len().min(MAX_QUOTED_LINES);
    let mut out = format!("{line}:\n{}", lines[..shown].join("\n"));
    match lines.len() - shown {
        0 => {}
        1 => out.push_str("\n(and 1 more line)"),
        rest => out.push_str(&format!("\n(and {rest} more lines)")),
    }
    out
}

#[cfg(test)]
mod tests {
    use super::*;

    /// Mutation: give any variant another exit class; this test fails.
    #[test]
    fn every_toolchain_error_is_a_setup_problem() {
        for e in [
            ToolchainError::VswhereMissing { path: "x".into() },
            ToolchainError::VswhereFailed { detail: "x".into() },
            ToolchainError::NoVisualStudio,
            ToolchainError::ClVersionUnknown { path: "x".into() },
            ToolchainError::ConfiguredToolMissing {
                setting: "x".into(),
                path: "x".into(),
            },
            ToolchainError::NoWindowsSdk {
                looked_in: vec!["x".into()],
            },
            ToolchainError::UnknownCompiler {
                name: "x".into(),
                source: "x".into(),
            },
            ToolchainError::UnsupportedCompiler {
                name: "x".into(),
                source: "x".into(),
            },
            ToolchainError::CompilerNotFound { compiler: "x" },
            ToolchainError::NoUsableCompiler {
                compiler: "x",
                excluded: vec![],
            },
            ToolchainError::NoMatchingVersion {
                compiler: "x",
                requirements: vec![],
                found: vec![],
            },
            ToolchainError::InvalidVersionRequirement {
                compiler: "x".into(),
                text: "x".into(),
            },
            ToolchainError::VisualStudioNotAt { path: "x".into() },
            ToolchainError::RejectedByStl {
                compiler: "x",
                version: Version {
                    major: 0,
                    minor: 0,
                    patch: 0,
                },
                needed: None,
                message: "x".into(),
            },
            ToolchainError::ProbeFailed {
                compiler: "x",
                output: "x".into(),
            },
            ToolchainError::EditionNotSupported {
                compiler: "x",
                version: Version {
                    major: 0,
                    minor: 0,
                    patch: 0,
                },
                edition: "x",
                needed: Version {
                    major: 0,
                    minor: 0,
                    patch: 0,
                },
            },
        ] {
            assert_eq!(e.exit_class(), ExitClass::Setup, "{e}");
            assert!(e.help().is_some(), "{e}");
        }
    }

    /// Mutation: drop what was looked for from any message, or give a
    /// missing Visual Studio the repair advice instead of the Build Tools
    /// workload; this test fails.
    #[test]
    fn messages_name_what_was_looked_for_and_how_to_fix_it() {
        let cases = [
            (
                ToolchainError::VswhereMissing {
                    path: "Z:/x/vswhere.exe".into(),
                },
                "Z:/x/vswhere.exe",
                "Desktop development with C++",
            ),
            (
                ToolchainError::VswhereFailed {
                    detail: "access denied".into(),
                },
                "access denied",
                "Visual Studio Installer",
            ),
            (
                ToolchainError::NoVisualStudio,
                "C++ x64 tools",
                "Desktop development with C++",
            ),
            (
                ToolchainError::ClVersionUnknown {
                    path: "Z:/t/cl.exe".into(),
                },
                "Z:/t/cl.exe",
                "Visual Studio Installer",
            ),
            (
                ToolchainError::ConfiguredToolMissing {
                    setting: "[toolchain.paths] clang".into(),
                    path: "Z:/c/clang.exe".into(),
                },
                "Z:/c/clang.exe",
                "[toolchain.paths] clang",
            ),
            (
                ToolchainError::NoWindowsSdk {
                    looked_in: vec!["Y:/Kits".into(), "Z:/Windows Kits/10".into()],
                },
                "Y:/Kits or Z:/Windows Kits/10",
                "Windows 11 SDK",
            ),
            (
                ToolchainError::UnsupportedCompiler {
                    name: "safec".into(),
                    source: "CUNO_COMPILER".into(),
                },
                "safec is not supported yet (chosen by CUNO_COMPILER)",
                "msvc, clang, clang-cl or gcc",
            ),
            (
                ToolchainError::NoMatchingVersion {
                    compiler: "msvc",
                    requirements: vec![">=19.29 (cuno's minimum)".into()],
                    found: vec![Version {
                        major: 19,
                        minor: 28,
                        patch: 1,
                    }],
                },
                "satisfies >=19.29 (cuno's minimum); found 19.28.1",
                "[toolchain.version] msvc",
            ),
            (
                ToolchainError::RejectedByStl {
                    compiler: "clang",
                    version: Version {
                        major: 20,
                        minor: 1,
                        patch: 8,
                    },
                    needed: Some("22".into()),
                    message: "STL1000: ...".into(),
                },
                "clang 20.1.8 is not accepted by the MSVC standard library in use (STL1000)",
                "install Clang 22 or newer, or select another compiler",
            ),
            (
                ToolchainError::RejectedByStl {
                    compiler: "clang",
                    version: Version {
                        major: 20,
                        minor: 1,
                        patch: 8,
                    },
                    needed: None,
                    message: "STL1000: odd wording".into(),
                },
                "(STL1000)",
                "STL1000: odd wording",
            ),
            (
                ToolchainError::UnknownCompiler {
                    name: "nope".into(),
                    source: "--compiler".into(),
                },
                "--compiler names `nope`, which is not a compiler cuno knows",
                "msvc, clang, clang-cl or gcc",
            ),
            (
                ToolchainError::CompilerNotFound { compiler: "clang" },
                "no clang was found",
                "[toolchain.paths] clang",
            ),
            (
                ToolchainError::NoUsableCompiler {
                    compiler: "clang",
                    excluded: vec!["a (x)".into(), "b (y)".into()],
                },
                "no usable clang was found; left out: a (x); b (y)",
                "release of LLVM",
            ),
            (
                ToolchainError::CompilerNotFound { compiler: "gcc" },
                "no gcc was found",
                "pacman -S mingw-w64-ucrt-x86_64-gcc`), or write where gcc is in [toolchain.paths] gcc",
            ),
            (
                ToolchainError::NoUsableCompiler {
                    compiler: "gcc",
                    excluded: vec![
                        "C:/mingw64/bin/gcc.exe (its C runtime is MSVCRT, not UCRT)".into(),
                    ],
                },
                "left out: C:/mingw64/bin/gcc.exe (its C runtime is MSVCRT, not UCRT)",
                "install MSYS2's UCRT64 GCC",
            ),
            (
                ToolchainError::InvalidVersionRequirement {
                    compiler: "clang".into(),
                    text: "~17".into(),
                },
                "[toolchain.version] clang = \"~17\" is not a version requirement",
                "\">=19.29, <19.50\"",
            ),
            (
                ToolchainError::VisualStudioNotAt {
                    path: "Z:/VS".into(),
                },
                "[toolchain.paths] msvc is Z:/VS, but no Visual Studio",
                "correct [toolchain.paths] msvc",
            ),
            (
                ToolchainError::ProbeFailed {
                    compiler: "clang-cl",
                    output: "fatal error: x".into(),
                },
                "whether clang-cl works with the MSVC standard library:\nfatal error: x",
                "[build.<compiler>] flags",
            ),
        ];
        for (error, in_message, in_help) in cases {
            let message = error.to_string();
            let help = error.help().unwrap();
            assert!(message.contains(in_message), "{message}");
            assert!(help.contains(in_help), "{help}");
        }
    }

    fn unreadable(output: &str) -> String {
        ToolchainError::GccUnreadable {
            path: PathBuf::from("gcc.exe"),
            asked: "where its headers are",
            output: output.to_owned(),
        }
        .to_string()
    }

    fn numbered(n: usize) -> String {
        (1..=n).map(|i| format!("line {i}\n")).collect()
    }

    /// With nothing printed, or only whitespace, the error is one line with
    /// no `:` and nothing quoted (commands.md, "Format").
    ///
    /// Mutation: keep the `:` and the newline when the output is empty, or
    /// take trailing whitespace for output; this test fails.
    #[test]
    fn an_empty_output_quotes_nothing() {
        for output in ["", "\n  \n", "\r\n"] {
            assert_eq!(
                unreadable(output),
                "gcc.exe did not say where its headers are"
            );
        }
    }

    /// Up to 20 lines are quoted whole after a `:`, trailing whitespace
    /// dropped; past 20, the first 20 and a count of the rest, singular for
    /// one.
    ///
    /// Mutation: truncate below the limit, count the kept lines in the rest,
    /// keep the last lines instead of the first, or always say "lines"; this
    /// test fails.
    #[test]
    fn a_long_output_is_quoted_as_its_first_20_lines() {
        assert_eq!(
            unreadable("cc1: fatal\nsecond\n\n"),
            "gcc.exe did not say where its headers are:\ncc1: fatal\nsecond"
        );
        let twenty = numbered(20);
        assert_eq!(
            unreadable(&twenty),
            format!(
                "gcc.exe did not say where its headers are:\n{}",
                twenty.trim_end()
            )
        );
        assert_eq!(
            unreadable(&numbered(21)),
            format!(
                "gcc.exe did not say where its headers are:\n{}\n(and 1 more line)",
                twenty.trim_end()
            )
        );
        assert_eq!(
            unreadable(&numbered(3000)),
            format!(
                "gcc.exe did not say where its headers are:\n{}\n(and 2980 more lines)",
                twenty.trim_end()
            )
        );
    }

    /// The standard library probe's error quotes by the same rule.
    ///
    /// Mutation: write `ProbeFailed`'s output whole, or with its old `:`
    /// when empty; this test fails.
    #[test]
    fn the_probe_failure_quotes_by_the_same_rule() {
        let failed = |output: &str| {
            ToolchainError::ProbeFailed {
                compiler: "clang",
                output: output.to_owned(),
            }
            .to_string()
        };
        let line = "could not tell whether clang works with the MSVC standard library";
        assert_eq!(failed(""), line);
        assert_eq!(
            failed(&numbered(25)),
            format!("{line}:\n{}\n(and 5 more lines)", numbered(20).trim_end())
        );
    }

    /// vswhere's failure quotes what it printed by the same rule: a
    /// silent failure is one line, and a long one is cut.
    ///
    /// Mutation: write vswhere's detail inline after `: ` again; this test
    /// fails.
    #[test]
    fn the_vswhere_failure_quotes_by_the_same_rule() {
        let failed = |detail: &str| {
            ToolchainError::VswhereFailed {
                detail: detail.to_owned(),
            }
            .to_string()
        };
        assert_eq!(failed(""), "vswhere.exe failed");
        assert_eq!(
            failed(&numbered(22)),
            format!(
                "vswhere.exe failed:\n{}\n(and 2 more lines)",
                numbered(20).trim_end()
            )
        );
    }
}