(executables
 (names test_toplevel1 test_toplevel2)
 (libraries js_of_ocaml js_of_ocaml_toplevel re)
 (flags
  (:standard -linkall))
 (modes byte))

(rule
 (targets export.txt)
 (deps
  (package js_of_ocaml-toplevel))
 (action
  (run jsoo_listunits -o %{targets} stdlib js_of_ocaml-toplevel re)))

(rule
 (target re.cmis.js)
 (action
  (run jsoo_mkcmis -o %{target} re)))

(rule
 (targets test_toplevel1.js)
 (action
  (run
   %{bin:js_of_ocaml}
   --export
   %{dep:export.txt}
   --toplevel
   --disable
   shortvar
   -w
   no-missing-effects-backend
   %{dep:test_toplevel1.bc}
   -o
   %{targets})))

(rule
 (targets test_toplevel2.js)
 (action
  (run
   %{bin:js_of_ocaml}
   --toplevel
   --no-cmis
   --disable
   shortvar
   -w
   no-missing-effects-backend
   %{dep:test_toplevel2.bc}
   -o
   %{targets})))

(rule
 (target test_toplevel1.actual)
 (deps test_toplevel1.js re.cmis.js)
 (action
  (with-stdout-to
   %{target}
   (run node ./test_toplevel1.js))))

(rule
 (target test_toplevel2.actual)
 (deps test_toplevel2.js re.cmis.js)
 (action
  (with-stdout-to
   %{target}
   (run node ./test_toplevel2.js))))

(rule
 (alias runtest-js)
 (action
  (diff test_toplevel.expected test_toplevel1.actual)))

(rule
 (alias runtest-js)
 (action
  (diff test_toplevel.expected test_toplevel2.actual)))

(rule
 (alias runtest)
 (action
  (run jsoo_mkcmis -o a.js --no-runtime stdlib)))
