parent
0d75723f91
commit
6ff8752be5
52 changed files with 464 additions and 324 deletions
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
##
|
||||
## can_alias_specialised_generic Nimrod Module
|
||||
##
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
import strutils
|
||||
|
||||
const
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
type
|
||||
TDict[TK, TV] = object
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
type
|
||||
TMatcherKind = enum
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
# Compiles:
|
||||
|
||||
type
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
# We start with a comment
|
||||
# This is the same comment
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
when defined(windows):
|
||||
import winlean
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
type
|
||||
TA = object
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
type
|
||||
PNode = ref TNode
|
||||
TNode = tuple[self: PNode]
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
import math, algorithm
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import strtabs
|
||||
|
||||
var tab = newStringTable(["key1", "val1", "key2", "val2"],
|
||||
var tab = newStringTable({"key1": "val1", "key2": "val2"},
|
||||
modeStyleInsensitive)
|
||||
for i in 0..80:
|
||||
tab["key_" & $i] = "value" & $i
|
||||
|
|
|
|||
|
|
@ -24,3 +24,19 @@ var
|
|||
ha = 1
|
||||
echo(ha)
|
||||
|
||||
|
||||
# Test identifier generation:
|
||||
template prefix(name: expr): expr = `"hu" name`
|
||||
|
||||
var `hu "XYZ"` = "yay"
|
||||
|
||||
echo prefix(XYZ)
|
||||
|
||||
template typedef(name: expr, typ: typeDesc) =
|
||||
type
|
||||
`T name`* = typ
|
||||
`P name`* = ref `T name`
|
||||
|
||||
typedef(myint, int)
|
||||
var x: PMyInt
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
discard """
|
||||
file: "tassert.nim"
|
||||
output: "assertion failure!this shall be always written"
|
||||
outputsub: "assertion failure!this shall be always written"
|
||||
"""
|
||||
# test assert and exception handling
|
||||
|
||||
proc callB() = assert(False)
|
||||
proc callA() = callB()
|
||||
proc callC() = callA()
|
||||
|
||||
try:
|
||||
callC()
|
||||
except EAssertionFailed:
|
||||
write(stdout, "assertion failure!")
|
||||
except:
|
||||
write(stdout, "unknown exception!")
|
||||
finally:
|
||||
system.write(stdout, "this shall be always written")
|
||||
|
||||
assert(false) #OUT assertion failure!this shall be always written
|
||||
# test assert and exception handling
|
||||
|
||||
proc callB() = assert(False)
|
||||
proc callA() = callB()
|
||||
proc callC() = callA()
|
||||
|
||||
try:
|
||||
callC()
|
||||
except EAssertionFailed:
|
||||
write(stdout, "assertion failure!")
|
||||
except:
|
||||
write(stdout, "unknown exception!")
|
||||
finally:
|
||||
system.write(stdout, "this shall be always written")
|
||||
|
||||
assert(false) #OUT assertion failure!this shall be always written
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
file: "tcgbug.nim"
|
||||
output: ""
|
||||
output: "success"
|
||||
"""
|
||||
|
||||
type
|
||||
|
|
@ -19,5 +19,5 @@ var
|
|||
new(a)
|
||||
q(a)
|
||||
|
||||
|
||||
echo "success"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
discard """
|
||||
file: "tclosure.nim"
|
||||
output: "2 4 6 8 10"
|
||||
disabled: true
|
||||
"""
|
||||
# Test the closure implementation
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
file: "tcontinuexc.nim"
|
||||
output: "ECcaught"
|
||||
outputsub: "ECcaught"
|
||||
"""
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
discard """
|
||||
file: "texcsub.nim"
|
||||
output: "caught!"
|
||||
disabled: true
|
||||
"""
|
||||
# Test inheritance for exception matching:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
discard """
|
||||
output: "Key: 12 value: 12Key: 13 value: 13 Key: A value: 12 Key: B value: 13"
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
# test explicit type instantiation
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
file: "tfloat1.nim"
|
||||
output: "Error: unhandled exception: FPU operation caused an overflow [EFloatOverflow]"
|
||||
outputsub: "Error: unhandled exception: FPU operation caused an overflow [EFloatOverflow]"
|
||||
"""
|
||||
# Test new floating point exceptions
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
file: "tfloat2.nim"
|
||||
output: "Error: unhandled exception: FPU operation caused a NaN result [EFloatInvalidOp]"
|
||||
outputsub: "Error: unhandled exception: FPU operation caused a NaN result [EFloatInvalidOp]"
|
||||
"""
|
||||
# Test new floating point exceptions
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ proc add*[T](heap: PBinHeap[T], priority: int, data: T) =
|
|||
|
||||
proc print*[T](heap: PBinHeap[T]) =
|
||||
for i in countup(0, heap.last):
|
||||
echo heap.heap[i].data
|
||||
stdout.write($heap.heap[i].data, " ")
|
||||
|
||||
var
|
||||
heap: PBinHeap[int]
|
||||
|
|
|
|||
|
|
@ -19,30 +19,12 @@ proc createMatrix*(width, height: int): TMatrix =
|
|||
proc width*(m: TMatrix): int {.inline.} = return m.fWidth
|
||||
proc height*(m: TMatrix): int {.inline.} = return m.fHeight
|
||||
|
||||
proc `[,]`*(m: TMatrix, x, y: int): float {.inline.} =
|
||||
proc `[]`*(m: TMatrix, x, y: int): float {.inline.} =
|
||||
result = m.data[x|y]
|
||||
|
||||
proc `[,]=`*(m: var TMatrix, x, y: int, val: float) {.inline.} =
|
||||
proc `[]=`*(m: var TMatrix, x, y: int, val: float) {.inline.} =
|
||||
m.data[x|y] = val
|
||||
|
||||
proc `[$ .. $, $ .. $]`*(m: TMatrix, a, b, c, d: int): TMatrix =
|
||||
result = createMatrix(b-a+1, d-c+1)
|
||||
for x in a..b:
|
||||
for y in c..d:
|
||||
result[x-a, y-c] = m[x, y]
|
||||
|
||||
proc `[$ .. $, $ .. $]=`*(m: var TMatrix, a, b, c, d: int, val: float) =
|
||||
for x in a..b:
|
||||
for y in c..d:
|
||||
m[x, y] = val
|
||||
|
||||
proc `[$ .. $, $ .. $]=`*(m: var TMatrix, a, b, c, d: int, val: TMatrix) =
|
||||
assert val.width == b-a+1
|
||||
assert val.height == d-c+1
|
||||
for x in a..b:
|
||||
for y in c..d:
|
||||
m[x, y] = val[x-a, y-c]
|
||||
|
||||
proc `-|`*(m: TMatrix): TMatrix =
|
||||
## transposes a matrix
|
||||
result = createMatrix(m.height, m.width)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
file: "toverflw2.nim"
|
||||
output: "Error: unhandled exception: over- or underflow [EOverflow]"
|
||||
outputsub: "Error: unhandled exception: over- or underflow [EOverflow]"
|
||||
"""
|
||||
var a : int32 = 2147483647
|
||||
var b : int32 = 2147483647
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
file: "treraise.nim"
|
||||
output: "Error: unhandled exception: bla [ESomeOtherErr]"
|
||||
outputsub: "Error: unhandled exception: bla [ESomeOtherErr]"
|
||||
"""
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
file: "tunhandledexc.nim"
|
||||
output: "Error: unhandled exception: bla [ESomeOtherErr]"
|
||||
outputsub: "Error: unhandled exception: bla [ESomeOtherErr]"
|
||||
"""
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
file: "twrongexc.nim"
|
||||
output: "Error: unhandled exception [EInvalidValue]"
|
||||
outputsub: "Error: unhandled exception [EInvalidValue]"
|
||||
"""
|
||||
try:
|
||||
raise newException(EInvalidValue, "")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
discard """
|
||||
file: "system.nim"
|
||||
line: 599
|
||||
errormsg: "type mismatch"
|
||||
"""
|
||||
# BUG: following compiles, but should not:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
discard """
|
||||
file: "trectype.nim"
|
||||
line: 25
|
||||
errormsg: "internal error: cannot generate C type for: PA"
|
||||
"""
|
||||
# Test recursive type descriptions
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
discard """
|
||||
file: "ttypelessemptyset.nim"
|
||||
line: 5
|
||||
errormsg: "internal error: invalid kind for last(tyEmpty)"
|
||||
"""
|
||||
var q = false
|
||||
discard (if q: {} else: {})
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ type
|
|||
msg: string
|
||||
err: bool
|
||||
disabled: bool
|
||||
substr: bool
|
||||
TResults {.pure.} = object
|
||||
total, passed, skipped: int
|
||||
data: string
|
||||
|
|
@ -53,7 +54,7 @@ proc extractSpec(filename: string): string =
|
|||
if a >= 0 and b > a:
|
||||
result = x.copy(a+3, b-1).replace("'''", tripleQuote)
|
||||
else:
|
||||
echo "warning: file does not contain spec: " & filename
|
||||
#echo "warning: file does not contain spec: " & filename
|
||||
result = ""
|
||||
|
||||
template parseSpecAux(fillResult: stmt) =
|
||||
|
|
@ -87,6 +88,9 @@ proc parseSpec(filename: string): TSpec =
|
|||
of "file": result.file = e.value
|
||||
of "line": discard parseInt(e.value, result.line)
|
||||
of "output": result.outp = e.value
|
||||
of "outputsub":
|
||||
result.outp = e.value
|
||||
result.substr = true
|
||||
of "errormsg", "msg": result.msg = e.value
|
||||
of "disabled": result.disabled = parseCfgBool(e.value)
|
||||
of "cmd": result.cmd = e.value
|
||||
|
|
@ -184,9 +188,10 @@ proc listResults(reject, compile, run: TResults) =
|
|||
proc cmpMsgs(r: var TResults, expected, given: TSpec, test: string) =
|
||||
if strip(expected.msg) notin strip(given.msg):
|
||||
r.addResult(test, expected.msg, given.msg, reFailure)
|
||||
elif extractFilename(expected.file) != extractFilename(given.file):
|
||||
elif extractFilename(expected.file) != extractFilename(given.file) and
|
||||
"internal error:" notin expected.msg:
|
||||
r.addResult(test, expected.file, given.file, reFailure)
|
||||
elif expected.line != given.line:
|
||||
elif expected.line != given.line and expected.line != 0:
|
||||
r.addResult(test, $expected.line, $given.line, reFailure)
|
||||
else:
|
||||
r.addResult(test, expected.msg, given.msg, reSuccess)
|
||||
|
|
@ -206,7 +211,21 @@ proc reject(r: var TResults, dir, options: string) =
|
|||
var given = callCompiler(expected.cmd, test, options)
|
||||
cmpMsgs(r, expected, given, t)
|
||||
|
||||
proc compile(r: var TResults, pattern, options: string) =
|
||||
proc compile(r: var TResults, pattern, options: string) =
|
||||
for test in os.walkFiles(pattern):
|
||||
var t = extractFilename(test)
|
||||
echo t
|
||||
inc(r.total)
|
||||
var expected = parseSpec(test)
|
||||
if expected.disabled:
|
||||
r.addResult(t, "", reIgnored)
|
||||
inc(r.skipped)
|
||||
else:
|
||||
var given = callCompiler(expected.cmd, test, options)
|
||||
r.addResult(t, given.msg, if given.err: reFailure else: reSuccess)
|
||||
if not given.err: inc(r.passed)
|
||||
|
||||
proc compileExample(r: var TResults, pattern, options: string) =
|
||||
for test in os.walkFiles(pattern):
|
||||
var t = extractFilename(test)
|
||||
inc(r.total)
|
||||
|
|
@ -233,6 +252,7 @@ proc run(r: var TResults, dir, options: string) =
|
|||
if existsFile(exeFile):
|
||||
var buf = myExec(exeFile)
|
||||
var success = strip(buf) == strip(expected.outp)
|
||||
if expected.substr: success = expected.outp in buf
|
||||
if success: inc(r.passed)
|
||||
r.addResult(t, expected.outp,
|
||||
buf, if success: reSuccess else: reFailure)
|
||||
|
|
@ -250,8 +270,8 @@ for i in 1.. paramCount():
|
|||
|
||||
reject(rejectRes, "tests/reject", options)
|
||||
compile(compileRes, "tests/accept/compile/t*.nim", options)
|
||||
compile(compileRes, "examples/*.nim", options)
|
||||
compile(compileRes, "examples/gtk/*.nim", options)
|
||||
compileExample(compileRes, "examples/*.nim", options)
|
||||
compileExample(compileRes, "examples/gtk/*.nim", options)
|
||||
run(runRes, "tests/accept/run", options)
|
||||
listResults(rejectRes, compileRes, runRes)
|
||||
openDefaultBrowser(resultsFile)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue