Skip to content

Commit

Permalink
Fix codegen tests
Browse files Browse the repository at this point in the history
While working on the new C# codegen, I accidentally noticed that those tests were passing even when they clearly should've been failing due to changed output.

After running with `--nocapture`, I found out it's because the tests are silently skipped and reported as successful when `rust_wasm_test.wasm` isn't built.

This further led to finding that `rust_wasm_test.wasm` is never built - the relevant module results in `rust_wasm_test_module.wasm` instead - so these tests have been incorrectly passing for ages.

This PR changes them to actually build the module as part of testing and updates the snapshots to latest master.
  • Loading branch information
RReverser committed Apr 23, 2024
1 parent e1064ee commit 76745d2
Show file tree
Hide file tree
Showing 5 changed files with 1,224 additions and 408 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ wasmtime.workspace = true

[dev-dependencies]
insta.workspace = true
spacetimedb-testing = { path = "../testing" }

[features]
standalone = ["spacetimedb-standalone"]
Expand Down
34 changes: 12 additions & 22 deletions crates/cli/tests/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use spacetimedb_cli::generate;
use spacetimedb_data_structures::map::HashMap;
use spacetimedb_testing::modules::{CompilationMode, CompiledModule};
use std::path::Path;
use std::sync::OnceLock;

fn compiled_module() -> &'static Path {
static COMPILED_MODULE: OnceLock<CompiledModule> = OnceLock::new();
COMPILED_MODULE
.get_or_init(|| CompiledModule::compile("rust-wasm-test", CompilationMode::Debug))
.path()
}

#[test]
fn test_codegen_output() {
let path = Path::new(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../target/wasm32-unknown-unknown/release/rust_wasm_test.wasm"
));
if !path.exists() {
eprintln!("rust_wasm_test isn't built, skipping");
return;
}
use spacetimedb_cli::generate;
println!("{}", path.to_str().unwrap());
let outfiles: HashMap<_, _> = generate::generate(path, generate::Language::Csharp, "SpacetimeDB")
let outfiles: HashMap<_, _> = generate::generate(compiled_module(), generate::Language::Csharp, "SpacetimeDB")
.unwrap()
.into_iter()
.collect();
Expand All @@ -24,17 +24,7 @@ fn test_codegen_output() {

#[test]
fn test_typescript_codegen_output() {
let path = Path::new(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../target/wasm32-unknown-unknown/release/rust_wasm_test.wasm"
));
if !path.exists() {
eprintln!("rust_wasm_test isn't built, skipping");
return;
}
use spacetimedb_cli::generate;
println!("{}", path.to_str().unwrap());
let outfiles: HashMap<_, _> = generate::generate(path, generate::Language::TypeScript, "SpacetimeDB")
let outfiles: HashMap<_, _> = generate::generate(compiled_module(), generate::Language::TypeScript, "SpacetimeDB")
.unwrap()
.into_iter()
.collect();
Expand Down
Loading

0 comments on commit 76745d2

Please sign in to comment.