mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-28 19:36:34 +00:00
Merge branch 'devel' into alloc-overloads
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
line: 21
|
||||
errormsg: "invalid type: 'TTable'"
|
||||
errormsg: "invalid type: 'TTable[string, proc (string)]'"
|
||||
"""
|
||||
|
||||
import tables
|
||||
|
||||
@@ -7,4 +7,4 @@ type
|
||||
proc ha() =
|
||||
var
|
||||
x: TExport # no error
|
||||
nil
|
||||
discard
|
||||
|
||||
@@ -4,4 +4,4 @@ type
|
||||
TExport* = enum x, y, z
|
||||
|
||||
proc foo*(x: int) =
|
||||
nil
|
||||
discard
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
type
|
||||
TExport* = enum x, y, z # exactly the same type!
|
||||
|
||||
proc foo*(x: int) = nil
|
||||
proc foo*(x: int) = discard
|
||||
|
||||
64
tests/async/tasyncawait.nim
Normal file
64
tests/async/tasyncawait.nim
Normal file
@@ -0,0 +1,64 @@
|
||||
discard """
|
||||
file: "tasyncawait.nim"
|
||||
cmd: "nimrod cc --hints:on $# $#"
|
||||
output: "5000"
|
||||
"""
|
||||
import asyncio2, sockets2, net, strutils
|
||||
|
||||
var disp = newDispatcher()
|
||||
var msgCount = 0
|
||||
|
||||
const
|
||||
swarmSize = 50
|
||||
messagesToSend = 100
|
||||
|
||||
var clientCount = 0
|
||||
|
||||
proc sendMessages(disp: PDispatcher, client: TSocketHandle): PFuture[int] {.async.} =
|
||||
for i in 0 .. <messagesToSend:
|
||||
discard await disp.send(client, "Message " & $i & "\c\L")
|
||||
|
||||
proc launchSwarm(disp: PDispatcher, port: TPort): PFuture[int] {.async.} =
|
||||
for i in 0 .. <swarmSize:
|
||||
var sock = socket()
|
||||
#disp.register(sock)
|
||||
discard await disp.connect(sock, "localhost", port)
|
||||
when true:
|
||||
discard await sendMessages(disp, sock)
|
||||
sock.close()
|
||||
else:
|
||||
# Issue #932: https://github.com/Araq/Nimrod/issues/932
|
||||
var msgFut = sendMessages(disp, sock)
|
||||
msgFut.callback =
|
||||
proc () =
|
||||
sock.close()
|
||||
|
||||
proc readMessages(disp: PDispatcher, client: TSocketHandle): PFuture[int] {.async.} =
|
||||
while true:
|
||||
var line = await disp.recvLine(client)
|
||||
if line == "":
|
||||
client.close()
|
||||
clientCount.inc
|
||||
break
|
||||
else:
|
||||
if line.startswith("Message "):
|
||||
msgCount.inc
|
||||
else:
|
||||
doAssert false
|
||||
|
||||
proc createServer(disp: PDispatcher, port: TPort): PFuture[int] {.async.} =
|
||||
var server = socket()
|
||||
#disp.register(server)
|
||||
server.bindAddr(port)
|
||||
server.listen()
|
||||
while true:
|
||||
discard readMessages(disp, await disp.accept(server))
|
||||
|
||||
discard disp.createServer(TPort(10335))
|
||||
discard disp.launchSwarm(TPort(10335))
|
||||
while true:
|
||||
disp.poll()
|
||||
if clientCount == swarmSize: break
|
||||
|
||||
assert msgCount == swarmSize * messagesToSend
|
||||
echo msgCount
|
||||
@@ -19,8 +19,8 @@ of eB, eC: write(stdout, "b or c")
|
||||
case x
|
||||
of "Andreas", "Rumpf": write(stdout, "Hallo Meister!")
|
||||
of "aa", "bb": write(stdout, "Du bist nicht mein Meister")
|
||||
of "cc", "hash", "when": nil
|
||||
of "will", "it", "finally", "be", "generated": nil
|
||||
of "cc", "hash", "when": discard
|
||||
of "will", "it", "finally", "be", "generated": discard
|
||||
|
||||
var z = case i
|
||||
of 1..5, 8, 9: "aa"
|
||||
|
||||
@@ -19,5 +19,18 @@ var
|
||||
new(a)
|
||||
q(a)
|
||||
|
||||
# bug #914
|
||||
var x = newWideCString("Hello")
|
||||
|
||||
echo "success"
|
||||
|
||||
|
||||
# bug #833
|
||||
|
||||
type
|
||||
PFuture*[T] = ref object
|
||||
value*: T
|
||||
finished*: bool
|
||||
cb: proc (future: PFuture[T]) {.closure.}
|
||||
|
||||
var k = PFuture[void]()
|
||||
|
||||
17
tests/collections/tsets.nim
Normal file
17
tests/collections/tsets.nim
Normal file
@@ -0,0 +1,17 @@
|
||||
discard """
|
||||
output: '''true
|
||||
true'''
|
||||
"""
|
||||
|
||||
import sets
|
||||
var
|
||||
a = initSet[int]()
|
||||
b = initSet[int]()
|
||||
c = initSet[string]()
|
||||
|
||||
for i in 0..5: a.incl(i)
|
||||
for i in 1..6: b.incl(i)
|
||||
for i in 0..5: c.incl($i)
|
||||
|
||||
echo map(a, proc(x: int): int = x + 1) == b
|
||||
echo map(a, proc(x: int): string = $x) == c
|
||||
@@ -24,3 +24,5 @@ ok supports(`+`, 34)
|
||||
|
||||
no compiles(4+5.0 * "hallo")
|
||||
|
||||
no compiles(undeclaredIdentifier)
|
||||
no compiles(undeclaredIdentifier)
|
||||
|
||||
@@ -12,7 +12,7 @@ var
|
||||
thr: array [0..5, TThread[tuple[a, b: int]]]
|
||||
L, M, N: TLock
|
||||
|
||||
proc doNothing() = nil
|
||||
proc doNothing() = discard
|
||||
|
||||
proc threadFunc(interval: tuple[a, b: int]) {.thread.} =
|
||||
doNothing()
|
||||
|
||||
@@ -12,6 +12,13 @@ myobj destroyed
|
||||
----
|
||||
mygeneric3 constructed
|
||||
mygeneric1 destroyed
|
||||
----
|
||||
mygeneric1 destroyed
|
||||
----
|
||||
myobj destroyed
|
||||
----
|
||||
----
|
||||
myobj destroyed
|
||||
'''
|
||||
"""
|
||||
|
||||
@@ -31,6 +38,22 @@ type
|
||||
x: A
|
||||
y: B
|
||||
z: C
|
||||
|
||||
TObjKind = enum A, B, C, D
|
||||
|
||||
TCaseObj = object
|
||||
case kind: TObjKind
|
||||
of A:
|
||||
x: TMyGeneric1[int]
|
||||
of B, C:
|
||||
y: TMyObj
|
||||
else:
|
||||
case innerKind: TObjKind
|
||||
of A, B, C:
|
||||
p: TMyGeneric3[int, float, string]
|
||||
of D:
|
||||
q: TMyGeneric3[TMyObj, int, int]
|
||||
r: string
|
||||
|
||||
proc destruct(o: var TMyObj) {.destructor.} =
|
||||
if o.p != nil: dealloc o.p
|
||||
@@ -57,13 +80,13 @@ proc mygeneric1() =
|
||||
echo "mygeneric1 constructed"
|
||||
|
||||
proc mygeneric2[T](val: T) =
|
||||
var
|
||||
a = open()
|
||||
b = TMyGeneric2[int, T](x: 10, y: val)
|
||||
c = TMyGeneric3[int, int, string](x: 10, y: 20, z: "test")
|
||||
|
||||
var a = open()
|
||||
|
||||
var b = TMyGeneric2[int, T](x: 10, y: val)
|
||||
echo "mygeneric2 constructed"
|
||||
|
||||
var c = TMyGeneric3[int, int, string](x: 10, y: 20, z: "test")
|
||||
|
||||
proc mygeneric3 =
|
||||
var x = TMyGeneric3[int, string, TMyGeneric1[int]](
|
||||
x: 10, y: "test", z: TMyGeneric1[int](x: 10))
|
||||
@@ -82,3 +105,24 @@ mygeneric2[int](10)
|
||||
echo "----"
|
||||
mygeneric3()
|
||||
|
||||
proc caseobj =
|
||||
block:
|
||||
echo "----"
|
||||
var o1 = TCaseObj(kind: A, x: TMyGeneric1[int](x: 10))
|
||||
|
||||
block:
|
||||
echo "----"
|
||||
var o2 = TCaseObj(kind: B, y: open())
|
||||
|
||||
block:
|
||||
echo "----"
|
||||
var o3 = TCaseObj(kind: D, innerKind: B, r: "test",
|
||||
p: TMyGeneric3[int, float, string](x: 10, y: 1.0, z: "test"))
|
||||
|
||||
block:
|
||||
echo "----"
|
||||
var o4 = TCaseObj(kind: D, innerKind: D, r: "test",
|
||||
q: TMyGeneric3[TMyObj, int, int](x: open(), y: 1, z: 0))
|
||||
|
||||
caseobj()
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ type
|
||||
PDict[TK, TV] = ref TDict[TK, TV]
|
||||
|
||||
proc fakeNew[T](x: var ref T, destroy: proc (a: ref T) {.nimcall.}) =
|
||||
nil
|
||||
discard
|
||||
|
||||
proc destroyDict[TK, TV](a: PDict[TK, TV]) =
|
||||
return
|
||||
|
||||
@@ -11,3 +11,19 @@ proc q[T](x, y: T): T {.discardable.} =
|
||||
p(8, 2)
|
||||
q[float](0.8, 0.2)
|
||||
|
||||
# bug #942
|
||||
|
||||
template maybeMod(x: Tinteger, module:Natural):expr =
|
||||
if module > 0: x mod module
|
||||
else: x
|
||||
|
||||
proc foo(b: int):int =
|
||||
var x = 1
|
||||
result = x.maybeMod(b) # Works fine
|
||||
|
||||
proc bar(b: int):int =
|
||||
result = 1
|
||||
result = result.maybeMod(b) # Error: value returned by statement has to be discarded
|
||||
|
||||
echo foo(0)
|
||||
echo bar(0)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
line: 10
|
||||
errormsg: "value returned by statement has to be discarded"
|
||||
errormsg: "value of type 'bool' has to be discarded"
|
||||
"""
|
||||
|
||||
proc p =
|
||||
|
||||
@@ -4,7 +4,7 @@ type
|
||||
PMenuItem = ref object
|
||||
|
||||
proc createMenuItem*(menu: PMenu, label: string,
|
||||
action: proc (i: PMenuItem, p: pointer) {.cdecl.}) = nil
|
||||
action: proc (i: PMenuItem, p: pointer) {.cdecl.}) = discard
|
||||
|
||||
var s: PMenu
|
||||
createMenuItem(s, "Go to definition...",
|
||||
|
||||
45
tests/exception/texceptionbreak.nim
Normal file
45
tests/exception/texceptionbreak.nim
Normal file
@@ -0,0 +1,45 @@
|
||||
discard """
|
||||
file: "tnestedbreak.nim"
|
||||
output: "1\n2\n3\n4"
|
||||
"""
|
||||
|
||||
# First variety
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
for y in [1, 2, 3]:
|
||||
discard
|
||||
try:
|
||||
discard
|
||||
except EOS:
|
||||
discard
|
||||
echo "1"
|
||||
|
||||
# Second Variety
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
for y in [1, 2, 3]:
|
||||
discard
|
||||
for y in [1, 2, 3]:
|
||||
discard
|
||||
|
||||
echo "2"
|
||||
|
||||
# Third Variety
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
block:
|
||||
break
|
||||
|
||||
echo "3"
|
||||
|
||||
# Fourth Variety
|
||||
block:
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
break
|
||||
|
||||
echo "4"
|
||||
40
tests/exception/tfinally4.nim
Normal file
40
tests/exception/tfinally4.nim
Normal file
@@ -0,0 +1,40 @@
|
||||
discard """
|
||||
file: "tfinally4.nim"
|
||||
output: "B1\nA1\n1\nB1\nB2\ncatch\nA1\n1\nB1\nA1\nA2\n2\nB1\nB2\ncatch\nA1\nA2\n0\nB1\nA1\n1\nB1\nB2\nA1\n1\nB1\nA1\nA2\n2\nB1\nB2\nA1\nA2\n3"
|
||||
"""
|
||||
|
||||
# More thorough test of return-in-finaly
|
||||
|
||||
var raiseEx = true
|
||||
var returnA = true
|
||||
var returnB = false
|
||||
|
||||
proc main: int =
|
||||
try: #A
|
||||
try: #B
|
||||
if raiseEx:
|
||||
raise newException(EOS, "")
|
||||
return 3
|
||||
finally: #B
|
||||
echo "B1"
|
||||
if returnB:
|
||||
return 2
|
||||
echo "B2"
|
||||
except EOS: #A
|
||||
echo "catch"
|
||||
finally: #A
|
||||
echo "A1"
|
||||
if returnA:
|
||||
return 1
|
||||
echo "A2"
|
||||
|
||||
for x in [true, false]:
|
||||
for y in [true, false]:
|
||||
for z in [true, false]:
|
||||
# echo "raiseEx: " & $x
|
||||
# echo "returnA: " & $y
|
||||
# echo "returnB: " & $z
|
||||
raiseEx = x
|
||||
returnA = y
|
||||
returnB = z
|
||||
echo main()
|
||||
40
tests/exception/tnestedreturn.nim
Normal file
40
tests/exception/tnestedreturn.nim
Normal file
@@ -0,0 +1,40 @@
|
||||
discard """
|
||||
file: "tnestedreturn.nim"
|
||||
output: "A\nB\nC\n"
|
||||
"""
|
||||
|
||||
# Various tests of return nested in double try/except statements
|
||||
|
||||
proc test1() =
|
||||
|
||||
finally: echo "A"
|
||||
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
return
|
||||
|
||||
test1()
|
||||
|
||||
|
||||
proc test2() =
|
||||
|
||||
finally: echo "B"
|
||||
|
||||
try:
|
||||
return
|
||||
except EOS:
|
||||
discard
|
||||
|
||||
test2()
|
||||
|
||||
proc test3() =
|
||||
try:
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
return
|
||||
finally:
|
||||
echo "C"
|
||||
|
||||
test3()
|
||||
20
tests/exception/tnestedreturn2.nim
Normal file
20
tests/exception/tnestedreturn2.nim
Normal file
@@ -0,0 +1,20 @@
|
||||
discard """
|
||||
file: "tnestedreturn.nim"
|
||||
outputsub: "Error: unhandled exception: Problem [EOS]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
|
||||
proc test4() =
|
||||
try:
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
return
|
||||
finally:
|
||||
discard
|
||||
|
||||
# Should cause unhandled exception error,
|
||||
# but could cause segmentation fault if
|
||||
# exceptions are not handled properly.
|
||||
test4()
|
||||
raise newException(EOS, "Problem")
|
||||
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
line: 10
|
||||
errormsg: "value returned by statement has to be discarded"
|
||||
errormsg: "value of type 'string' has to be discarded"
|
||||
"""
|
||||
|
||||
# bug #578
|
||||
|
||||
20
tests/exprs/tifexpr_typeinference.nim
Normal file
20
tests/exprs/tifexpr_typeinference.nim
Normal file
@@ -0,0 +1,20 @@
|
||||
#bug #712
|
||||
|
||||
import tables
|
||||
|
||||
proc test(): TTable[string, string] =
|
||||
discard
|
||||
|
||||
proc test2(): TTable[string, string] =
|
||||
discard
|
||||
|
||||
var x = 5
|
||||
let blah =
|
||||
case x
|
||||
of 5:
|
||||
test2()
|
||||
of 2:
|
||||
test()
|
||||
else: test()
|
||||
|
||||
echo blah.len
|
||||
@@ -1,9 +1,9 @@
|
||||
discard """
|
||||
file: "tstmtexp.nim"
|
||||
line: 8
|
||||
errormsg: "value returned by statement has to be discarded"
|
||||
errormsg: "value of type 'int literal(5)' has to be discarded"
|
||||
"""
|
||||
# Test 3
|
||||
|
||||
1+4 #ERROR_MSG value returned by statement has to be discarded
|
||||
1+4
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ when defined(GC_setMaxPause):
|
||||
GC_setMaxPause 2_000
|
||||
|
||||
type
|
||||
TExpr = object ## abstract base class for an expression
|
||||
TExpr = object {.inheritable.} ## abstract base class for an expression
|
||||
PLiteral = ref TLiteral
|
||||
TLiteral = object of TExpr
|
||||
x: int
|
||||
|
||||
25
tests/gc/gcleak5.nim
Normal file
25
tests/gc/gcleak5.nim
Normal file
@@ -0,0 +1,25 @@
|
||||
discard """
|
||||
output: "success"
|
||||
"""
|
||||
|
||||
import os, times
|
||||
|
||||
proc main =
|
||||
var i = 0
|
||||
for ii in 0..50_000:
|
||||
#while true:
|
||||
var t = getTime()
|
||||
var g = t.getGMTime()
|
||||
#echo isOnStack(addr g)
|
||||
|
||||
if i mod 100 == 0:
|
||||
let om = getOccupiedMem()
|
||||
#echo "memory: ", om
|
||||
if om > 100_000: quit "leak"
|
||||
|
||||
inc(i)
|
||||
sleep(1)
|
||||
|
||||
echo "success"
|
||||
|
||||
main()
|
||||
@@ -32,7 +32,7 @@ const
|
||||
proc len[T,D] (n:PNode[T,D]): Int {.inline.} =
|
||||
return n.Count
|
||||
|
||||
proc clean[T: TOrdinal|TNumber](o: var T) {.inline.} = nil
|
||||
proc clean[T: TOrdinal|TNumber](o: var T) {.inline.} = discard
|
||||
|
||||
proc clean[T: string|seq](o: var T) {.inline.} =
|
||||
o = nil
|
||||
@@ -98,7 +98,7 @@ proc DeleteItem[T,D] (n: PNode[T,D], x: Int): PNode[T,D] {.inline.} =
|
||||
of cLen3 : setLen(n.slots, cLen3)
|
||||
of cLenCenter : setLen(n.slots, cLenCenter)
|
||||
of cLen4 : setLen(n.slots, cLen4)
|
||||
else: nil
|
||||
else: discard
|
||||
Result = n
|
||||
|
||||
else :
|
||||
@@ -232,7 +232,7 @@ proc InsertItem[T,D](APath: RPath[T,D], ANode:PNode[T,D], AKey: T, AValue: D) =
|
||||
of cLen3: setLen(APath.Nd.slots, cLenCenter)
|
||||
of cLenCenter: setLen(APath.Nd.slots, cLen4)
|
||||
of cLen4: setLen(APath.Nd.slots, cLenMax)
|
||||
else: nil
|
||||
else: discard
|
||||
for i in countdown(APath.Nd.Count.int - 1, x + 1): shallowCopy(APath.Nd.slots[i], APath.Nd.slots[i - 1])
|
||||
APath.Nd.slots[x] = setItem(AKey, AValue, ANode)
|
||||
|
||||
|
||||
18
tests/generics/tgenericlambda.nim
Normal file
18
tests/generics/tgenericlambda.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
discard """
|
||||
output: "10\n10\n1\n2\n3"
|
||||
"""
|
||||
|
||||
proc test(x: proc (a, b: int): int) =
|
||||
echo x(5, 5)
|
||||
|
||||
test(proc (a, b): auto = a + b)
|
||||
|
||||
test do (a, b) -> auto: a + b
|
||||
|
||||
proc foreach[T](s: seq[T], body: proc(x: T)) =
|
||||
for e in s:
|
||||
body(e)
|
||||
|
||||
foreach(@[1,2,3]) do (x):
|
||||
echo x
|
||||
|
||||
@@ -6,6 +6,18 @@ var a: PA[string]
|
||||
new(a)
|
||||
a.field = "some string"
|
||||
|
||||
|
||||
proc someOther[T](len: string): seq[T] = discard
|
||||
proc someOther[T](len: int): seq[T] = echo "we"
|
||||
|
||||
proc foo[T](x: T) =
|
||||
var s = someOther[T](34)
|
||||
#newSeq[T](34)
|
||||
|
||||
foo 23
|
||||
|
||||
|
||||
|
||||
when false:
|
||||
# Compiles unless you use var a: PA[string]
|
||||
type
|
||||
|
||||
20
tests/generics/tinferredgenericprocs.nim
Normal file
20
tests/generics/tinferredgenericprocs.nim
Normal file
@@ -0,0 +1,20 @@
|
||||
discard """
|
||||
output: '''123
|
||||
1
|
||||
2
|
||||
3'''
|
||||
"""
|
||||
|
||||
# https://github.com/Araq/Nimrod/issues/797
|
||||
proc foo[T](s:T):string = $s
|
||||
|
||||
type IntStringProc = proc(x: int): string
|
||||
|
||||
var f1 = IntStringProc(foo)
|
||||
var f2: proc(x: int): string = foo
|
||||
var f3: IntStringProc = foo
|
||||
|
||||
echo f1(1), f2(2), f3(3)
|
||||
|
||||
for x in map([1,2,3], foo): echo x
|
||||
|
||||
18
tests/generics/tmetafield.nim
Normal file
18
tests/generics/tmetafield.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
discard """
|
||||
cmd: "nimrod check $# $#"
|
||||
msg: "'proc' is not a concrete type"
|
||||
msg: "'Foo' is not a concrete type."
|
||||
msg: "invalid type: 'TBaseMed'"
|
||||
"""
|
||||
|
||||
type
|
||||
Foo[T] = object
|
||||
x: T
|
||||
|
||||
TBaseMed = object
|
||||
doSmth: proc
|
||||
data: seq[Foo]
|
||||
|
||||
var a: TBaseMed
|
||||
|
||||
# issue 188
|
||||
15
tests/global/globalaux.nim
Normal file
15
tests/global/globalaux.nim
Normal file
@@ -0,0 +1,15 @@
|
||||
type
|
||||
TObj*[T] = object
|
||||
val*: T
|
||||
|
||||
var
|
||||
totalGlobals* = 0
|
||||
|
||||
proc makeObj[T](x: T): TObj[T] =
|
||||
totalGlobals += 1
|
||||
result.val = x
|
||||
|
||||
proc globalInstance*[T]: var TObj[T] =
|
||||
var g {.global.} = when T is int: makeObj(10) else: makeObj("hello")
|
||||
result = g
|
||||
|
||||
4
tests/global/globalaux2.nim
Normal file
4
tests/global/globalaux2.nim
Normal file
@@ -0,0 +1,4 @@
|
||||
import globalaux
|
||||
|
||||
echo "in globalaux2: ", globalInstance[int]().val
|
||||
|
||||
@@ -22,11 +22,11 @@ proc factory2(a, b: int): iterator (): int =
|
||||
yield x
|
||||
inc x
|
||||
|
||||
let foo = factory 1, 4
|
||||
let foo = factory(1, 4)
|
||||
|
||||
for f in foo():
|
||||
echo f
|
||||
|
||||
let foo2 = factory2 1,2
|
||||
let foo2 = factory2(1,2)
|
||||
|
||||
for f in foo2(): echo f
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
template foo(a: int, b: string) = nil
|
||||
template foo(a: int, b: string) = discard
|
||||
foo(1, "test")
|
||||
|
||||
proc bar(a: int, b: string) = nil
|
||||
proc bar(a: int, b: string) = discard
|
||||
bar(1, "test")
|
||||
|
||||
template foo(a: int, b: string) = bar(a, b)
|
||||
foo(1, "test")
|
||||
|
||||
block:
|
||||
proc bar(a: int, b: string) = nil
|
||||
template foo(a: int, b: string) = nil
|
||||
proc bar(a: int, b: string) = discard
|
||||
template foo(a: int, b: string) = discard
|
||||
foo(1, "test")
|
||||
bar(1, "test")
|
||||
|
||||
proc baz =
|
||||
proc foo(a: int, b: string) = nil
|
||||
proc foo(a: int, b: string) = discard
|
||||
proc foo(b: string) =
|
||||
template bar(a: int, b: string) = nil
|
||||
template bar(a: int, b: string) = discard
|
||||
bar(1, "test")
|
||||
|
||||
foo("test")
|
||||
|
||||
block:
|
||||
proc foo(b: string) = nil
|
||||
proc foo(b: string) = discard
|
||||
foo("test")
|
||||
foo(1, "test")
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ macro okayy:stmt =
|
||||
for node in decls: result.add node
|
||||
for node in impls: result.add node
|
||||
|
||||
importimpl(Item, int):
|
||||
importImpl(Item, int):
|
||||
echo 42
|
||||
importImpl(Foo, int16):
|
||||
echo 77
|
||||
|
||||
19
tests/macros/tvarnimnode.nim
Normal file
19
tests/macros/tvarnimnode.nim
Normal file
@@ -0,0 +1,19 @@
|
||||
discard """
|
||||
output: 10
|
||||
"""
|
||||
|
||||
#bug #926
|
||||
|
||||
import macros
|
||||
|
||||
proc test(f: var PNimrodNode) {.compileTime.} =
|
||||
f = newNimNode(nnkStmtList)
|
||||
f.add newCall(newIdentNode("echo"), newLit(10))
|
||||
|
||||
macro blah(prc: stmt): stmt =
|
||||
result = prc
|
||||
|
||||
test(result)
|
||||
|
||||
proc test() {.blah.} =
|
||||
echo 5
|
||||
@@ -178,14 +178,14 @@ template new_parsed_parameter*(tkind: Tparam_kind, expr): Tparsed_parameter =
|
||||
## #parsed_param3 = new_parsed_parameter(PK_INT, "231")
|
||||
var result {.gensym.}: Tparsed_parameter
|
||||
result.kind = tkind
|
||||
when tkind == PK_EMPTY: nil
|
||||
when tkind == PK_EMPTY: discard
|
||||
elif tkind == PK_INT: result.int_val = expr
|
||||
elif tkind == PK_BIGGEST_INT: result.big_int_val = expr
|
||||
elif tkind == PK_FLOAT: result.float_val = expr
|
||||
elif tkind == PK_BIGGEST_FLOAT: result.big_float_val = expr
|
||||
elif tkind == PK_STRING: result.str_val = expr
|
||||
elif tkind == PK_BOOL: result.bool_val = expr
|
||||
elif tkind == PK_HELP: nil
|
||||
elif tkind == PK_HELP: discard
|
||||
else: {.error: "unknown kind".}
|
||||
result
|
||||
|
||||
|
||||
@@ -18,10 +18,9 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
when defined(Linux):
|
||||
const Lib = "libchipmunk.so.6.1.1"
|
||||
else:
|
||||
{.error: "Platform unsupported".}
|
||||
|
||||
const Lib = "libchipmunk.so.6.1.1"
|
||||
|
||||
when defined(MoreNimrod):
|
||||
{.hint: "MoreNimrod defined; some Chipmunk functions replaced in Nimrod".}
|
||||
{.deadCodeElim: on.}
|
||||
|
||||
@@ -17,10 +17,9 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
when defined(Linux):
|
||||
const Lib = "libenet.so.1(|.0.3)"
|
||||
else:
|
||||
{.error: "Your platform has not been accounted for."}
|
||||
|
||||
const Lib = "libenet.so.1(|.0.3)"
|
||||
|
||||
{.deadCodeElim: ON.}
|
||||
const
|
||||
ENET_VERSION_MAJOR* = 1
|
||||
@@ -267,7 +266,7 @@ const
|
||||
ENET_PEER_RELIABLE_WINDOW_SIZE = 0x1000
|
||||
ENET_PEER_FREE_RELIABLE_WINDOWS = 8
|
||||
|
||||
when defined(Linux):
|
||||
when defined(Linux) or true:
|
||||
import posix
|
||||
const
|
||||
ENET_SOCKET_NULL*: cint = -1
|
||||
|
||||
@@ -6,7 +6,12 @@ when defined(linux):
|
||||
LibS = "libcsfml-system.so.2.0"
|
||||
LibW = "libcsfml-window.so.2.0"
|
||||
else:
|
||||
{.error: "Platform unsupported".}
|
||||
# We only compile for testing here, so it doesn't matter it's not supported
|
||||
const
|
||||
LibG = "libcsfml-graphics.so.2.0"
|
||||
LibS = "libcsfml-system.so.2.0"
|
||||
LibW = "libcsfml-window.so.2.0"
|
||||
#{.error: "Platform unsupported".}
|
||||
{.deadCodeElim: on.}
|
||||
{.pragma: pf, pure, final.}
|
||||
type
|
||||
@@ -153,8 +158,9 @@ type
|
||||
KeyF15, #/< The F15 key
|
||||
KeyPause, #/< The Pause key
|
||||
KeyCount #/< Keep last -- the total number of keyboard keys
|
||||
when defined(linux): #or defined(bsd) ??
|
||||
type TWindowHandle* = clong
|
||||
|
||||
type TWindowHandle* = clong
|
||||
|
||||
#elif defined(mac):
|
||||
# type TWindowHandle* = pointer ##typedef void* sfWindowHandle; <- whatever the hell that is
|
||||
#elif defined(windows):
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
discard """
|
||||
msg: '''
|
||||
int
|
||||
float
|
||||
TFoo
|
||||
TFoo
|
||||
'''
|
||||
msg: '''int int
|
||||
float float
|
||||
int int
|
||||
TFoo TFoo
|
||||
int float
|
||||
TFoo TFoo'''
|
||||
"""
|
||||
|
||||
import typetraits
|
||||
@@ -24,9 +24,8 @@ template reject(e: expr) =
|
||||
|
||||
proc genericParamRepeated[T: typedesc](a: T, b: T) =
|
||||
static:
|
||||
echo a.name
|
||||
echo b.name
|
||||
|
||||
echo a.name, " ", b.name
|
||||
|
||||
accept genericParamRepeated(int, int)
|
||||
accept genericParamRepeated(float, float)
|
||||
|
||||
@@ -35,8 +34,7 @@ reject genericParamRepeated(int, float)
|
||||
|
||||
proc genericParamOnce[T: typedesc](a, b: T) =
|
||||
static:
|
||||
echo a.name
|
||||
echo b.name
|
||||
echo a.name, " ", b.name
|
||||
|
||||
accept genericParamOnce(int, int)
|
||||
accept genericParamOnce(TFoo, TFoo)
|
||||
@@ -68,8 +66,7 @@ reject typePairs2(string, int, TBAR, TBAR)
|
||||
|
||||
proc dontBind(a: typedesc, b: typedesc) =
|
||||
static:
|
||||
echo a.name
|
||||
echo b.name
|
||||
echo a.name, " ", b.name
|
||||
|
||||
accept dontBind(int, float)
|
||||
accept dontBind(TFoo, TFoo)
|
||||
|
||||
@@ -26,3 +26,17 @@ foo 10
|
||||
foo "test"
|
||||
foo(@[TObj(x: 10), TObj(x: 20)])
|
||||
|
||||
proc intval(x: int) = discard
|
||||
|
||||
# check real and virtual fields
|
||||
type
|
||||
TFoo = generic T
|
||||
T.x
|
||||
y(T)
|
||||
intval T.y
|
||||
|
||||
proc y(x: TObj): int = 10
|
||||
|
||||
proc testFoo(x: TFoo) = discard
|
||||
testFoo(TObj(x: 10))
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ type
|
||||
TSomethingElse = object
|
||||
PSomethingElse = ref TSomethingElse
|
||||
|
||||
method foo(a: PNode, b: PSomethingElse) = nil
|
||||
method foo(a: PNodeFoo, b: PSomethingElse) = nil
|
||||
method foo(a: PNode, b: PSomethingElse) = discard
|
||||
method foo(a: PNodeFoo, b: PSomethingElse) = discard
|
||||
|
||||
var o: TObject
|
||||
o.somethin()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
discard """
|
||||
file: "tests/reject/trecincb.nim"
|
||||
line: 9
|
||||
errormsg: "recursive dependency: 'tests/reject/trecincb.nim'"
|
||||
errormsg: "recursive dependency: 'tests/module/trecincb.nim'"
|
||||
"""
|
||||
# Test recursive includes
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
discard """
|
||||
file: "trecincb.nim"
|
||||
line: 9
|
||||
errormsg: "recursive dependency: 'tests/reject/trecincb.nim'"
|
||||
errormsg: "recursive dependency: 'tests/module/trecincb.nim'"
|
||||
"""
|
||||
# Test recursive includes
|
||||
|
||||
|
||||
35
tests/notnil/tnotnil3.nim
Normal file
35
tests/notnil/tnotnil3.nim
Normal file
@@ -0,0 +1,35 @@
|
||||
discard """
|
||||
errormsg: "cannot prove 'variable' is not nil"
|
||||
line: 31
|
||||
"""
|
||||
|
||||
# bug #584
|
||||
# Testprogram for 'not nil' check
|
||||
|
||||
const testWithResult = true
|
||||
|
||||
type
|
||||
A = object
|
||||
B = object
|
||||
C = object
|
||||
a: ref A
|
||||
b: ref B
|
||||
|
||||
|
||||
proc testNotNil(c: ref C not nil) =
|
||||
discard
|
||||
|
||||
|
||||
when testWithResult:
|
||||
proc testNotNilOnResult(): ref C =
|
||||
new(result)
|
||||
#result.testNotNil() # Here 'not nil' can't be proved
|
||||
|
||||
|
||||
var variable: ref C
|
||||
new(variable)
|
||||
variable.testNotNil() # Here 'not nil' is proved
|
||||
|
||||
when testWithResult:
|
||||
discard testNotNilOnResult()
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
discard """
|
||||
file: "toverwr.nim"
|
||||
output: "hello"
|
||||
"""
|
||||
discard """
|
||||
file: "toverwr.nim"
|
||||
output: "hello"
|
||||
"""
|
||||
# Test the overloading resolution in connection with a qualifier
|
||||
|
||||
proc write(t: TFile, s: string) =
|
||||
nil # a nop
|
||||
discard # a nop
|
||||
|
||||
system.write(stdout, "hello")
|
||||
#OUT hello
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ discard """
|
||||
output: "12false3ha"
|
||||
"""
|
||||
|
||||
proc f(x: varargs[string, `$`]) = nil
|
||||
proc f(x: varargs[string, `$`]) = discard
|
||||
template optF{f(X)}(x: varargs[expr]) =
|
||||
writeln(stdout, x)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ type
|
||||
TRange = range[0..40]
|
||||
|
||||
proc p(r: TRange) =
|
||||
nil
|
||||
discard
|
||||
|
||||
var
|
||||
r: TRange
|
||||
|
||||
@@ -8,7 +8,7 @@ type
|
||||
TRange = range[0..40]
|
||||
|
||||
proc p(r: TRange) =
|
||||
nil
|
||||
discard
|
||||
|
||||
var
|
||||
r: TRange
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
discard """
|
||||
file: "tsets.nim"
|
||||
output: "Ha ein F ist in s!"
|
||||
"""
|
||||
discard """
|
||||
file: "tsets.nim"
|
||||
output: "Ha ein F ist in s!"
|
||||
"""
|
||||
# Test the handling of sets
|
||||
|
||||
import
|
||||
@@ -38,7 +38,7 @@ type
|
||||
TTokTypes* = set[TTokTypeRange]
|
||||
|
||||
const
|
||||
toktypes: TTokTypes = {TTokTypeRange(tkSymbol)..pred(tkIntLit),
|
||||
toktypes: TTokTypes = {TTokTypeRange(tkSymbol)..pred(tkIntLit),
|
||||
tkStrLit..tkTripleStrLit}
|
||||
|
||||
var
|
||||
@@ -51,14 +51,14 @@ else: write(stdout, "BUG: F ist nicht in s!\n")
|
||||
a = {} #{'a'..'z'}
|
||||
for x in low(TAZ) .. high(TAZ):
|
||||
incl(a, x)
|
||||
if x in a: nil
|
||||
if x in a: discard
|
||||
else: write(stdout, "BUG: something not in a!\n")
|
||||
|
||||
for x in low(TTokTypeRange) .. high(TTokTypeRange):
|
||||
if x in tokTypes:
|
||||
nil
|
||||
discard
|
||||
#writeln(stdout, "the token '$1' is in the set" % repr(x))
|
||||
|
||||
#OUT Ha ein F ist in s!
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
12
tests/sets/tsets_lt.nim
Normal file
12
tests/sets/tsets_lt.nim
Normal file
@@ -0,0 +1,12 @@
|
||||
discard """
|
||||
output: '''true
|
||||
true
|
||||
true'''
|
||||
"""
|
||||
|
||||
var s, s1: set[char]
|
||||
s = {'a'..'d'}
|
||||
s1 = {'a'..'c'}
|
||||
echo s1 < s
|
||||
echo s1 * s == {'a'..'c'}
|
||||
echo s1 <= s
|
||||
66
tests/specialops/tdotops.nim
Normal file
66
tests/specialops/tdotops.nim
Normal file
@@ -0,0 +1,66 @@
|
||||
discard """
|
||||
output: '''
|
||||
10
|
||||
assigning z = 20
|
||||
reading field y
|
||||
20
|
||||
call to y
|
||||
dot call
|
||||
no params call to a
|
||||
100
|
||||
no params call to b
|
||||
100
|
||||
one param call to c with 10
|
||||
100'''
|
||||
"""
|
||||
|
||||
type
|
||||
T1 = object
|
||||
x*: int
|
||||
|
||||
TD = distinct T1
|
||||
|
||||
T2 = object
|
||||
x: int
|
||||
|
||||
proc `.`*(v: T1, f: string): int =
|
||||
echo "reading field ", f
|
||||
return v.x
|
||||
|
||||
proc `.=`(x: var T1, f: string{lit}, v: int) =
|
||||
echo "assigning ", f, " = ", v
|
||||
x.x = v
|
||||
|
||||
template `.()`(x: T1, f: string, args: varargs[expr]): string =
|
||||
echo "call to ", f
|
||||
"dot call"
|
||||
|
||||
echo ""
|
||||
|
||||
var t = T1(x: 10)
|
||||
|
||||
echo t.x
|
||||
t.z = 20
|
||||
echo t.y
|
||||
echo t.y()
|
||||
|
||||
var d = TD(t)
|
||||
assert(not compiles(d.y))
|
||||
|
||||
proc `.`(v: T2, f: string): int =
|
||||
echo "no params call to ", f
|
||||
return v.x
|
||||
|
||||
proc `.`*(v: T2, f: string, a: int): int =
|
||||
echo "one param call to ", f, " with ", a
|
||||
return v.x
|
||||
|
||||
var tt = T2(x: 100)
|
||||
|
||||
echo tt.a
|
||||
echo tt.b()
|
||||
echo tt.c(10)
|
||||
|
||||
assert(not compiles(tt.d("x")))
|
||||
assert(not compiles(tt.d(1, 2)))
|
||||
|
||||
@@ -200,7 +200,7 @@ proc setSeen(d: TDb, s: TSeen) =
|
||||
var hashToSet = @[("type", $s.kind.int), ("channel", s.channel),
|
||||
("timestamp", $s.timestamp.int)]
|
||||
case s.kind
|
||||
of PSeenJoin: nil
|
||||
of PSeenJoin: discard
|
||||
of PSeenPart, PSeenMsg, PSeenQuit:
|
||||
hashToSet.add(("msg", s.msg))
|
||||
of PSeenNick:
|
||||
@@ -338,7 +338,7 @@ proc hubConnect(state: PState) =
|
||||
|
||||
proc handleIrc(irc: PAsyncIRC, event: TIRCEvent, state: PState) =
|
||||
case event.typ
|
||||
of EvConnected: nil
|
||||
of EvConnected: discard
|
||||
of EvDisconnected:
|
||||
while not state.ircClient.isConnected:
|
||||
try:
|
||||
@@ -424,7 +424,7 @@ proc handleIrc(irc: PAsyncIRC, event: TIRCEvent, state: PState) =
|
||||
seenNick.newNick = event.params[0]
|
||||
state.database.setSeen(seenNick)
|
||||
else:
|
||||
nil # TODO: ?
|
||||
discard # TODO: ?
|
||||
|
||||
proc open(port: TPort = TPort(5123)): PState =
|
||||
var res: PState
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# tests for the interpreter
|
||||
|
||||
proc loops(a: var int) =
|
||||
nil
|
||||
discard
|
||||
#var
|
||||
# b: int
|
||||
#b = glob
|
||||
|
||||
@@ -7,6 +7,6 @@ proc walkDirTree(root: string) =
|
||||
case k
|
||||
of pcFile, pcLinkToFile: echo(f)
|
||||
of pcDir: walkDirTree(f)
|
||||
of pcLinkToDir: nil
|
||||
of pcLinkToDir: discard
|
||||
|
||||
walkDirTree(".")
|
||||
|
||||
@@ -72,7 +72,7 @@ type
|
||||
rule: TNode ## the rule that the symbol refers to
|
||||
TNode {.final, shallow.} = object
|
||||
case kind: TPegKind
|
||||
of pkEmpty..pkWhitespace: nil
|
||||
of pkEmpty..pkWhitespace: discard
|
||||
of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle: term: string
|
||||
of pkChar, pkGreedyRepChar: ch: char
|
||||
of pkCharChoice, pkGreedyRepSet: charChoice: ref set[char]
|
||||
@@ -123,7 +123,7 @@ proc add(d: var TPeg, s: TPeg) {.inline.} = add(d.sons, s)
|
||||
proc copyPeg(a: TPeg): TPeg =
|
||||
result.kind = a.kind
|
||||
case a.kind
|
||||
of pkEmpty..pkWhitespace: nil
|
||||
of pkEmpty..pkWhitespace: discard
|
||||
of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle:
|
||||
result.term = a.term
|
||||
of pkChar, pkGreedyRepChar:
|
||||
@@ -229,7 +229,7 @@ when false:
|
||||
case a.kind
|
||||
of pkEmpty, pkAny, pkAnyRune, pkGreedyAny, pkNewLine, pkTerminal,
|
||||
pkTerminalIgnoreCase, pkTerminalIgnoreStyle, pkChar, pkGreedyRepChar,
|
||||
pkCharChoice, pkGreedyRepSet: nil
|
||||
pkCharChoice, pkGreedyRepSet: discard
|
||||
of pkNonTerminal: return true
|
||||
else:
|
||||
for i in 0..a.sons.len-1:
|
||||
@@ -318,7 +318,7 @@ proc backrefIgnoreStyle*(index: range[1..MaxSubPatterns]): TPeg {.
|
||||
|
||||
proc spaceCost(n: TPeg): int =
|
||||
case n.kind
|
||||
of pkEmpty: nil
|
||||
of pkEmpty: discard
|
||||
of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle, pkChar,
|
||||
pkGreedyRepChar, pkCharChoice, pkGreedyRepSet,
|
||||
pkAny..pkWhitespace, pkGreedyAny:
|
||||
@@ -1111,7 +1111,7 @@ proc handleHexChar(c: var TPegLexer, xi: var int) =
|
||||
of 'A'..'F':
|
||||
xi = (xi shl 4) or (ord(c.buf[c.bufpos]) - ord('A') + 10)
|
||||
inc(c.bufpos)
|
||||
else: nil
|
||||
else: discard
|
||||
|
||||
proc getEscapedChar(c: var TPegLexer, tok: var TToken) =
|
||||
inc(c.bufpos)
|
||||
@@ -1341,7 +1341,7 @@ proc getTok(c: var TPegLexer, tok: var TToken) =
|
||||
of "i": tok.modifier = modIgnoreCase
|
||||
of "y": tok.modifier = modIgnoreStyle
|
||||
of "v": tok.modifier = modVerbatim
|
||||
else: nil
|
||||
else: discard
|
||||
setLen(tok.literal, 0)
|
||||
if c.buf[c.bufpos] == '$':
|
||||
getDollar(c, tok)
|
||||
@@ -1488,7 +1488,7 @@ proc primary(p: var TPegParser): TPeg =
|
||||
of tkCurlyAt:
|
||||
getTok(p)
|
||||
return !*\primary(p).token(p)
|
||||
else: nil
|
||||
else: discard
|
||||
case p.tok.kind
|
||||
of tkIdentifier:
|
||||
if p.identIsVerbatim:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Test if the new table constructor syntax works:
|
||||
|
||||
template ignoreExpr(e: expr): stmt {.immediate.} =
|
||||
nil
|
||||
discard
|
||||
|
||||
# test first class '..' syntactical citizen:
|
||||
ignoreExpr x <> 2..4
|
||||
|
||||
@@ -3,3 +3,16 @@ import mtempl5
|
||||
|
||||
echo templ()
|
||||
|
||||
#bug #892
|
||||
|
||||
proc parse_to_close(value: string, index: int, open='(', close=')'): int =
|
||||
discard
|
||||
|
||||
# Call parse_to_close
|
||||
template get_next_ident: stmt =
|
||||
discard "{something}".parse_to_close(0, open = '{', close = '}')
|
||||
|
||||
get_next_ident()
|
||||
|
||||
|
||||
#identifier expected, but found '(open|open|open)'
|
||||
|
||||
@@ -123,9 +123,14 @@ proc gcTests(r: var TResults, cat: Category, options: string) =
|
||||
test "gcleak2"
|
||||
test "gctest"
|
||||
test "gcleak3"
|
||||
test "gcleak4"
|
||||
test "gcleak5"
|
||||
test "weakrefs"
|
||||
test "cycleleak"
|
||||
test "closureleak"
|
||||
test "refarrayleak"
|
||||
test "stackrefleak"
|
||||
|
||||
|
||||
# ------------------------- threading tests -----------------------------------
|
||||
|
||||
@@ -217,9 +222,88 @@ proc testStdlib(r: var TResults, pattern, options: string, cat: Category) =
|
||||
else:
|
||||
testNoSpec r, makeTest(test, options, cat, actionCompile)
|
||||
|
||||
# ----------------------------- babel ----------------------------------------
|
||||
type PackageFilter = enum
|
||||
pfCoreOnly
|
||||
pfExtraOnly
|
||||
pfAll
|
||||
|
||||
let
|
||||
babelExe = findExe("babel")
|
||||
babelDir = getHomeDir() / ".babel"
|
||||
packageDir = babelDir / "pkgs"
|
||||
packageIndex = babelDir / "packages.json"
|
||||
|
||||
proc waitForExitEx(p: PProcess): int =
|
||||
var outp: PStream = outputStream(p)
|
||||
var line = newStringOfCap(120).TaintedString
|
||||
while true:
|
||||
if outp.readLine(line):
|
||||
discard
|
||||
else:
|
||||
result = peekExitCode(p)
|
||||
if result != -1: break
|
||||
close(p)
|
||||
|
||||
proc getPackageDir(package: string): string =
|
||||
## TODO - Replace this with dom's version comparison magic.
|
||||
var commandOutput = execCmdEx("babel path $#" % package)
|
||||
if commandOutput.exitCode != quitSuccess:
|
||||
return ""
|
||||
else:
|
||||
result = commandOutput[0].string
|
||||
|
||||
iterator listPackages(filter: PackageFilter): tuple[name, url: string] =
|
||||
let packageList = parseFile(packageIndex)
|
||||
|
||||
for package in packageList.items():
|
||||
let
|
||||
name = package["name"].str
|
||||
url = package["url"].str
|
||||
isCorePackage = "nimrod-code" in normalize(url)
|
||||
case filter:
|
||||
of pfCoreOnly:
|
||||
if isCorePackage:
|
||||
yield (name, url)
|
||||
of pfExtraOnly:
|
||||
if not isCorePackage:
|
||||
yield (name, url)
|
||||
of pfAll:
|
||||
yield (name, url)
|
||||
|
||||
proc testBabelPackages(r: var TResults, cat: Category, filter: PackageFilter) =
|
||||
if babelExe == "":
|
||||
echo("[Warning] - Cannot run babel tests: Babel binary not found.")
|
||||
return
|
||||
|
||||
if execCmd("$# update" % babelExe) == quitFailure:
|
||||
echo("[Warning] - Cannot run babel tests: Babel update failed.")
|
||||
return
|
||||
|
||||
for name, url in listPackages(filter):
|
||||
var test = makeTest(name, "", cat)
|
||||
echo(url)
|
||||
let
|
||||
installProcess = startProcess(babelExe, "", ["install", "-y", name])
|
||||
installStatus = waitForExitEx(installProcess)
|
||||
installProcess.close
|
||||
if installStatus != quitSuccess:
|
||||
r.addResult(test, "", "", reInstallFailed)
|
||||
continue
|
||||
|
||||
let
|
||||
buildPath = getPackageDir(name)[0.. -3]
|
||||
let
|
||||
buildProcess = startProcess(babelExe, buildPath, ["build"])
|
||||
buildStatus = waitForExitEx(buildProcess)
|
||||
buildProcess.close
|
||||
if buildStatus != quitSuccess:
|
||||
r.addResult(test, "", "", reBuildFailed)
|
||||
r.addResult(test, "", "", reSuccess)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
const AdditionalCategories = ["debugger", "tools", "examples", "stdlib"]
|
||||
const AdditionalCategories = ["debugger", "tools", "examples", "stdlib", "babel-core"]
|
||||
|
||||
proc `&.?`(a, b: string): string =
|
||||
# candidate for the stdlib?
|
||||
@@ -259,6 +343,12 @@ proc processCategory(r: var TResults, cat: Category, options: string) =
|
||||
compileExample(r, "examples/*.nim", options, cat)
|
||||
compileExample(r, "examples/gtk/*.nim", options, cat)
|
||||
compileExample(r, "examples/talk/*.nim", options, cat)
|
||||
of "babel-core":
|
||||
testBabelPackages(r, cat, pfCoreOnly)
|
||||
of "babel-extra":
|
||||
testBabelPackages(r, cat, pfExtraOnly)
|
||||
of "babel-all":
|
||||
testBabelPackages(r, cat, pfAll)
|
||||
else:
|
||||
for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"):
|
||||
testSpec r, makeTest(name, options, cat)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
## HTML generator for the tester.
|
||||
|
||||
import db_sqlite, cgi, backend, strutils
|
||||
import db_sqlite, cgi, backend, strutils, json
|
||||
|
||||
const
|
||||
TableHeader = """<table border="1">
|
||||
@@ -114,8 +114,6 @@ proc getCommit(db: TDbConn, c: int): string =
|
||||
for thisCommit in db.rows(sql"select id from [Commit] order by id desc"):
|
||||
if commit == 0: result = thisCommit[0]
|
||||
inc commit
|
||||
if result.isNil:
|
||||
quit "cannot determine commit " & $c
|
||||
|
||||
proc generateHtml*(filename: string, commit: int) =
|
||||
const selRow = """select name, category, target, action,
|
||||
@@ -161,20 +159,48 @@ proc generateHtml*(filename: string, commit: int) =
|
||||
close(outfile)
|
||||
|
||||
proc generateJson*(filename: string, commit: int) =
|
||||
const selRow = """select count(*),
|
||||
const
|
||||
selRow = """select count(*),
|
||||
sum(result = 'reSuccess'),
|
||||
sum(result = 'reIgnored')
|
||||
from TestResult
|
||||
where [commit] = ? and machine = ?
|
||||
order by category"""
|
||||
from TestResult
|
||||
where [commit] = ? and machine = ?
|
||||
order by category"""
|
||||
selDiff = """select A.category || '/' || A.target || '/' || A.name,
|
||||
A.result,
|
||||
B.result
|
||||
from TestResult A
|
||||
inner join TestResult B
|
||||
on A.name = B.name and A.category = B.category
|
||||
where A.[commit] = ? and B.[commit] = ? and A.machine = ?
|
||||
and A.result != B.result"""
|
||||
var db = open(connection="testament.db", user="testament", password="",
|
||||
database="testament")
|
||||
let lastCommit = db.getCommit(commit)
|
||||
if lastCommit.isNil:
|
||||
quit "cannot determine commit " & $commit
|
||||
|
||||
let previousCommit = db.getCommit(commit-1)
|
||||
|
||||
var outfile = open(filename, fmWrite)
|
||||
|
||||
let data = db.getRow(sql(selRow), lastCommit, $backend.getMachine(db))
|
||||
let machine = $backend.getMachine(db)
|
||||
let data = db.getRow(sql(selRow), lastCommit, machine)
|
||||
|
||||
outfile.writeln("""{"total": $#, "passed": $#, "skipped": $#}""" % data)
|
||||
outfile.writeln("""{"total": $#, "passed": $#, "skipped": $#""" % data)
|
||||
|
||||
if not previousCommit.isNil:
|
||||
let diff = newJArray()
|
||||
|
||||
for row in db.rows(sql(selDiff), previousCommit, lastCommit, machine):
|
||||
var obj = newJObject()
|
||||
obj["name"] = %row[0]
|
||||
obj["old"] = %row[1]
|
||||
obj["new"] = %row[2]
|
||||
diff.add obj
|
||||
outfile.writeln(""", "diff": """)
|
||||
outfile.writeln(diff.pretty)
|
||||
|
||||
outfile.writeln "}"
|
||||
close(db)
|
||||
close(outfile)
|
||||
|
||||
@@ -28,6 +28,8 @@ type
|
||||
reCodegenFailure,
|
||||
reCodeNotFound,
|
||||
reExeNotFound,
|
||||
reInstallFailed # package installation failed
|
||||
reBuildFailed # package building failed
|
||||
reIgnored, # test is ignored
|
||||
reSuccess # test was successful
|
||||
TTarget* = enum
|
||||
|
||||
1
tests/threads/nimrod.cfg
Normal file
1
tests/threads/nimrod.cfg
Normal file
@@ -0,0 +1 @@
|
||||
threads:on
|
||||
@@ -1,5 +1,9 @@
|
||||
discard """
|
||||
output: "he, no return type;abc a string"
|
||||
output: '''12
|
||||
empty
|
||||
he, no return type;
|
||||
abc a string
|
||||
ha'''
|
||||
"""
|
||||
|
||||
proc ReturnT[T](x: T): T =
|
||||
|
||||
@@ -9,7 +9,7 @@ proc init: TYourObj =
|
||||
result.y = -1
|
||||
|
||||
proc f(x: var TYourObj) =
|
||||
nil
|
||||
discard
|
||||
|
||||
var m: TMyObj = init()
|
||||
f(m)
|
||||
|
||||
21
tests/vm/tstaticprintseq.nim
Normal file
21
tests/vm/tstaticprintseq.nim
Normal file
@@ -0,0 +1,21 @@
|
||||
discard """
|
||||
msg: '''1
|
||||
2
|
||||
3
|
||||
1
|
||||
2
|
||||
3'''
|
||||
"""
|
||||
|
||||
const s = @[1,2,3]
|
||||
|
||||
macro foo: stmt =
|
||||
for e in s:
|
||||
echo e
|
||||
|
||||
foo()
|
||||
|
||||
static:
|
||||
for e in s:
|
||||
echo e
|
||||
|
||||
13
tests/vm/twrongwhen.nim
Normal file
13
tests/vm/twrongwhen.nim
Normal file
@@ -0,0 +1,13 @@
|
||||
discard """
|
||||
output: "Error: cannot evaluate at compile time: x"
|
||||
line: 7
|
||||
"""
|
||||
|
||||
proc bla(x:int) =
|
||||
when x == 0:
|
||||
echo "oops"
|
||||
else:
|
||||
echo "good"
|
||||
|
||||
bla(2) # echos "oops"
|
||||
|
||||
Reference in New Issue
Block a user