Skip to content

Commit

Permalink
Generate conformance tests (#226)
Browse files Browse the repository at this point in the history
* init test generation

* run the wasi test

* split test dir up into subcomponents

* first pass at test codegen

* update test generation

* generate tests

* fix newline issues
  • Loading branch information
yoshuawuyts authored Oct 24, 2023
1 parent 22ad066 commit 5f321ef
Show file tree
Hide file tree
Showing 98 changed files with 1,621 additions and 33 deletions.
77 changes: 77 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "jco"
version.workspace = true
edition.workspace = true
version = { workspace = true }
edition = { workspace = true }
publish = false

[[bin]]
Expand All @@ -13,6 +13,7 @@ members = [
"crates/js-component-bindgen",
"crates/js-component-bindgen-component",
"crates/wasm-tools-component",
"crates/test-utils",
"xtask",
]
resolver = "2"
Expand All @@ -28,6 +29,7 @@ heck = { version = "0.4", features = ["unicode"] }
indexmap = "2.0"
js-component-bindgen = { path = "./crates/js-component-bindgen" }
structopt = "0.3.25"
tempdir = "0.3.7"
wasm-encoder = "0.35.0"
wasm-metadata = "0.10.9"
wasmparser = "0.115.0"
Expand All @@ -38,3 +40,10 @@ wit-bindgen = { version = "0.13.0" }
wit-bindgen-core = { version = "0.13.0" }
wit-component = { version = "0.16.0", features = ["dummy-module"] }
wit-parser = "0.12.1"
xshell = "0.2.5"

[dev-dependencies]
anyhow = { workspace = true }
tempdir = { workspace = true }
xshell = { workspace = true }
test-utils = { path = "./crates/test-utils" }
12 changes: 12 additions & 0 deletions crates/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "test-utils"
authors = ["Yosh Wuyts <[email protected]>", "Guy Bedford <[email protected]>"]
publish = false

version = { workspace = true }
edition = { workspace = true }

[dependencies]
anyhow = { workspace = true }
xshell = { workspace = true }
tempdir = { workspace = true }
25 changes: 25 additions & 0 deletions crates/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use anyhow::anyhow;
use std::{fs::File, path::PathBuf};
use tempdir::TempDir;
use xshell::{cmd, Shell};

/// Compile a `.wasm` file to `.wasm.component` file using `jco`.
pub fn compile(sh: &Shell, tmpdir: &TempDir, file_name: &str) -> anyhow::Result<PathBuf> {
let src_file: PathBuf =
format!("./submodules/wasmtime/target/wasm32-wasi/release/{file_name}.wasm").parse()?;
if !src_file.exists() {
return Err(anyhow!("src: {src_file:?} does not exists on disk"));
}

let out_dir = tmpdir.path();
let dest_file = out_dir.join(format!("{file_name}.component.wasm"));
File::create(&dest_file)?;

cmd!(
sh,
"./src/jco.js new {src_file} --wasi-command -o {dest_file}"
)
.run()?;

Ok(dest_file)
}
15 changes: 15 additions & 0 deletions tests/generated/api_proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn api_proxy() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "api_proxy";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/api_reactor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn api_reactor() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "api_reactor";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/api_read_only.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn api_read_only() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "api_read_only";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/api_time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn api_time() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "api_time";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/cli_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn cli_args() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "cli_args";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/cli_default_clocks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn cli_default_clocks() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "cli_default_clocks";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/cli_directory_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn cli_directory_list() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "cli_directory_list";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/cli_env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn cli_env() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "cli_env";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/cli_exit_default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn cli_exit_default() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "cli_exit_default";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/cli_exit_failure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn cli_exit_failure() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "cli_exit_failure";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/cli_exit_panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn cli_exit_panic() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "cli_exit_panic";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/cli_exit_success.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn cli_exit_success() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "cli_exit_success";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
15 changes: 15 additions & 0 deletions tests/generated/cli_export_cabi_realloc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This file has been auto-generated, please do not modify manually
//! To regenerate this file re-run `cargo xtask generate tests` from the project root

use tempdir::TempDir;
use xshell::{cmd, Shell};

#[test]
fn cli_export_cabi_realloc() -> anyhow::Result<()> {
let sh = Shell::new()?;
let file_name = "cli_export_cabi_realloc";
let tempdir = TempDir::new("{file_name}")?;
let wasi_file = test_utils::compile(&sh, &tempdir, &file_name)?;
cmd!(sh, "./src/jco.js run {wasi_file}").run()?;
Ok(())
}
Loading

0 comments on commit 5f321ef

Please sign in to comment.