README Source History Refs Reviews Compare Notes Search Review guide SM-003 slice: `xtask check` orchestrator (fmt + clippy + test + doc) (#112) f0dad88f256904db36bc097d21622d948991161d
agent-smith-bugabinga-adc[bot] <306488075+agent-smith-bugabinga-adc[bot]@users.noreply.github.com > · 25 Jul 2026
SSH signature · not checked
Browse files Compare with HEAD
Implements #89. Built by Codex (cross-family builder); rides the normal
review + merge-gate.
---------
Co-authored-by: agent-smith-bugabinga-adc[bot] <agent-smith-bugabinga-adc[bot]@users.noreply.github.com>
Co-authored-by: Oliver Jan Krylow <oliver@bugabinga.net> Changed files (1) Diff layout Auto Unified Split
xtask/src/main.rs Modified +180 / −4 text lines
4 - clippy::missing_const_for_fn,5 - reason = "Rust entry points cannot be const, and test builds lint main as a regular function" 7 + process::{Command, ExitCode},10 + const CHECK_GATES : [Gate; 4 ] = [11 + Gate::new("fmt" , & ["fmt" , "--check" ]),24 + Gate::new("test" , & ["nextest" , "run" , "--workspace" ]),25 + Gate::new("doc" , & ["test" , "--doc" , "--workspace" ]),30 + arguments: &'static [&'static str ],34 + const fn new (name: &'static str , arguments: &'static [&'static str ]) -> Self {35 + Self { name, arguments }45 + impl fmt::Display for GateError {46 + fn fmt (& self, formatter: &mut fmt::Formatter<'_ >) -> fmt::Result {48 + Self ::Spawn(error) => write! (formatter, "could not start cargo: {error}" ),49 + Self ::Failed => formatter.write_str ("returned a non-zero status" ),54 + impl Error for GateError {55 + fn source (& self) -> Option <& (dyn Error + 'static )> {57 + Self ::Spawn(error) => Some (error),58 + Self ::Failed => None ,68 + impl fmt::Display for CheckError {69 + fn fmt (& self, formatter: &mut fmt::Formatter<'_ >) -> fmt::Result {70 + write! (formatter, "{} gate {}" , self.gate, self.source)75 + clippy::print_stderr,76 + reason = "A failed gate needs a concise diagnostic before xtask exits non-zero." 78 + fn main () -> ExitCode {79 + let mut arguments = env::args().skip (1 );80 + let command = arguments.next ();82 + if command.as_deref () == Some ("check" ) && arguments.next ().is_none () {83 + return match run_check (run_cargo) {84 + Ok (()) => ExitCode::SUCCESS ,86 + eprintln! ("xtask check: {error}" );92 + eprintln! ("usage: cargo run -p xtask -- check" );97 + mut run_gate: impl FnMut(&'static [&'static str]) -> Result <(), GateError>,98 + ) -> Result <(), CheckError> {99 + for gate in CHECK_GATES {100 + run_gate (gate.arguments).map_err (|source| CheckError {109 + fn run_cargo (arguments: & [&str ]) -> Result <(), GateError> {110 + let status = Command::new("cargo" )113 + .map_err (GateError::Spawn)? ;115 + if status.success () {118 + Err (GateError::Failed)124 + use super ::{GateError, run_check};127 + fn check_runs_stable_gates_in_order () {128 + let mut invocations = Vec ::new();130 + let result = run_check (|arguments| {131 + invocations.push (arguments);135 + assert! (result.is_ok ());136 + let expected: [& [&str ]; 4 ] = [137 + & ["fmt" , "--check" ],147 + & ["nextest" , "run" , "--workspace" ],148 + & ["test" , "--doc" , "--workspace" ],150 + assert_eq! (invocations, expected);154 + fn check_stops_when_a_gate_fails () {155 + let mut invocations = Vec ::new();158 + let result = run_check (|arguments| {159 + invocations.push (arguments);162 + Err (GateError::Failed)168 + assert! (matches! (result, Err (error) if error.gate == "clippy" ));169 + let expected: [& [&str ]; 2 ] = [170 + & ["fmt" , "--check" ],181 + assert_eq! (invocations, expected);