Skip to content

Commit 4a6c383

Browse files
committed
migrate kotlin backend to new test infrastructure
1 parent 125dd9f commit 4a6c383

File tree

5 files changed

+102
-60
lines changed

5 files changed

+102
-60
lines changed

Cargo.lock

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

crates/kotlin/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,3 @@ wasm-metadata = { workspace = true }
1717
heck = { workspace = true }
1818
clap = { workspace = true, optional = true }
1919

20-
[dev-dependencies]
21-
test-helpers = { path = '../test-helpers' }
22-
wit-parser = { workspace = true }

crates/kotlin/tests/codegen.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

crates/test/src/kotlin.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use crate::{LanguageMethods, Runner, Verify};
2+
use anyhow::{bail, Result};
3+
use std::process::Command;
4+
5+
pub struct Kotlin;
6+
7+
impl LanguageMethods for Kotlin {
8+
fn display(&self) -> &str {
9+
"kotlin"
10+
}
11+
12+
fn comment_prefix_for_test_config(&self) -> Option<&str> {
13+
Some("//@")
14+
}
15+
16+
fn prepare(&self, runner: &mut Runner) -> Result<()> {
17+
println!("Testing if ktfmt is available...");
18+
let test_crate = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
19+
let wit_bindgen_root = test_crate.parent().unwrap().parent().unwrap();
20+
let ktfmt_jar = wit_bindgen_root.join("ktfmt-0.47-jar-with-dependencies.jar");
21+
if !ktfmt_jar.exists() {
22+
bail!(
23+
"ktfmt jar not found at `{}`",
24+
ktfmt_jar.display()
25+
);
26+
}
27+
runner.run_command(Command::new("java").arg("-version"))?;
28+
Ok(())
29+
}
30+
31+
fn default_bindgen_args_for_codegen(&self) -> &[&str] {
32+
&["--generate-stubs"]
33+
}
34+
35+
fn compile(&self, _runner: &Runner, _compile: &crate::Compile) -> Result<()> {
36+
bail!("compiling Kotlin to a wasm component is not yet supported")
37+
}
38+
39+
fn should_fail_verify(
40+
&self,
41+
name: &str,
42+
config: &crate::config::WitConfig,
43+
_args: &[String],
44+
) -> bool {
45+
config.error_context
46+
// TODO: fix these codegen failures, and organize them better (e.g. add as a failure condition config.async_ here, once we have real verification)
47+
|| matches!(
48+
name,
49+
"future-same-type-different-names.wit"
50+
| "futures.wit"
51+
| "import-and-export-resource-alias.wit"
52+
| "import-and-export-resource.wit"
53+
| "import-export-future.wit"
54+
| "import-export-stream.wit"
55+
| "issue-1432.wit"
56+
| "issue-1544.wit"
57+
| "issue1515-special-in-comment.wit"
58+
| "issue573.wit"
59+
| "issue929-only-methods.wit"
60+
| "issue929.wit"
61+
| "keywords-in-interfaces-and-worlds.wit"
62+
| "named-fixed-length-list.wit"
63+
| "rename-interface.wit"
64+
| "resource-alias.wit"
65+
| "resource-borrow-in-record.wit"
66+
| "resource-fallible-constructor.wit"
67+
| "resource-local-alias.wit"
68+
| "resource-own-in-other-interface.wit"
69+
| "resources-in-aggregates.wit"
70+
| "resources-with-futures.wit"
71+
| "resources-with-lists.wit"
72+
| "resources-with-streams.wit"
73+
| "resources.wit"
74+
| "return-resource-from-export.wit"
75+
| "smoke-export.wit"
76+
| "smoke.wit"
77+
| "streams.wit"
78+
| "unused-import.wit"
79+
| "use-across-interfaces.wit"
80+
)
81+
}
82+
83+
fn verify(&self, runner: &Runner, verify: &Verify) -> Result<()> {
84+
let test_crate = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
85+
let wit_bindgen_root = test_crate.parent().unwrap().parent().unwrap();
86+
let ktfmt_jar = wit_bindgen_root.join("ktfmt-0.47-jar-with-dependencies.jar");
87+
88+
let mut cmd = Command::new("java");
89+
cmd.arg("-jar")
90+
.arg(&ktfmt_jar)
91+
.arg(verify.bindings_dir.file_name().unwrap())
92+
.current_dir(verify.bindings_dir.parent().unwrap());
93+
runner.run_command(&mut cmd)
94+
95+
// TODO actually compile the bindings to verify compilation
96+
}
97+
}

crates/test/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod cpp;
1818
mod csharp;
1919
mod custom;
2020
mod go;
21+
mod kotlin;
2122
mod moonbit;
2223
mod runner;
2324
mod rust;
@@ -228,6 +229,7 @@ enum Language {
228229
Csharp,
229230
MoonBit,
230231
Go,
232+
Kotlin,
231233
Custom(custom::Language),
232234
}
233235

@@ -449,6 +451,7 @@ impl Runner {
449451
"cs" => Language::Csharp,
450452
"mbt" => Language::MoonBit,
451453
"go" => Language::Go,
454+
"kt" => Language::Kotlin,
452455
other => Language::Custom(custom::Language::lookup(self, other)?),
453456
};
454457

@@ -1296,6 +1299,7 @@ impl Language {
12961299
Language::Csharp,
12971300
Language::MoonBit,
12981301
Language::Go,
1302+
Language::Kotlin,
12991303
];
13001304

13011305
fn obj(&self) -> &dyn LanguageMethods {
@@ -1307,6 +1311,7 @@ impl Language {
13071311
Language::Csharp => &csharp::Csharp,
13081312
Language::MoonBit => &moonbit::MoonBit,
13091313
Language::Go => &go::Go,
1314+
Language::Kotlin => &kotlin::Kotlin,
13101315
Language::Custom(custom) => custom,
13111316
}
13121317
}

0 commit comments

Comments
 (0)