From 7fb3b310290f3ec6cd1756fa5f25dcfafc6948fe Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Tue, 23 Jul 2024 01:43:24 +0200 Subject: [PATCH] cli: Remove extra options parsing for test --- .github/workflows/ci.yml | 2 +- crates/rune/src/cli/tests.rs | 25 +--------------- crates/rune/src/compile/options.rs | 46 ++++++++++++++++++------------ 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55db0fc6e..24a39eb8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -158,4 +158,4 @@ jobs: - run: cargo test --doc - run: cargo run --bin rune -- check --recursive --experimental --path scripts - run: cargo run --bin rune -- test --recursive --experimental --path scripts - - run: cargo run --bin rune -- test --opt include-std + - run: cargo run --bin rune -- test -O test-std=true diff --git a/crates/rune/src/cli/tests.rs b/crates/rune/src/cli/tests.rs index 1bb76a4d5..33b460ea1 100644 --- a/crates/rune/src/cli/tests.rs +++ b/crates/rune/src/cli/tests.rs @@ -35,12 +35,6 @@ mod cli { /// Display one character per test instead of one line #[arg(long, short = 'q')] pub quiet: bool, - /// Add custom test options. - /// - /// Supported options: - /// - `include-std`: Include tests from the `::std` crate. - #[arg(long, long = "opt")] - pub option: Vec, /// Break on the first test failed. #[arg(long)] pub fail_fast: bool, @@ -121,20 +115,6 @@ where let mut batches = Vec::new(); let mut naming = Naming::default(); - - let mut include_std = false; - - for opt in &flags.option { - match opt.as_str() { - "include-std" => { - include_std = true; - } - other => { - bail!("Unsupported option: {other}") - } - } - } - let mut name = String::new(); let mut filter = |item: &Item| -> Result { @@ -223,7 +203,6 @@ where let cases = populate_doc_tests( io, artifacts, - include_std, shared, flags, options, @@ -245,7 +224,6 @@ where let cases = populate_doc_tests( io, artifacts, - include_std, shared, flags, options, @@ -359,7 +337,6 @@ where fn populate_doc_tests( io: &mut Io, artifacts: crate::doc::Artifacts, - include_std: bool, shared: &SharedFlags, flags: &Flags, options: &Options, @@ -370,7 +347,7 @@ fn populate_doc_tests( let mut cases = Vec::new(); for test in artifacts.tests() { - if test.item.as_crate() == Some("std") && !include_std || test.params.ignore { + if !options.test_std && test.item.as_crate() == Some("std") || test.params.ignore { continue; } diff --git a/crates/rune/src/compile/options.rs b/crates/rune/src/compile/options.rs index e03e5737c..bce133b6f 100644 --- a/crates/rune/src/compile/options.rs +++ b/crates/rune/src/compile/options.rs @@ -39,6 +39,8 @@ pub struct Options { pub(crate) v2: bool, /// Build sources as function bodies. pub(crate) function_body: bool, + /// When running tests, include std tests. + pub(crate) test_std: bool, } impl Options { @@ -49,32 +51,39 @@ impl Options { /// It can be used to consistenly parse a collection of options by other /// programs as well. pub fn parse_option(&mut self, option: &str) -> Result<(), ParseOptionError> { - let mut it = option.split('='); + let Some((head, tail)) = option.split_once('=') else { + return Err(ParseOptionError { + option: option.into(), + }); + }; - match it.next() { - Some("memoize-instance-fn") => { - self.memoize_instance_fn = it.next() == Some("true"); + match head { + "memoize-instance-fn" => { + self.memoize_instance_fn = tail == "true"; } - Some("debug-info") => { - self.debug_info = it.next() == Some("true"); + "debug-info" => { + self.debug_info = tail == "true"; } - Some("link-checks") => { - self.link_checks = it.next() == Some("true"); + "link-checks" => { + self.link_checks = tail == "true"; } - Some("macros") => { - self.macros = it.next() == Some("true"); + "macros" => { + self.macros = tail == "true"; } - Some("bytecode") => { - self.bytecode = it.next() == Some("true"); + "bytecode" => { + self.bytecode = tail == "true"; } - Some("test") => { - self.cfg_test = it.next() == Some("true"); + "test" => { + self.cfg_test = tail == "true"; } - Some("v2") => { - self.v2 = it.next() == Some("true"); + "v2" => { + self.v2 = tail == "true"; } - Some("function-body") => { - self.function_body = it.next() == Some("true"); + "function-body" => { + self.function_body = tail == "true"; + } + "test-std" => { + self.test_std = tail == "true"; } _ => { return Err(ParseOptionError { @@ -130,6 +139,7 @@ impl Default for Options { cfg_test: false, v2: false, function_body: false, + test_std: false, } } }