|
| 1 | +#![cfg_attr(target_arch = "wasm32", no_std)] // Enables no_std only for WASM builds. |
| 2 | + |
| 3 | +extern crate alloc; // Enables heap allocation without the standard library. |
| 4 | + |
1 | 5 | #[cfg(target_arch = "wasm32")] |
2 | 6 | mod runtime { |
3 | 7 | use lol_alloc::LeakingPageAllocator; |
@@ -51,6 +55,7 @@ mod runtime { |
51 | 55 | } else { |
52 | 56 | crate::modules::vm::optimizer::constant_fold(&mut chunk); |
53 | 57 | let mut vm = VM::with_limits(&chunk, Limits::sandbox()); |
| 58 | + vm.strict_input = true; |
54 | 59 | // Feed input buffer from host |
55 | 60 | let inp_len = unsafe { INP_LEN }; |
56 | 61 | if inp_len > 0 { |
@@ -112,22 +117,31 @@ mod tests { |
112 | 117 | assert!(errs.is_empty(), "parse error on {:?}: {:?}", case.src, errs.iter().map(|e| &e.msg).collect::<Vec<_>>()); |
113 | 118 |
|
114 | 119 | let mut vm = VM::new(&chunk); |
| 120 | + vm.strict_input = true; |
| 121 | + // Cases that supply an input buffer feed the VM normally; the |
| 122 | + // strict_input flag only triggers when the VM tries to read past |
| 123 | + // the end of the buffer (i.e. the WASM "no host data" path). |
115 | 124 | vm.input_buffer = case.input.clone(); |
116 | | - // WASM: input tests should produce a RuntimeError |
117 | | - let expect_input_error = case.input.len() > 0 && cfg!(target_arch = "wasm32"); |
| 125 | + let expects_input_error = case.input.is_empty() |
| 126 | + && (case.src.contains("input(") || case.src.contains("input (")); |
118 | 127 |
|
119 | 128 | match vm.run() { |
120 | 129 | Ok(_) => { |
| 130 | + assert!( |
| 131 | + !expects_input_error, |
| 132 | + "expected input() to error under WASM strict mode for: {:?}", case.src |
| 133 | + ); |
121 | 134 | assert_eq!(vm.output, case.output, "output mismatch on: {:?}", case.src); |
122 | 135 | } |
123 | 136 | Err(e) => match &case.error { |
124 | 137 | Some(expected) => assert!( |
125 | 138 | e.to_string().contains(expected.as_str()), |
126 | 139 | "wrong error on {:?}: got '{}', expected '{}'", case.src, e, expected |
127 | 140 | ), |
128 | | - None if expect_input_error => assert!( |
| 141 | + None if expects_input_error => assert!( |
129 | 142 | e.to_string().contains("input"), |
130 | | - "expected input RuntimeError on wasm32 for: {:?}", case.src |
| 143 | + "expected input RuntimeError under WASM strict mode for: {:?}, got: {}", |
| 144 | + case.src, e |
131 | 145 | ), |
132 | 146 | None => panic!("VM error on {:?}: {}", case.src, e), |
133 | 147 | } |
|
0 commit comments