summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-11-18 22:14:32 +0100
committerAraq <rumpf_a@web.de>2011-11-18 22:14:32 +0100
commita497b4d1cf529b24ac469e701cb60e8d8b5fdefc (patch)
tree867eb30d869f96ab3bec0908f62e1f26bc187a82 /tests
parentc9b67f724d039437ea72f666018d2a80266b8a2b (diff)
downloadNim-a497b4d1cf529b24ac469e701cb60e8d8b5fdefc.tar.gz
bugfix: fixed memory leaks in osproc module
Diffstat (limited to 'tests')
-rw-r--r--tests/specials.nim138
-rwxr-xr-xtests/tester.nim116
-rw-r--r--tests/threads/tactors.nim13
-rwxr-xr-xtests/threads/threadex.nim5
-rwxr-xr-xtests/threads/tthreadanalysis2.nim2
5 files changed, 165 insertions, 109 deletions
diff --git a/tests/specials.nim b/tests/specials.nim
new file mode 100644
index 000000000..eadd0d887
--- /dev/null
+++ b/tests/specials.nim
@@ -0,0 +1,138 @@
+#
+#
+#            Nimrod Tester
+#        (c) Copyright 2011 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+## Include for the tester that contains test suites that test special features
+## of the compiler.
+
+# ---------------- ROD file tests ---------------------------------------------
+
+const
+  rodfilesDir = "tests/rodfiles"
+
+proc delNimCache() = removeDir(rodfilesDir / "nimcache")
+proc plusCache(options: string): string = return options & " --symbolFiles:on"
+
+proc runRodFiles(r: var TResults, options: string) =
+  template test(filename: expr): stmt =
+    runSingleTest(r, rodfilesDir / filename, options)
+  
+  var options = options.plusCache
+  delNimCache()
+  
+  # test basic recompilation scheme:
+  test "hallo"
+  test "hallo"
+  # test incremental type information:
+  test "hallo2"
+  delNimCache()
+  
+  # test type converters:
+  test "aconv"
+  test "bconv"
+  delNimCache()
+  
+  # test G, A, B example from the documentation; test init sections:
+  test "deada"
+  test "deada2"
+  delNimCache()
+  
+  # test method generation:
+  test "bmethods"
+  test "bmethods2"
+  delNimCache()
+  
+  # test generics:
+  test "tgeneric1"
+  test "tgeneric2"
+  delNimCache()
+
+proc compileRodFiles(r: var TResults, options: string) =
+  template test(filename: expr): stmt =
+    compileSingleTest(r, rodfilesDir / filename, options)
+    
+  var options = options.plusCache
+  delNimCache()
+  # test DLL interfacing:
+  test "gtkex1"
+  test "gtkex2"
+  delNimCache()
+
+# --------------------- DLL generation tests ----------------------------------
+
+proc runBasicDLLTest(c, r: var TResults, options: string) =
+  compileSingleTest c, "lib/nimrtl.nim", options & " --app:lib -d:createNimRtl"
+  compileSingleTest c, "tests/dll/server.nim", 
+    options & " --app:lib -d:useNimRtl"
+  
+  when defined(Windows): 
+    # windows looks in the dir of the exe (yay!):
+    var nimrtlDll = DynlibFormat % "nimrtl"
+    copyFile("lib" / nimrtlDll, "tests/dll" / nimrtlDll)
+  else:
+    # posix relies on crappy LD_LIBRARY_PATH (ugh!):
+    var libpath = getenv"LD_LIBRARY_PATH".string
+    if peg"\i '/nimrod' (!'/')* '/lib'" notin libpath:
+      echo "[Warning] insufficient LD_LIBRARY_PATH"
+    var serverDll = DynlibFormat % "server"
+    copyFile("tests/dll" / serverDll, "lib" / serverDll)
+  
+  runSingleTest r, "tests/dll/client.nim", options & " -d:useNimRtl"
+
+proc runDLLTests(r: var TResults, options: string) =
+  # dummy compile result:
+  var c = initResults()
+  
+  runBasicDLLTest c, r, options
+  runBasicDLLTest c, r, options & " -d:release"
+  runBasicDLLTest c, r, options & " --gc:boehm"
+  runBasicDLLTest c, r, options & " -d:release --gc:boehm"
+  
+# ------------------------------ GC tests -------------------------------------
+
+proc runGcTests(r: var TResults, options: string) =
+  template test(filename: expr): stmt =
+    runSingleTest(r, "tests/gc" / filename, options)
+    runSingleTest(r, "tests/gc" / filename, options & " -d:release")
+  
+  test "gcbench"
+  test "gcleak"
+  test "gcleak2"
+  test "gctest"
+  # disabled for now as it somehow runs very slowly ('delete' bug?) but works:
+  test "gcleak3"
+  
+
+# ------------------------- threading tests -----------------------------------
+
+proc runThreadTests(r: var TResults, options: string) =
+  template test(filename: expr): stmt =
+    runSingleTest(r, "tests/threads" / filename, options)
+    runSingleTest(r, "tests/threads" / filename, options & " -d:release")
+    runSingleTest(r, "tests/threads" / filename, options & " -tlsEmulation:on")
+  
+  test "tactors"
+  #test "threadex"
+  #test "threadring"
+  #test "tthreadanalysis"
+  #test "tthreadanalysis2"
+  #test "tthreadsort"
+
+# ------------------------- register special tests here -----------------------
+proc runSpecialTests(r: var TResults, options: string) =
+  runRodFiles(r, options)
+  runDLLTests(r, options)
+  runGCTests(r, options)
+  runThreadTests(r, options & " --threads:on")
+
+proc rejectSpecialTests(r: var TResults, options: string) =
+  
+
+proc compileSpecialTests(r: var TResults, options: string) =
+  nil
+
diff --git a/tests/tester.nim b/tests/tester.nim
index 76543d0ea..7dd023cb0 100755
--- a/tests/tester.nim
+++ b/tests/tester.nim
@@ -18,7 +18,7 @@ const
   resultsFile = "testresults.html"
   jsonFile = "testresults.json"
   Usage = "usage: tester reject|compile|examples|run|merge [nimrod options]\n" &
-          "   or: tester test singleTest"
+          "   or: tester test|comp|rej singleTest"
 
 type
   TTestAction = enum
@@ -104,7 +104,8 @@ proc parseSpec(filename: string): TSpec =
 # ----------------------------------------------------------------------------
 
 var
-  pegLineError = peg"{[^(]*} '(' {\d+} ', ' \d+ ') Error:' \s* {.*}"
+  pegLineError = 
+    peg"{[^(]*} '(' {\d+} ', ' \d+ ') ' ('Error'/'Warning') ':' \s* {.*}"
   pegOtherError = peg"'Error:' \s* {.*}"
   pegSuccess = peg"'Hint: operation successful'.*"
   pegOfInterest = pegLineError / pegOtherError / pegSuccess
@@ -118,7 +119,7 @@ proc callCompiler(cmdTemplate, filename, options: string): TSpec =
   while running(p) or not atEnd(outp):
     var x = outp.readLine().string
     if x =~ pegOfInterest:
-      # `s` should contain the last error message
+      # `s` should contain the last error/warning message
       s = x
   close(p)
   result.msg = ""
@@ -290,104 +291,7 @@ proc runSingleTest(r: var TResults, test, options: string) =
 proc run(r: var TResults, dir, options: string) =
   for test in os.walkFiles(dir / "t*.nim"): runSingleTest(r, test, options)
 
-# ---------------- ROD file tests ---------------------------------------------
-
-const
-  rodfilesDir = "tests/rodfiles"
-
-proc delNimCache() = removeDir(rodfilesDir / "nimcache")
-proc plusCache(options: string): string = return options & " --symbolFiles:on"
-
-proc runRodFiles(r: var TResults, options: string) =
-  template test(filename: expr): stmt =
-    runSingleTest(r, rodfilesDir / filename, options)
-  
-  var options = options.plusCache
-  delNimCache()
-  
-  # test basic recompilation scheme:
-  test "hallo"
-  test "hallo"
-  # test incremental type information:
-  test "hallo2"
-  delNimCache()
-  
-  # test type converters:
-  test "aconv"
-  test "bconv"
-  delNimCache()
-  
-  # test G, A, B example from the documentation; test init sections:
-  test "deada"
-  test "deada2"
-  delNimCache()
-  
-  # test method generation:
-  test "bmethods"
-  test "bmethods2"
-  delNimCache()
-  
-  # test generics:
-  test "tgeneric1"
-  test "tgeneric2"
-  delNimCache()
-
-proc compileRodFiles(r: var TResults, options: string) =
-  template test(filename: expr): stmt =
-    compileSingleTest(r, rodfilesDir / filename, options)
-    
-  var options = options.plusCache
-  delNimCache()
-  # test DLL interfacing:
-  test "gtkex1"
-  test "gtkex2"
-  delNimCache()
-
-# --------------------- DLL generation tests ----------------------------------
-
-proc runBasicDLLTest(c, r: var TResults, options: string) =
-  compileSingleTest c, "lib/nimrtl.nim", options & " --app:lib -d:createNimRtl"
-  compileSingleTest c, "tests/dll/server.nim", 
-    options & " --app:lib -d:useNimRtl"
-  
-  when defined(Windows): 
-    # windows looks in the dir of the exe (yay!):
-    var nimrtlDll = DynlibFormat % "nimrtl"
-    copyFile("lib" / nimrtlDll, "tests/dll" / nimrtlDll)
-  else:
-    # posix relies on crappy LD_LIBRARY_PATH (ugh!):
-    var libpath = getenv"LD_LIBRARY_PATH".string
-    if peg"\i '/nimrod' (!'/')* '/lib'" notin libpath:
-      echo "[Warning] insufficient LD_LIBRARY_PATH"
-    var serverDll = DynlibFormat % "server"
-    copyFile("tests/dll" / serverDll, "lib" / serverDll)
-  
-  runSingleTest r, "tests/dll/client.nim", options & " -d:useNimRtl"
-
-proc runDLLTests(r: var TResults, options: string) =
-  # dummy compile result:
-  var c = initResults()
-  
-  runBasicDLLTest c, r, options
-  runBasicDLLTest c, r, options & " -d:release"
-  runBasicDLLTest c, r, options & " --gc:boehm"
-  runBasicDLLTest c, r, options & " -d:release --gc:boehm"
-  
-# ------------------------------ GC tests -------------------------------------
-
-proc runGcTests(r: var TResults, options: string) =
-  template test(filename: expr): stmt =
-    runSingleTest(r, "tests/gc" / filename, options)
-    runSingleTest(r, "tests/gc" / filename, options & " -d:release")
-  
-  test "gcbench"
-  test "gcleak"
-  test "gcleak2"
-  test "gctest"
-  # disabled for now as it somehow runs very slowly ('delete' bug?) but works:
-  test "gcleak3"
-  
-# -----------------------------------------------------------------------------
+include specials
    
 proc compileExample(r: var TResults, pattern, options: string) =
   for test in os.walkFiles(pattern): compileSingleTest(r, test, options)
@@ -440,9 +344,7 @@ proc main() =
   of "run":
     var runRes = initResults()
     run(runRes, "tests/accept/run", p.cmdLineRest.string)
-    runRodFiles(runRes, p.cmdLineRest.string)
-    runDLLTests(runRes, p.cmdLineRest.string)
-    runGCTests(runRes, p.cmdLineRest.string)
+    runSpecialTests(runRes, p.cmdLineRest.string)
     writeResults(runJson, runRes)
   of "merge":
     var rejectRes = readResults(rejectJson)
@@ -458,14 +360,14 @@ proc main() =
     var r = initResults()
     runGCTests(r, p.cmdLineRest.string)
     echo r.data, r
-  of "test":
+  of "test", "comp", "rej":
     var r = initResults()
     if p.kind != cmdArgument: quit usage
     var testFile = p.key.string
     p.next()
-    if peg"'/reject/'" in testFile:
+    if peg"'/reject/'" in testFile or action == "rej":
       rejectSingleTest(r, testFile, p.cmdLineRest.string)
-    elif peg"'/compile/'" in testFile:
+    elif peg"'/compile/'" in testFile or action == "comp":
       compileSingleTest(r, testFile, p.cmdLineRest.string)
     else:
       runSingleTest(r, testFile, p.cmdLineRest.string)
diff --git a/tests/threads/tactors.nim b/tests/threads/tactors.nim
new file mode 100644
index 000000000..d6297d6bc
--- /dev/null
+++ b/tests/threads/tactors.nim
@@ -0,0 +1,13 @@
+discard """
+  outputsub: "150"
+"""
+
+import actors
+
+var
+  a: TActorPool[int, void]
+createActorPool(a)
+for i in 0 .. < 300:
+  a.spawn(i, proc (x: int) {.thread.} = echo x)
+a.join()
+
diff --git a/tests/threads/threadex.nim b/tests/threads/threadex.nim
index d8b4a94fb..5b8055413 100755
--- a/tests/threads/threadex.nim
+++ b/tests/threads/threadex.nim
@@ -1,3 +1,6 @@
+discard """
+  output: ""
+"""
 
 type
   TMsgKind = enum
@@ -18,7 +21,7 @@ proc consume() {.thread.} =
       x.backTo.send(printedLines)
       break
     echo x.data
-    discard atomicInc(printedLines)
+    atomicInc(printedLines)
 
 proc produce() =
   var m: TMsg
diff --git a/tests/threads/tthreadanalysis2.nim b/tests/threads/tthreadanalysis2.nim
index 95f39723f..bc071b478 100755
--- a/tests/threads/tthreadanalysis2.nim
+++ b/tests/threads/tthreadanalysis2.nim
@@ -1,6 +1,6 @@
 discard """
   file: "tthreadanalysis2.nim"
-  line: 45
+  line: 42
   errormsg: "write to foreign heap"
   cmd: "nimrod cc --hints:on --threads:on $# $#"
 """