Skip to content

Commit 90b5013

Browse files
authored
Switch to libtest-mimic for wit-bindgen-test (#1496)
* Switch to libtest-mimic for wit-bindgen-test In poking around at #1495 I found that there was no way to actually print the name of the current test being run. I also found that it wouldn't be easy to print the name of the test as it was run before it started running to figure out which test was hanging. Instead of building out infrastructure to do this I've instead opted to switch to using `libtest-mimic`-the-crate also being used in wasm-tools and Wasmtime. This should help add these options by default and while it's not a standard embedding it's close enough. The main downside with this is that `libtest-mimic` requires `'static` tests which was not implemented in this crate. That required a lot of clones to get lifetimes to line up. * CI fixes
1 parent 2d98864 commit 90b5013

File tree

11 files changed

+245
-248
lines changed

11 files changed

+245
-248
lines changed

Cargo.lock

Lines changed: 19 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ anyhow = { workspace = true }
2323
clap = { workspace = true, features = ['env'] }
2424
heck = { workspace = true }
2525
log = "0.4.26"
26-
rayon = "1.10.0"
2726
regex = "1.11.1"
2827
serde = { workspace = true }
2928
toml = "0.8.20"
@@ -39,3 +38,4 @@ wat = { workspace = true }
3938
wit-component = { workspace = true }
4039
wit-parser = { workspace = true }
4140
wit-bindgen-csharp = { workspace = true }
41+
libtest-mimic = "0.8.1"

crates/test/src/c.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct LangConfig {
3333
ldflags: StringList,
3434
}
3535

36-
fn clang(runner: &Runner<'_>) -> PathBuf {
36+
fn clang(runner: &Runner) -> PathBuf {
3737
let target = &runner.opts.c.c_target;
3838
match &runner.opts.c.wasi_sdk_path {
3939
Some(path) => path.join(format!("bin/{target}-clang")),
@@ -67,20 +67,20 @@ impl LanguageMethods for C {
6767
]
6868
}
6969

70-
fn prepare(&self, runner: &mut Runner<'_>) -> Result<()> {
70+
fn prepare(&self, runner: &mut Runner) -> Result<()> {
7171
prepare(runner, clang(runner))
7272
}
7373

74-
fn compile(&self, runner: &Runner<'_>, c: &Compile<'_>) -> Result<()> {
74+
fn compile(&self, runner: &Runner, c: &Compile<'_>) -> Result<()> {
7575
compile(runner, c, clang(runner))
7676
}
7777

78-
fn verify(&self, runner: &Runner<'_>, v: &Verify<'_>) -> Result<()> {
78+
fn verify(&self, runner: &Runner, v: &Verify<'_>) -> Result<()> {
7979
verify(runner, v, clang(runner))
8080
}
8181
}
8282

83-
fn prepare(runner: &mut Runner<'_>, compiler: PathBuf) -> Result<()> {
83+
fn prepare(runner: &mut Runner, compiler: PathBuf) -> Result<()> {
8484
let cwd = env::current_dir()?;
8585
let dir = cwd.join(&runner.opts.artifacts).join("c");
8686

@@ -99,7 +99,7 @@ fn prepare(runner: &mut Runner<'_>, compiler: PathBuf) -> Result<()> {
9999
Ok(())
100100
}
101101

102-
fn compile(runner: &Runner<'_>, compile: &Compile<'_>, compiler: PathBuf) -> Result<()> {
102+
fn compile(runner: &Runner, compile: &Compile<'_>, compiler: PathBuf) -> Result<()> {
103103
let config = compile.component.deserialize_lang_config::<LangConfig>()?;
104104

105105
// Compile the C-based bindings to an object file.
@@ -162,14 +162,14 @@ fn compile(runner: &Runner<'_>, compile: &Compile<'_>, compiler: PathBuf) -> Res
162162
Ok(())
163163
}
164164

165-
fn produces_component(runner: &Runner<'_>) -> bool {
165+
fn produces_component(runner: &Runner) -> bool {
166166
match runner.opts.c.c_target.as_str() {
167167
"wasm32-wasip1" => false,
168168
_ => true,
169169
}
170170
}
171171

172-
fn verify(runner: &Runner<'_>, verify: &Verify<'_>, compiler: PathBuf) -> Result<()> {
172+
fn verify(runner: &Runner, verify: &Verify<'_>, compiler: PathBuf) -> Result<()> {
173173
let mut cmd = Command::new(compiler);
174174
cmd.arg(
175175
verify

crates/test/src/cpp.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct LangConfig {
1919
cflags: StringList,
2020
}
2121

22-
fn clangpp(runner: &Runner<'_>) -> PathBuf {
22+
fn clangpp(runner: &Runner) -> PathBuf {
2323
match &runner.opts.c.wasi_sdk_path {
2424
Some(path) => path.join("bin/wasm32-wasip2-clang++"),
2525
None => "wasm32-wasip2-clang++".into(),
@@ -57,7 +57,7 @@ impl LanguageMethods for Cpp {
5757
}
5858
}
5959

60-
fn prepare(&self, runner: &mut crate::Runner<'_>) -> anyhow::Result<()> {
60+
fn prepare(&self, runner: &mut Runner) -> anyhow::Result<()> {
6161
let compiler = clangpp(runner);
6262
let cwd = std::env::current_dir()?;
6363
let dir = cwd.join(&runner.opts.artifacts).join("cpp");
@@ -79,7 +79,7 @@ impl LanguageMethods for Cpp {
7979

8080
fn generate_bindings_prepare(
8181
&self,
82-
_runner: &Runner<'_>,
82+
_runner: &Runner,
8383
bindgen: &crate::Bindgen,
8484
dir: &std::path::Path,
8585
) -> anyhow::Result<()> {
@@ -106,7 +106,7 @@ impl LanguageMethods for Cpp {
106106
Ok(())
107107
}
108108

109-
fn compile(&self, runner: &crate::Runner<'_>, compile: &crate::Compile) -> anyhow::Result<()> {
109+
fn compile(&self, runner: &Runner, compile: &crate::Compile) -> anyhow::Result<()> {
110110
let compiler = clangpp(runner);
111111
let config = compile.component.deserialize_lang_config::<LangConfig>()?;
112112

@@ -180,7 +180,7 @@ impl LanguageMethods for Cpp {
180180
Ok(())
181181
}
182182

183-
fn verify(&self, runner: &crate::Runner<'_>, verify: &crate::Verify) -> anyhow::Result<()> {
183+
fn verify(&self, runner: &Runner, verify: &crate::Verify) -> anyhow::Result<()> {
184184
// for expected
185185
let cwd = std::env::current_dir()?;
186186
let mut helper_dir2 = cwd;

crates/test/src/csharp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ impl LanguageMethods for Csharp {
5151
)
5252
}
5353

54-
fn prepare(&self, runner: &mut Runner<'_>) -> Result<()> {
54+
fn prepare(&self, runner: &mut Runner) -> Result<()> {
5555
runner.run_command(dotnet().arg("--version"))?;
5656

5757
Ok(())
5858
}
5959

60-
fn compile(&self, runner: &Runner<'_>, compile: &Compile<'_>) -> Result<()> {
60+
fn compile(&self, runner: &Runner, compile: &Compile<'_>) -> Result<()> {
6161
let world_name = &compile.component.bindgen.world;
6262
let path = &compile.component.path;
6363
let test_dir = &compile.bindings_dir;
@@ -113,7 +113,7 @@ impl LanguageMethods for Csharp {
113113
Ok(())
114114
}
115115

116-
fn verify(&self, runner: &Runner<'_>, verify: &Verify<'_>) -> Result<()> {
116+
fn verify(&self, runner: &Runner, verify: &Verify<'_>) -> Result<()> {
117117
let dir = verify.bindings_dir;
118118
let name = verify.world;
119119
let mut project = wit_bindgen_csharp::CSProject::new(dir.to_path_buf(), &name, "the_world");

crates/test/src/custom.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub struct Language {
7373
}
7474

7575
impl Language {
76-
pub fn lookup(runner: &Runner<'_>, language: &str) -> Result<Language> {
76+
pub fn lookup(runner: &Runner, language: &str) -> Result<Language> {
7777
for (ext, script) in runner.opts.custom.custom.iter() {
7878
if ext == language {
7979
return Ok(Language {
@@ -108,7 +108,7 @@ impl LanguageMethods for Language {
108108
false
109109
}
110110

111-
fn generate_bindings(&self, runner: &Runner<'_>, bindgen: &Bindgen, dir: &Path) -> Result<()> {
111+
fn generate_bindings(&self, runner: &Runner, bindgen: &Bindgen, dir: &Path) -> Result<()> {
112112
runner.run_command(
113113
Command::new(&self.script)
114114
.arg("bindgen")
@@ -117,7 +117,7 @@ impl LanguageMethods for Language {
117117
)
118118
}
119119

120-
fn prepare(&self, runner: &mut Runner<'_>) -> Result<()> {
120+
fn prepare(&self, runner: &mut Runner) -> Result<()> {
121121
let dir = env::current_dir()?
122122
.join(&runner.opts.artifacts)
123123
.join(&self.extension);
@@ -128,7 +128,7 @@ impl LanguageMethods for Language {
128128
)
129129
}
130130

131-
fn compile(&self, runner: &Runner<'_>, compile: &Compile<'_>) -> Result<()> {
131+
fn compile(&self, runner: &Runner, compile: &Compile<'_>) -> Result<()> {
132132
let dir = env::current_dir()?
133133
.join(&runner.opts.artifacts)
134134
.join(&self.extension);
@@ -144,7 +144,7 @@ impl LanguageMethods for Language {
144144
)
145145
}
146146

147-
fn verify(&self, runner: &Runner<'_>, verify: &Verify<'_>) -> Result<()> {
147+
fn verify(&self, runner: &Runner, verify: &Verify<'_>) -> Result<()> {
148148
runner.run_command(
149149
Command::new(&self.script)
150150
.arg("verify")

crates/test/src/go.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl LanguageMethods for Go {
3434
&["--generate-stubs"]
3535
}
3636

37-
fn prepare(&self, runner: &mut Runner<'_>) -> Result<()> {
37+
fn prepare(&self, runner: &mut Runner) -> Result<()> {
3838
let cwd = env::current_dir()?;
3939
let dir = cwd.join(&runner.opts.artifacts).join("go");
4040
let bindings_dir = cwd.join("wit_component");
@@ -56,7 +56,7 @@ impl LanguageMethods for Go {
5656
)
5757
}
5858

59-
fn compile(&self, runner: &Runner<'_>, compile: &Compile<'_>) -> Result<()> {
59+
fn compile(&self, runner: &Runner, compile: &Compile<'_>) -> Result<()> {
6060
let output = compile.output.with_extension("core.wasm");
6161

6262
// Tests which involve importing and/or exporting more than one
@@ -96,7 +96,7 @@ impl LanguageMethods for Go {
9696
Ok(())
9797
}
9898

99-
fn verify(&self, runner: &Runner<'_>, verify: &Verify<'_>) -> Result<()> {
99+
fn verify(&self, runner: &Runner, verify: &Verify<'_>) -> Result<()> {
100100
replace_bindings_go_mod(runner, verify.bindings_dir)?;
101101

102102
runner.run_command(
@@ -152,7 +152,7 @@ fn all_paths(path: &Path) -> Result<Vec<PathBuf>> {
152152
Ok(paths)
153153
}
154154

155-
fn replace_bindings_go_mod(runner: &Runner<'_>, bindings_dir: &Path) -> Result<()> {
155+
fn replace_bindings_go_mod(runner: &Runner, bindings_dir: &Path) -> Result<()> {
156156
let test_crate = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
157157
let wit_bindgen_root = test_crate.parent().unwrap().parent().unwrap();
158158
let go_package_path = wit_bindgen_root.join("crates/go/src/package");

0 commit comments

Comments
 (0)