Wasm: change TypeSection tests to unit tests rather than integration tests

This commit is contained in:
Brian Carroll 2022-01-08 15:17:52 +00:00
parent 8e7f398e50
commit d88b86e884
2 changed files with 44 additions and 20 deletions

View file

@ -752,14 +752,14 @@ impl<'a> WasmModule<'a> {
}
}
/// Assertion to run on the generated Wasm module in every test
pub fn test_assert_preload<'a>(arena: &'a Bump, wasm_module: &WasmModule<'a>) {
test_assert_types_preload(arena, &wasm_module.types);
}
#[cfg(test)]
mod tests {
use super::*;
use bumpalo::{self, collections::Vec, Bump};
fn test_assert_types_preload<'a>(arena: &'a Bump, original: &TypeSection<'a>) {
fn test_assert_types_preload<'a>(arena: &'a Bump, original: &TypeSection<'a>) {
// Serialize the Type section that we built from Roc code
let mut original_serialized = Vec::with_capacity_in(original.bytes.len() + 10, arena);
let mut original_serialized = Vec::with_capacity_in(6 + original.bytes.len(), arena);
original.serialize(&mut original_serialized);
debug_assert!(original_serialized[0] == SectionId::Type as u8);
@ -770,4 +770,30 @@ fn test_assert_types_preload<'a>(arena: &'a Bump, original: &TypeSection<'a>) {
debug_assert_eq!(original.offsets, preloaded.offsets);
debug_assert_eq!(original.bytes, preloaded.bytes);
}
#[test]
fn test_type_section() {
use ValueType::*;
let arena = &Bump::new();
let signatures = [
Signature {
param_types: bumpalo::vec![in arena],
ret_type: None,
},
Signature {
param_types: bumpalo::vec![in arena; I32, I64, F32, F64],
ret_type: None,
},
Signature {
param_types: bumpalo::vec![in arena; I32, I32, I32],
ret_type: Some(I32),
},
];
let mut section = TypeSection::new(arena, signatures.len());
for sig in signatures {
section.insert(sig);
}
test_assert_types_preload(arena, &section);
}
}

View file

@ -135,8 +135,6 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32TestResult>(
T::insert_test_wrapper(arena, &mut wasm_module, TEST_WRAPPER_NAME, main_fn_index);
roc_gen_wasm::wasm_module::sections::test_assert_preload(arena, &wasm_module);
let needs_linking = !wasm_module.import.entries.is_empty();
let mut app_module_bytes = std::vec::Vec::with_capacity(4096);