mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-18 23:11:36 +00:00
compilation cache: tests now part of test suite
This commit is contained in:
@@ -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
|
||||
|
||||
9
tests/rodfiles/aconv.nim
Normal file
9
tests/rodfiles/aconv.nim
Normal file
@@ -0,0 +1,9 @@
|
||||
discard """
|
||||
output: "ugly conversion successful"
|
||||
"""
|
||||
|
||||
import int2bool
|
||||
|
||||
if 4:
|
||||
echo "ugly conversion successful"
|
||||
|
||||
13
tests/rodfiles/amethods.nim
Normal file
13
tests/rodfiles/amethods.nim
Normal file
@@ -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
|
||||
|
||||
9
tests/rodfiles/bconv.nim
Normal file
9
tests/rodfiles/bconv.nim
Normal file
@@ -0,0 +1,9 @@
|
||||
discard """
|
||||
output: "ugly conversion successful 2"
|
||||
"""
|
||||
|
||||
import int2bool
|
||||
|
||||
if 4:
|
||||
echo "ugly conversion successful 2"
|
||||
|
||||
30
tests/rodfiles/bmethods.nim
Normal file
30
tests/rodfiles/bmethods.nim
Normal file
@@ -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
|
||||
|
||||
30
tests/rodfiles/bmethods2.nim
Normal file
30
tests/rodfiles/bmethods2.nim
Normal file
@@ -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
|
||||
|
||||
9
tests/rodfiles/deada.nim
Normal file
9
tests/rodfiles/deada.nim
Normal file
@@ -0,0 +1,9 @@
|
||||
discard """
|
||||
output: '''
|
||||
246
|
||||
'''
|
||||
"""
|
||||
|
||||
import deadg, deadb
|
||||
|
||||
|
||||
13
tests/rodfiles/deada2.nim
Normal file
13
tests/rodfiles/deada2.nim
Normal file
@@ -0,0 +1,13 @@
|
||||
discard """
|
||||
output: '''
|
||||
246
|
||||
xyzabc
|
||||
'''
|
||||
"""
|
||||
|
||||
import deadg, deadb
|
||||
|
||||
# now add call to previously unused proc p2:
|
||||
echo p2("xyz", "abc")
|
||||
|
||||
|
||||
7
tests/rodfiles/deadb.nim
Normal file
7
tests/rodfiles/deadb.nim
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
import deadg
|
||||
|
||||
|
||||
echo p1(123, 123)
|
||||
|
||||
|
||||
10
tests/rodfiles/deadg.nim
Normal file
10
tests/rodfiles/deadg.nim
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
{.deadCodeElim: on.}
|
||||
|
||||
proc p1*(x, y: int): int =
|
||||
result = x + y
|
||||
|
||||
proc p2*(x, y: string): string =
|
||||
result = x & y
|
||||
|
||||
|
||||
14
tests/rodfiles/gtkex1.nim
Executable file
14
tests/rodfiles/gtkex1.nim
Executable file
@@ -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()
|
||||
22
tests/rodfiles/gtkex2.nim
Executable file
22
tests/rodfiles/gtkex2.nim
Executable file
@@ -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()
|
||||
|
||||
6
tests/rodfiles/hallo.nim
Executable file
6
tests/rodfiles/hallo.nim
Executable file
@@ -0,0 +1,6 @@
|
||||
discard """
|
||||
output: "Hello World"
|
||||
"""
|
||||
|
||||
echo "Hello World"
|
||||
|
||||
17
tests/rodfiles/hallo2.nim
Normal file
17
tests/rodfiles/hallo2.nim
Normal file
@@ -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
|
||||
|
||||
5
tests/rodfiles/int2bool.nim
Normal file
5
tests/rodfiles/int2bool.nim
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
converter uglyToBool*(x: int): bool =
|
||||
result = x != 0
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
15
todo.txt
15
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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user