Skip to content

Commit c30dc9a

Browse files
authored
Don't include all languages by default in wit-bindgen test (#1246)
Instead switch the `-l`/`--language` argument to a required argument. I'm backtracking on "include everything" being a reasonable default since I don't think most users actually want to test everything. Short of that this requires explicit opt-in for what to test.
1 parent ec56282 commit c30dc9a

File tree

2 files changed

+14
-50
lines changed

2 files changed

+14
-50
lines changed

crates/test/src/lib.rs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ pub struct Opts {
100100

101101
/// Configuration of which languages are tested.
102102
///
103-
/// Passing `--lang rust` will only test Rust for example. Passing
104-
/// `--lang=-rust` will test everything except Rust.
105-
#[clap(short, long)]
103+
/// Passing `--lang rust` will only test Rust for example.
104+
#[clap(short, long, required = true, value_delimiter = ',')]
106105
languages: Vec<String>,
107106
}
108107

@@ -1009,43 +1008,10 @@ status: {}",
10091008

10101009
/// Returns whether `languages` is included in this testing session.
10111010
fn include_language(&self, language: &Language) -> bool {
1012-
let lang = language.obj().display();
1013-
let mut any_positive = false;
1014-
let mut any_negative = false;
1015-
for opt in self.opts.languages.iter() {
1016-
for name in opt.split(',') {
1017-
if let Some(suffix) = name.strip_prefix('-') {
1018-
any_negative = true;
1019-
// If explicitly asked to not include this, don't include
1020-
// it.
1021-
if suffix == lang {
1022-
return false;
1023-
}
1024-
} else {
1025-
any_positive = true;
1026-
// If explicitly asked to include this, then include it.
1027-
if name == lang {
1028-
return true;
1029-
}
1030-
}
1031-
}
1032-
}
1033-
1034-
// By default include all languages.
1035-
if self.opts.languages.is_empty() {
1036-
return true;
1037-
}
1038-
1039-
// If any language was explicitly included then assume any non-mentioned
1040-
// language should be omitted.
1041-
if any_positive {
1042-
return false;
1043-
}
1044-
1045-
// And if there are only negative mentions (e.g. `-foo`) then assume
1046-
// everything else is allowed.
1047-
assert!(any_negative);
1048-
true
1011+
self.opts
1012+
.languages
1013+
.iter()
1014+
.any(|l| l == language.obj().display())
10491015
}
10501016

10511017
fn render_errors<'a>(&self, results: impl Iterator<Item = StepResult<'a>>) {

crates/test/src/moonbit.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use std::process::Command;
2-
3-
use serde::Deserialize;
4-
51
use crate::LanguageMethods;
2+
use anyhow::bail;
3+
use serde::Deserialize;
4+
use std::process::Command;
65

76
/// MoonBit configuration of project files
87
#[derive(Default, Deserialize)]
@@ -29,13 +28,12 @@ impl LanguageMethods for MoonBit {
2928

3029
fn prepare(&self, runner: &mut crate::Runner<'_>) -> anyhow::Result<()> {
3130
println!("Testing if MoonBit toolchain exists...");
32-
runner
31+
if runner
3332
.run_command(Command::new("moon").arg("version"))
34-
.inspect_err(|_| {
35-
eprintln!(
36-
"MoonBit toolchain not found. Check out <https://www.moonbitlang.com/download>"
37-
);
38-
})?;
33+
.is_err()
34+
{
35+
bail!("MoonBit toolchain not found. Check out <https://www.moonbitlang.com/download>");
36+
}
3937
Ok(())
4038
}
4139

0 commit comments

Comments
 (0)