Skip to content

Commit

Permalink
cli: Remove extra options parsing for test
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Jul 23, 2024
1 parent 906dadd commit 7fb3b31
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 1 addition & 24 deletions crates/rune/src/cli/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// Break on the first test failed.
#[arg(long)]
pub fail_fast: bool,
Expand Down Expand Up @@ -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<bool> {
Expand Down Expand Up @@ -223,7 +203,6 @@ where
let cases = populate_doc_tests(
io,
artifacts,
include_std,
shared,
flags,
options,
Expand All @@ -245,7 +224,6 @@ where
let cases = populate_doc_tests(
io,
artifacts,
include_std,
shared,
flags,
options,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down
46 changes: 28 additions & 18 deletions crates/rune/src/compile/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -130,6 +139,7 @@ impl Default for Options {
cfg_test: false,
v2: false,
function_body: false,
test_std: false,
}
}
}

0 comments on commit 7fb3b31

Please sign in to comment.