summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/specials.nim16
-rwxr-xr-xtests/tester.nim25
2 files changed, 38 insertions, 3 deletions
diff --git a/tests/specials.nim b/tests/specials.nim
index da2013e02..073ea0d27 100644
--- a/tests/specials.nim
+++ b/tests/specials.nim
@@ -169,6 +169,22 @@ proc compileDebuggerTests(r: var TResults, options: string) =
   compileSingleTest(r, "tools/nimgrep", options & 
                     " --debugger:on")
 
+# ------------------------- JS tests ------------------------------------------
+
+proc runJsTests(r: var TResults, options: string) =
+  template test(filename: expr): stmt =
+    runSingleTest(r, filename, options & " -d:nodejs", targetJS)
+    runSingleTest(r, filename, options & " -d:nodejs -d:release", targetJS)
+    
+  # tactiontable, texceptions, texcpt1, texcsub, tfinally, tfinally2,
+  # tfinally3
+  for t in os.walkFiles("tests/js/t*.nim"):
+    test(t)
+  test "tests/run/tactiontable"
+  test "tests/run/tmultim1"
+  test "tests/run/tmultim3"
+  test "tests/run/tmultim4"
+
 # ------------------------- register special tests here -----------------------
 proc runSpecialTests(r: var TResults, options: string) =
   runRodFiles(r, options)
diff --git a/tests/tester.nim b/tests/tester.nim
index a26b7c178..be0765874 100755
--- a/tests/tester.nim
+++ b/tests/tester.nim
@@ -261,7 +261,10 @@ proc compileSingleTest(r: var TResults, test, options: string) =
   r.addResult(t, given.msg, if given.err: reFailure else: reSuccess)
   if not given.err: inc(r.passed)
 
-proc runSingleTest(r: var TResults, test, options: string) =
+type
+  TTarget = enum targetC, targetJS
+
+proc runSingleTest(r: var TResults, test, options: string, target: TTarget) =
   var test = test.addFileExt(".nim")
   var t = extractFilename(test)
   echo t
@@ -275,9 +278,16 @@ proc runSingleTest(r: var TResults, test, options: string) =
     if given.err:
       r.addResult(t, "", given.msg, reFailure)
     else:
-      var exeFile = changeFileExt(test, ExeExt)
+      var exeFile: string
+      if target == targetC:
+        exeFile = changeFileExt(test, ExeExt)
+      else:
+        let (dir, file, ext) = splitFile(test)
+        exeFile = dir / "nimcache" / file & ".js"
+      
       if existsFile(exeFile):
-        var (buf, exitCode) = execCmdEx(exeFile)
+        var (buf, exitCode) = execCmdEx(
+          (if target==targetJS: "node " else: "") & exeFile)
         if exitCode != expected.ExitCode:
           r.addResult(t, "exitcode: " & $expected.ExitCode,
                          "exitcode: " & $exitCode, reFailure)
@@ -291,6 +301,9 @@ proc runSingleTest(r: var TResults, test, options: string) =
       else:
         r.addResult(t, expected.outp, "executable not found", reFailure)
 
+proc runSingleTest(r: var TResults, test, options: string) =
+  runSingleTest(r, test, options, targetC)
+  
 proc run(r: var TResults, dir, options: string) =
   for test in os.walkFiles(dir / "t*.nim"): runSingleTest(r, test, options)
 
@@ -350,6 +363,12 @@ proc main() =
     run(runRes, "tests/run", p.cmdLineRest.string)
     runSpecialTests(runRes, p.cmdLineRest.string)
     writeResults(runJson, runRes)
+  of "js":
+    var runRes = initResults()
+    if existsFile(runJSon):
+      runRes = readResults(runJson)
+    runJsTests(runRes, p.cmdLineRest.string)
+    writeResults(runJson, runRes)
   of "merge":
     var rejectRes = readResults(rejectJson)
     var compileRes = readResults(compileJson)