Skip to content

Commit 1272720

Browse files
committed
Test both --stubs=embedded and --stubs=separate
1 parent 34da20e commit 1272720

4 files changed

Lines changed: 41 additions & 41 deletions

File tree

crates/test/src/c.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl LanguageMethods for C {
6868

6969
fn codegen_test_variants(&self) -> &[(&str, &[&str])] {
7070
&[
71+
("base", &[]),
7172
("no-sig-flattening", &["--no-sig-flattening"]),
7273
("autodrop", &["--autodrop-borrows=yes"]),
7374
("async", &["--async=all"]),

crates/test/src/csharp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ impl LanguageMethods for Csharp {
3030
&["--runtime=native-aot"]
3131
}
3232

33-
fn default_bindgen_args_for_codegen(&self) -> &[&str] {
34-
&["--generate-stub"]
33+
fn codegen_test_variants(&self) -> &[(&str, &[&str])] {
34+
&[("base", &["--generate-stub"])]
3535
}
3636

3737
fn should_fail_verify(

crates/test/src/lib.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ struct Verify<'a> {
214214
bindings_dir: &'a Path,
215215
artifacts_dir: &'a Path,
216216
args: &'a [String],
217+
args_kind: &'a str,
217218
world: &'a str,
218219
}
219220

@@ -503,21 +504,9 @@ impl Runner<'_> {
503504
continue;
504505
}
505506

506-
let mut args = Vec::new();
507-
for arg in language.obj().default_bindgen_args_for_codegen() {
508-
args.push(arg.to_string());
509-
}
510-
511-
codegen_tests.push((
512-
language.clone(),
513-
test,
514-
name.to_string(),
515-
args.clone(),
516-
config.clone(),
517-
));
518-
519507
for (args_kind, new_args) in language.obj().codegen_test_variants() {
520508
let mut args = args.clone();
509+
let mut args = Vec::new();
521510
for arg in new_args.iter() {
522511
args.push(arg.to_string());
523512
}
@@ -615,6 +604,7 @@ impl Runner<'_> {
615604
bindings_dir: &bindings_dir,
616605
wit_test: test,
617606
args: &bindgen.args,
607+
args_kind,
618608
},
619609
)
620610
.context("failed to verify generated bindings")?;
@@ -1107,16 +1097,15 @@ trait LanguageMethods {
11071097
/// `//@` for Rust or `;;@` for WebAssembly Text.
11081098
fn comment_prefix_for_test_config(&self) -> Option<&str>;
11091099

1110-
/// Returns the extra permutations, if any, of arguments to use with codegen
1111-
/// tests.
1100+
/// Returns all test permutations of arguments to use with codegen tests.
11121101
///
11131102
/// This is used to run all codegen tests with a variety of bindings
11141103
/// generator options. The first element in the tuple is a descriptive
1115-
/// string that should be unique (used in file names) and the second elemtn
1104+
/// string that should be unique (used in file names) and the second element
11161105
/// is the list of arguments for that variant to pass to the bindings
11171106
/// generator.
11181107
fn codegen_test_variants(&self) -> &[(&str, &[&str])] {
1119-
&[]
1108+
&[("base", &[])]
11201109
}
11211110

11221111
/// Performs any one-time preparation necessary for this language, such as
@@ -1174,12 +1163,6 @@ trait LanguageMethods {
11741163
&[]
11751164
}
11761165

1177-
/// Same as `default_bindgen_args` but specifically applied during codegen
1178-
/// tests, such as generating stub impls by default.
1179-
fn default_bindgen_args_for_codegen(&self) -> &[&str] {
1180-
&[]
1181-
}
1182-
11831166
/// Returns the name of this bindings generator when passed to
11841167
/// `wit-bindgen`.
11851168
///

crates/test/src/rust.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ struct RustConfig {
4545
externs: Vec<String>,
4646
}
4747

48-
const STUB_SEPARATE: bool = false;
49-
5048
impl LanguageMethods for Rust {
5149
fn display(&self) -> &str {
5250
"rust"
@@ -69,7 +67,7 @@ impl LanguageMethods for Rust {
6967

7068
// Currently there's a bug with this borrowing mode which means that
7169
// this variant does not pass.
72-
if name == "wasi-http-borrowed-duplicate" {
70+
if name.starts_with("wasi-http-borrowed-duplicate") {
7371
return true;
7472
}
7573

@@ -78,28 +76,42 @@ impl LanguageMethods for Rust {
7876

7977
fn codegen_test_variants(&self) -> &[(&str, &[&str])] {
8078
&[
81-
("borrowed", &["--ownership=borrowing"]),
79+
// embedded stubs
80+
("base", &["--stubs=embedded"]),
81+
("borrowed", &["--stubs=embedded", "--ownership=borrowing"]),
8282
(
8383
"borrowed-duplicate",
84-
&["--ownership=borrowing-duplicate-if-necessary"],
84+
&[
85+
"--stubs=embedded",
86+
"--ownership=borrowing-duplicate-if-necessary",
87+
],
88+
),
89+
("async", &["--stubs=embedded", "--async=all"]),
90+
("no-std", &["--stubs=embedded", "--std-feature"]),
91+
// separate stubs
92+
(
93+
"separate-stubs",
94+
&["--stubs=separate", "--ownership=borrowing"],
95+
),
96+
(
97+
"borrowed-duplicate-separate-stubs",
98+
&[
99+
"--stubs=separate",
100+
"--ownership=borrowing-duplicate-if-necessary",
101+
],
102+
),
103+
("async-separate-stubs", &["--stubs=separate", "--async=all"]),
104+
(
105+
"no-std-separate-stubs",
106+
&["--stubs=separate", "--std-feature"],
85107
),
86-
("async", &["--async=all"]),
87-
("no-std", &["--std-feature"]),
88108
]
89109
}
90110

91111
fn default_bindgen_args(&self) -> &[&str] {
92112
&["--generate-all", "--format"]
93113
}
94114

95-
fn default_bindgen_args_for_codegen(&self) -> &[&str] {
96-
if STUB_SEPARATE {
97-
&["--stubs", "separate"]
98-
} else {
99-
&["--stubs", "embedded"]
100-
}
101-
}
102-
103115
fn prepare(&self, runner: &mut Runner<'_>) -> Result<()> {
104116
let cwd = env::current_dir()?;
105117
let opts = &runner.opts.rust;
@@ -237,7 +249,11 @@ path = 'lib.rs'
237249
let bindings = verify.bindings_dir.join(format!(
238250
"{}{}.rs",
239251
verify.world.to_snake_case(),
240-
if STUB_SEPARATE { "_impl" } else { "" },
252+
if verify.args_kind.ends_with("separate-stubs") {
253+
"_impl"
254+
} else {
255+
""
256+
},
241257
));
242258
let test_edition = |edition: Edition| -> Result<()> {
243259
let mut cmd = runner.rustc(edition);

0 commit comments

Comments
 (0)