Skip to content

Commit

Permalink
Add export tests and catch duplicate exports in checker
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Aug 25, 2015
1 parent 7fcf6d1 commit 14b3b7f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
13 changes: 9 additions & 4 deletions ml-proto/src/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,14 @@ let check_table c tab =
List.iter (fun xI -> check_func_type (func c xI) s xI.at) xs;
{c with tables = c.tables @ [s]}

let check_export c ex =
let {name = _; func = x} = ex.it in
ignore (func c x)
module NameSet = Set.Make(String)

let check_export c set ex =
let {name; func = x} = ex.it in
ignore (func c x);
require (not (NameSet.mem name set)) ex.at
"duplicate export name";
NameSet.add name set

let check_segment size prev_end seg =
let seg_end = seg.it.Memory.addr + String.length seg.it.Memory.data in
Expand All @@ -295,4 +300,4 @@ let check_module m =
globals = List.map it globals} in
let c' = List.fold_left check_table c tables in
List.iter (check_func c') funcs;
List.iter (check_export c') exports
ignore (List.fold_left (check_export c') NameSet.empty exports)
9 changes: 0 additions & 9 deletions ml-proto/test/basic.wasm

This file was deleted.

22 changes: 22 additions & 0 deletions ml-proto/test/exports.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(module (func (const.i32 1)) (export "a" 0))
(module (func (const.i32 1)) (export "a" 0) (export "b" 0))
(module (func (const.i32 1)) (func (const.i32 2)) (export "a" 0) (export "b" 1))
(invalid
(module (func (const.i32 1)) (export "a" 1))
"unknown function 1")
(invalid
(module (func (const.i32 1)) (func (const.i32 2)) (export "a" 0) (export "a" 1))
"duplicate export name")
(invalid
(module (func (const.i32 1)) (export "a" 0) (export "a" 0))
"duplicate export name")

(module
(func $f (param $n i32) (result i32)
(return (add.i32 (getlocal $n) (const.i32 1)))
)

(export "e" $f)
)

(asserteq (invoke "e" (const.i32 42)) (const.i32 43))

0 comments on commit 14b3b7f

Please sign in to comment.