From 3e7665fb6305e7365871b386df63463d9c0891e7 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Wed, 5 Apr 2023 13:11:35 -0400 Subject: [PATCH] Slightly improve doctest output Warn user that no 3dsx will be built in this case, and use "human" formatting so that we get colored rustc output (since we don't need to parse the JSON output in this case anyway). --- src/command.rs | 30 ++++++++++++++++++++++-------- src/lib.rs | 2 ++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/command.rs b/src/command.rs index f3ddb55..7877819 100644 --- a/src/command.rs +++ b/src/command.rs @@ -119,8 +119,8 @@ impl CargoCmd { /// `3dslink`. pub fn should_link_to_device(&self) -> bool { match self { - CargoCmd::Test(test) => !test.no_run, - CargoCmd::Run(_) => true, + Self::Test(test) => !test.no_run, + Self::Run(_) => true, _ => false, } } @@ -128,12 +128,26 @@ impl CargoCmd { pub const DEFAULT_MESSAGE_FORMAT: &str = "json-render-diagnostics"; pub fn extract_message_format(&mut self) -> Result, String> { - Self::extract_message_format_from_args(match self { - CargoCmd::Build(args) => &mut args.args, - CargoCmd::Run(run) => &mut run.cargo_args.args, - CargoCmd::Test(test) => &mut test.run_args.cargo_args.args, - CargoCmd::Passthrough(args) => args, - }) + let cargo_args = match self { + Self::Build(args) => &mut args.args, + Self::Run(run) => &mut run.cargo_args.args, + Self::Passthrough(args) => args, + Self::Test(test) => &mut test.run_args.cargo_args.args, + }; + + let format = Self::extract_message_format_from_args(cargo_args)?; + if format.is_some() { + return Ok(format); + } + + if let Self::Test(Test { doc: true, .. }) = self { + // We don't care about JSON output for doctests since we're not + // building any 3dsx etc. Just use the default output as it's more + // readable compared to DEFAULT_MESSAGE_FORMAT + Ok(Some(String::from("human"))) + } else { + Ok(None) + } } fn extract_message_format_from_args( diff --git a/src/lib.rs b/src/lib.rs index a88773e..8fde305 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,6 +97,8 @@ pub fn make_cargo_build_command(cmd: &CargoCmd, message_format: &Option) // user wants if test.doc { + eprintln!("Documentation tests requested, no 3dsx will be built or run"); + // https://github.com/rust-lang/cargo/issues/7040 command.args(["--doc", "-Z", "doctest-xcompile"]);