Skip to content

Commit

Permalink
Avoid duplicate module name in test and improve diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg committed Apr 25, 2023
1 parent 603d148 commit 09c8953
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
23 changes: 13 additions & 10 deletions interpreter/script/run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,14 @@ let modules : Ast.module_ Map.t ref = ref Map.empty
let instances : Instance.module_inst Map.t ref = ref Map.empty
let registry : Instance.module_inst Map.t ref = ref Map.empty

let bind map x_opt y =
let bind category map x_opt y =
let map' =
match x_opt with
| None -> !map
| Some x -> Map.add x.it y !map
| Some x ->
if Map.mem x.it !map then
IO.error x.at (category ^ " " ^ x.it ^ " already defined");
Map.add x.it y !map
in map := Map.add "" y map'

let lookup category map x_opt at =
Expand Down Expand Up @@ -518,13 +521,13 @@ let rec run_command cmd =
print_module x_opt m
end
end;
bind scripts x_opt [cmd];
bind modules x_opt m;
bind "module" modules x_opt m;
bind "script" scripts x_opt [cmd];
if not !Flags.dry then begin
trace "Initializing...";
let imports = Import.link m in
let inst = Eval.init m imports in
bind instances x_opt inst
bind "instance" instances x_opt inst
end

| Register (name, x_opt) ->
Expand Down Expand Up @@ -556,17 +559,17 @@ and run_meta cmd =
match cmd.it with
| Script (x_opt, script) ->
run_quote_script script;
bind scripts x_opt (lookup_script None cmd.at)
bind "script" scripts x_opt (lookup_script None cmd.at)

| Input (x_opt, file) ->
(try if not (input_file file run_quote_script) then
Abort.error cmd.at "aborting"
with Sys_error msg -> IO.error cmd.at msg);
bind scripts x_opt (lookup_script None cmd.at);
bind "script" scripts x_opt (lookup_script None cmd.at);
if x_opt <> None then begin
bind modules x_opt (lookup_module None cmd.at);
bind "module" modules x_opt (lookup_module None cmd.at);
if not !Flags.dry then begin
bind instances x_opt (lookup_instance None cmd.at)
bind "instance" instances x_opt (lookup_instance None cmd.at)
end
end

Expand All @@ -588,7 +591,7 @@ and run_quote_script script =
let save_quote = !quote in
quote := [];
(try run_script script with exn -> quote := save_quote; raise exn);
bind scripts None (List.rev !quote);
bind "script" scripts None (List.rev !quote);
quote := !quote @ save_quote

let run_file file = input_file file run_script
Expand Down
4 changes: 2 additions & 2 deletions test/core/annotations.wast
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
) (@a)
) (@a)

((@a) module (@a) $m (@a) (@a)
((@a) module (@a) $m1 (@a) (@a)
((@a) global (@a) $g (@a)
((@a) export (@a) "g" (@a)) (@a)
((@a) import (@a) "spectest" (@a) "global_i32" (@a)) (@a)
Expand All @@ -142,7 +142,7 @@
) (@a)
) (@a)

((@a) module (@a) $m (@a) (@a)
((@a) module (@a) $m2 (@a) (@a)
((@a) type (@a) $T (@a)
((@a) func (@a)
((@a) param (@a) i32 (@a) i64 (@a)) (@a)
Expand Down
11 changes: 5 additions & 6 deletions test/core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ class RunTests(unittest.TestCase):
def _runCommand(self, command, logPath, expectedExitCode = 0):
with open(logPath, 'w+') as out:
exitCode = subprocess.call(command, shell=True, stdout=out, stderr=subprocess.STDOUT)
if exitCode != expectedExitCode:
print("=== log ===")
subprocess.call("cat %s" % logPath, shell=True)
print("===========")
self.assertEqual(expectedExitCode, exitCode, "failed with exit code %i (expected %i) for %s" % (exitCode, expectedExitCode, command))
with open(logPath) as out:
log = out.read()
msg = "failed with exit code %i (expected %i)\nCommand:\n %s\nLog:\n%s"
self.assertEqual(expectedExitCode, exitCode, msg % (exitCode, expectedExitCode, command, log))

def _auxFile(self, path):
if os.path.exists(path):
Expand All @@ -64,7 +63,7 @@ def _compareFile(self, expectFile, actualFile):
with open(actualFile) as actual:
expectText = expect.read()
actualText = actual.read()
self.assertEqual(expectText, actualText)
self.assertEqual(expectText, actualText)

def _runTestFile(self, inputPath):
dir, inputFile = os.path.split(inputPath)
Expand Down

0 comments on commit 09c8953

Please sign in to comment.