summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/rodfiles/aconv.nim9
-rw-r--r--tests/rodfiles/amethods.nim13
-rw-r--r--tests/rodfiles/bconv.nim9
-rw-r--r--tests/rodfiles/bmethods.nim30
-rw-r--r--tests/rodfiles/bmethods2.nim30
-rw-r--r--tests/rodfiles/deada.nim9
-rw-r--r--tests/rodfiles/deada2.nim13
-rw-r--r--tests/rodfiles/deadb.nim7
-rw-r--r--tests/rodfiles/deadg.nim10
-rwxr-xr-xtests/rodfiles/gtkex1.nim14
-rwxr-xr-xtests/rodfiles/gtkex2.nim22
-rwxr-xr-xtests/rodfiles/hallo.nim6
-rw-r--r--tests/rodfiles/hallo2.nim17
-rw-r--r--tests/rodfiles/int2bool.nim5
-rw-r--r--tests/rodfiles/tester.nim30
-rwxr-xr-xtests/tester.nim47
16 files changed, 241 insertions, 30 deletions
diff --git a/tests/rodfiles/aconv.nim b/tests/rodfiles/aconv.nim
new file mode 100644
index 000000000..ffd8f3648
--- /dev/null
+++ b/tests/rodfiles/aconv.nim
@@ -0,0 +1,9 @@
+discard """
+  output: "ugly conversion successful"
+"""
+
+import int2bool
+
+if 4:
+  echo "ugly conversion successful"
+
diff --git a/tests/rodfiles/amethods.nim b/tests/rodfiles/amethods.nim
new file mode 100644
index 000000000..c51d27d24
--- /dev/null
+++ b/tests/rodfiles/amethods.nim
@@ -0,0 +1,13 @@
+
+type
+  TBaseClass* = object of TObject
+
+proc newBaseClass*: ref TBaseClass =
+  new result
+  
+method echoType*(x: ref TBaseClass) =
+  echo "base class"
+
+proc echoAlias*(x: ref TBaseClass) =
+  echoType x
+
diff --git a/tests/rodfiles/bconv.nim b/tests/rodfiles/bconv.nim
new file mode 100644
index 000000000..2289a7f97
--- /dev/null
+++ b/tests/rodfiles/bconv.nim
@@ -0,0 +1,9 @@
+discard """
+  output: "ugly conversion successful 2"
+"""
+
+import int2bool
+
+if 4:
+  echo "ugly conversion successful 2"
+
diff --git a/tests/rodfiles/bmethods.nim b/tests/rodfiles/bmethods.nim
new file mode 100644
index 000000000..f665efa09
--- /dev/null
+++ b/tests/rodfiles/bmethods.nim
@@ -0,0 +1,30 @@
+discard """
+  output: '''
+derived class
+base class
+'''
+"""
+
+import amethods
+
+
+type
+  TDerivedClass* = object of TBaseClass
+
+proc newDerivedClass: ref TDerivedClass =
+  new result
+  
+method echoType*(x: ref TDerivedClass) =
+  echo "derived class"
+
+var b, d: ref TBaseClass
+
+b = newBaseClass()
+d = newDerivedClass()
+
+#b.echoType()
+#d.echoType()
+
+echoAlias d
+echoAlias b
+
diff --git a/tests/rodfiles/bmethods2.nim b/tests/rodfiles/bmethods2.nim
new file mode 100644
index 000000000..c4b9c37b6
--- /dev/null
+++ b/tests/rodfiles/bmethods2.nim
@@ -0,0 +1,30 @@
+discard """
+  output: '''
+derived class 2
+base class
+'''
+"""
+
+import amethods
+
+
+type
+  TDerivedClass* = object of TBaseClass
+
+proc newDerivedClass: ref TDerivedClass =
+  new result
+  
+method echoType*(x: ref TDerivedClass) =
+  echo "derived class 2"
+
+var b, d: ref TBaseClass
+
+b = newBaseClass()
+d = newDerivedClass()
+
+#b.echoType()
+#d.echoType()
+
+echoAlias d
+echoAlias b
+
diff --git a/tests/rodfiles/deada.nim b/tests/rodfiles/deada.nim
new file mode 100644
index 000000000..dca776640
--- /dev/null
+++ b/tests/rodfiles/deada.nim
@@ -0,0 +1,9 @@
+discard """
+  output: '''
+246
+'''
+"""
+
+import deadg, deadb
+
+
diff --git a/tests/rodfiles/deada2.nim b/tests/rodfiles/deada2.nim
new file mode 100644
index 000000000..ee8298371
--- /dev/null
+++ b/tests/rodfiles/deada2.nim
@@ -0,0 +1,13 @@
+discard """
+  output: '''
+246
+xyzabc
+'''
+"""
+
+import deadg, deadb
+
+# now add call to previously unused proc p2:
+echo p2("xyz", "abc")
+
+
diff --git a/tests/rodfiles/deadb.nim b/tests/rodfiles/deadb.nim
new file mode 100644
index 000000000..776a07ac7
--- /dev/null
+++ b/tests/rodfiles/deadb.nim
@@ -0,0 +1,7 @@
+
+import deadg
+
+
+echo p1(123, 123)
+
+
diff --git a/tests/rodfiles/deadg.nim b/tests/rodfiles/deadg.nim
new file mode 100644
index 000000000..97bfbed4f
--- /dev/null
+++ b/tests/rodfiles/deadg.nim
@@ -0,0 +1,10 @@
+
+{.deadCodeElim: on.}
+
+proc p1*(x, y: int): int =
+  result = x + y
+  
+proc p2*(x, y: string): string =
+  result = x & y
+  
+
diff --git a/tests/rodfiles/gtkex1.nim b/tests/rodfiles/gtkex1.nim
new file mode 100755
index 000000000..8f4db4a40
--- /dev/null
+++ b/tests/rodfiles/gtkex1.nim
@@ -0,0 +1,14 @@
+import 

+  cairo, glib2, gtk2

+

+proc destroy(widget: pWidget, data: pgpointer) {.cdecl.} =

+  main_quit()

+

+var

+  window: pWidget

+nimrod_init()

+window = window_new(WINDOW_TOPLEVEL)

+discard signal_connect(window, "destroy",

+                       SIGNAL_FUNC(gtkex1.destroy), nil)

+show(window)

+main()

diff --git a/tests/rodfiles/gtkex2.nim b/tests/rodfiles/gtkex2.nim
new file mode 100755
index 000000000..3d181ba12
--- /dev/null
+++ b/tests/rodfiles/gtkex2.nim
@@ -0,0 +1,22 @@
+
+import 
+  glib2, gtk2
+
+proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = 
+  main_quit()
+
+var 
+  window: PWidget
+  button: PWidget
+
+nimrod_init()
+window = window_new(WINDOW_TOPLEVEL)
+button = button_new("Click me")
+set_border_width(PContainer(Window), 5)
+add(PContainer(window), button)
+discard signal_connect(window, "destroy", 
+                           SIGNAL_FUNC(gtkex2.destroy), nil)
+show(button)
+show(window)
+main()
+
diff --git a/tests/rodfiles/hallo.nim b/tests/rodfiles/hallo.nim
new file mode 100755
index 000000000..ac45be9fa
--- /dev/null
+++ b/tests/rodfiles/hallo.nim
@@ -0,0 +1,6 @@
+discard """
+  output: "Hello World"
+"""
+
+echo "Hello World"
+
diff --git a/tests/rodfiles/hallo2.nim b/tests/rodfiles/hallo2.nim
new file mode 100644
index 000000000..a4b3957ec
--- /dev/null
+++ b/tests/rodfiles/hallo2.nim
@@ -0,0 +1,17 @@
+discard """
+  output: "Hello World"
+"""
+
+# Test incremental type information
+
+type
+  TNode = object {.pure.}
+    le, ri: ref TNode
+    data: string
+
+proc newNode(data: string): ref TNode =
+  new(result)
+  result.data = data
+  
+echo newNode("Hello World").data
+
diff --git a/tests/rodfiles/int2bool.nim b/tests/rodfiles/int2bool.nim
new file mode 100644
index 000000000..e6add9848
--- /dev/null
+++ b/tests/rodfiles/int2bool.nim
@@ -0,0 +1,5 @@
+
+converter uglyToBool*(x: int): bool =
+  result = x != 0
+
+
diff --git a/tests/rodfiles/tester.nim b/tests/rodfiles/tester.nim
deleted file mode 100644
index d2b5a1581..000000000
--- a/tests/rodfiles/tester.nim
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-#
-#            Nimrod Tester
-#        (c) Copyright 2011 Andreas Rumpf
-#
-#    See the file "copying.txt", included in this
-#    distribution, for details about the copyright.
-#
-
-## This program tests Nimrod's ROD file mechanism.
-
-import
-  parseutils, strutils, pegs, os, osproc, streams, parsecfg, browsers, json,
-  marshal, cgi
-
-const
-  cmdTemplate = r"nimrod cc --hints:on $# $#"
-  resultsFile = "testresults.html"
-  jsonFile = "testresults.json"
-  Usage = "usage: tester reject|compile|examples|run|merge [nimrod options]"
-
-proc myExec(cmd: string): string =
-  result = osproc.execProcess(cmd)
-
-var
-  pegLineError = peg"{[^(]*} '(' {\d+} ', ' \d+ ') Error:' \s* {.*}"
-  pegOtherError = peg"'Error:' \s* {.*}"
-  pegSuccess = peg"'Hint: operation successful'.*"
-  pegOfInterest = pegLineError / pegOtherError / pegSuccess
-
diff --git a/tests/tester.nim b/tests/tester.nim
index 1981dd066..f0e48c4e6 100755
--- a/tests/tester.nim
+++ b/tests/tester.nim
@@ -267,6 +267,51 @@ 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) =
+  var options = options.plusCache
+  delNimCache()
+  
+  # test basic recompilation scheme:
+  runSingleTest(r, rodfilesDir / "hallo", options)
+  runSingleTest(r, rodfilesDir / "hallo", options)
+  # test incremental type information:
+  runSingleTest(r, rodfilesDir / "hallo2", options)
+  delNimCache()
+  
+  # test type converters:
+  runSingleTest(r, rodfilesDir / "aconv", options)
+  runSingleTest(r, rodfilesDir / "bconv", options)
+  delNimCache()
+  
+  # test G, A, B example from the documentation; test init sections:
+  runSingleTest(r, rodfilesDir / "deada", options)
+  runSingleTest(r, rodfilesDir / "deada2", options)
+  delNimCache()
+  
+  # test method generation:
+  runSingleTest(r, rodfilesDir / "bmethods", options)
+  runSingleTest(r, rodfilesDir / "bmethods2", options)
+  delNimCache()
+  
+
+proc compileRodFiles(r: var TResults, options: string) =
+  var options = options.plusCache
+  delNimCache()
+  # test DLL interfacing:
+  compileSingleTest(r, rodfilesDir / "gtkex1", options)
+  compileSingleTest(r, rodfilesDir / "gtkex2", options)
+  delNimCache()
+
+# -----------------------------------------------------------------------------
+
 proc compileExample(r: var TResults, pattern, options: string) =
   for test in os.walkFiles(pattern): compileSingleTest(r, test, options)
 
@@ -303,6 +348,7 @@ proc main(action: string) =
     var compileRes = initResults()
     compile(compileRes, "tests/accept/compile/t*.nim", options)
     compile(compileRes, "tests/ecmas.nim", options)
+    compileRodFiles(compileRes, options)
     writeResults(compileJson, compileRes)
   of "examples":
     var compileRes = readResults(compileJson)
@@ -313,6 +359,7 @@ proc main(action: string) =
   of "run":
     var runRes = initResults()
     run(runRes, "tests/accept/run", options)
+    runRodFiles(runRes, options)
     writeResults(runJson, runRes)
   of "merge":
     var rejectRes = readResults(rejectJson)