From 2d54b850894004ad8116f804b6c0c2f013a5b7a2 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 27 Oct 2011 23:25:34 +0200 Subject: [PATCH] compilation cache: tests now part of test suite --- lib/core/typeinfo.nim | 4 +++ tests/rodfiles/aconv.nim | 9 +++++++ tests/rodfiles/amethods.nim | 13 ++++++++++ tests/rodfiles/bconv.nim | 9 +++++++ tests/rodfiles/bmethods.nim | 30 +++++++++++++++++++++++ tests/rodfiles/bmethods2.nim | 30 +++++++++++++++++++++++ tests/rodfiles/deada.nim | 9 +++++++ tests/rodfiles/deada2.nim | 13 ++++++++++ tests/rodfiles/deadb.nim | 7 ++++++ tests/rodfiles/deadg.nim | 10 ++++++++ tests/rodfiles/gtkex1.nim | 14 +++++++++++ tests/rodfiles/gtkex2.nim | 22 +++++++++++++++++ tests/rodfiles/hallo.nim | 6 +++++ tests/rodfiles/hallo2.nim | 17 +++++++++++++ tests/rodfiles/int2bool.nim | 5 ++++ tests/rodfiles/tester.nim | 30 ----------------------- tests/tester.nim | 47 ++++++++++++++++++++++++++++++++++++ todo.txt | 15 ++++-------- web/index.txt | 6 ----- 19 files changed, 250 insertions(+), 46 deletions(-) create mode 100644 tests/rodfiles/aconv.nim create mode 100644 tests/rodfiles/amethods.nim create mode 100644 tests/rodfiles/bconv.nim create mode 100644 tests/rodfiles/bmethods.nim create mode 100644 tests/rodfiles/bmethods2.nim create mode 100644 tests/rodfiles/deada.nim create mode 100644 tests/rodfiles/deada2.nim create mode 100644 tests/rodfiles/deadb.nim create mode 100644 tests/rodfiles/deadg.nim create mode 100755 tests/rodfiles/gtkex1.nim create mode 100755 tests/rodfiles/gtkex2.nim create mode 100755 tests/rodfiles/hallo.nim create mode 100644 tests/rodfiles/hallo2.nim create mode 100644 tests/rodfiles/int2bool.nim delete mode 100644 tests/rodfiles/tester.nim diff --git a/lib/core/typeinfo.nim b/lib/core/typeinfo.nim index b216fee0c9..8f2a08855d 100755 --- a/lib/core/typeinfo.nim +++ b/lib/core/typeinfo.nim @@ -11,8 +11,12 @@ ## Note that even though ``TAny`` and its operations hide the nasty low level ## details from its clients, it remains inherently unsafe! +{.push hints: off.} + include "system/hti.nim" +{.pop.} + type TAnyKind* = enum ## what kind of ``any`` it is akNone = 0, ## invalid any diff --git a/tests/rodfiles/aconv.nim b/tests/rodfiles/aconv.nim new file mode 100644 index 0000000000..ffd8f36486 --- /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 0000000000..c51d27d249 --- /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 0000000000..2289a7f972 --- /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 0000000000..f665efa097 --- /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 0000000000..c4b9c37b6c --- /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 0000000000..dca7766405 --- /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 0000000000..ee8298371d --- /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 0000000000..776a07ac74 --- /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 0000000000..97bfbed4f7 --- /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 0000000000..8f4db4a408 --- /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 0000000000..3d181ba124 --- /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 0000000000..ac45be9fad --- /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 0000000000..a4b3957ecd --- /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 0000000000..e6add98489 --- /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 d2b5a1581d..0000000000 --- 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 1981dd066c..f0e48c4e6e 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) diff --git a/todo.txt b/todo.txt index 8419e1d091..a04a9aa9e8 100755 --- a/todo.txt +++ b/todo.txt @@ -18,12 +18,6 @@ incremental compilation - the loading has to be MUCH more lazy! --> next version: We should re-load symbol.ast lazily -- automate tests: - - test basic recompilation scheme - - test type converters - - test G, A, B example from the documentation; test init sections - - test method generation - - test DLL interfacing version 0.9.0 @@ -34,7 +28,8 @@ version 0.9.0 - unsigned ints and bignums; requires abstract integer literal type - implement the high level optimizer - warning for implicit openArray -> varargs convention -- implement explicit varargs +- implement explicit varargs; **but** ``len(varargs)`` problem remains! + --> solve by implicit conversion from varargs to openarray - tests: run the GC tests - change overloading resolution - implement closures; implement proper coroutines @@ -60,7 +55,7 @@ Bugs var x: int result = forward(x) -- bug: DLL generation is broken +- bug: DLL generation is broken; write at least a basic test - bug: stress testing basic method example (eval example) without ``-d:relase`` leaks memory; good way to figure out how a fixed amount of stack can hold an arbitrary number of GC roots! @@ -73,10 +68,9 @@ version 0.9.XX - implicit ref/ptr->var conversion; the compiler may store an object implicitly on the heap for write barrier efficiency; better: proc specialization in the code gen -- adapt thread var emulation to care about the new merge operation - EcmaScript needs a new and better code gen: simply adapt the C code gen to it - tlastmod returns wrong results on BSD (Linux, MacOS X: works) -- nested tuple unpacking +- nested tuple unpacking; tuple unpacking in non-var-context - 'nimrod def': does not always work? - test branch coverage - checked exceptions @@ -128,6 +122,7 @@ Low priority - resizing of strings/sequences could take into account the memory that is allocated - timeout for locks +- adapt thread var emulation to care about the new merge operation Version 2 diff --git a/web/index.txt b/web/index.txt index c4c8f2f972..2b1e3b9e88 100755 --- a/web/index.txt +++ b/web/index.txt @@ -111,9 +111,3 @@ Version 0.9.0 * 2-phase type system for better interaction between macros, templates and overloading -Planned features beyond 1.0 -=========================== - -* Other code generators: LLVM, EcmaScript. -* Symbol files to make the compiler incremental. -