updated tests to be executed

This commit is contained in:
Arne Döring
2018-11-14 23:14:16 +01:00
committed by Araq
parent 8ea72bdcea
commit e012eb1001
57 changed files with 341 additions and 90 deletions

View File

@@ -1,3 +1,4 @@
import
unittest, macros
@@ -44,4 +45,3 @@ test "arithmetic failure":
expect(ArithmeticError, CatchableError):
discard foo()

View File

@@ -231,4 +231,8 @@ when isMainModule:
except RangeError:
discard
# don't use causes integer overflow
doAssert compiles(random[int](low(int) .. high(int)))
main()

View File

@@ -839,6 +839,11 @@ proc `$`*(zone: Timezone): string =
proc `==`*(zone1, zone2: Timezone): bool =
## Two ``Timezone``'s are considered equal if their name is equal.
if system.`==`(zone1, zone2):
return true
if zone1.isNil or zone2.isNil:
return false
runnableExamples:
doAssert local() == local()
doAssert local() != utc()
@@ -1799,7 +1804,7 @@ proc formatPattern(dt: DateTime, pattern: FormatPattern, result: var string) =
of UUUU:
result.add $dt.year
of z, zz, zzz, zzzz:
if dt.timezone.name == "Etc/UTC":
if dt.timezone != nil and dt.timezone.name == "Etc/UTC":
result.add 'Z'
else:
result.add if -dt.utcOffset >= 0: '+' else: '-'

View File

@@ -358,7 +358,7 @@ proc testSpec(r: var TResults, test: TTest, target = targetC) =
reExeNotFound)
continue
let exeCmd = (if isJsTarget: nodejs & " " else: "") & exeFile
let exeCmd = nodejs & " " & quoteShell(exeFile)
var (buf, exitCode) = execCmdEx(exeCmd, options = {poStdErrToStdOut})
# Treat all failure codes from nodejs as 1. Older versions of nodejs used

View File

@@ -2,7 +2,7 @@ discard """
file: "tasyncall.nim"
exitcode: 0
"""
import times, sequtils, unittest
import times, sequtils
import asyncdispatch
const

View File

@@ -3,7 +3,12 @@ discard """
cmd: "nim $target --hints:on --define:ssl $options $file"
output: "500"
disabled: "windows"
target: c
action: compile
"""
# XXX, deactivated
import asyncdispatch, asyncnet, net, strutils, os
when defined(ssl):

View File

@@ -1,3 +1,6 @@
discard """
action: compile
"""
import strutils
@@ -21,4 +24,3 @@ of 21: echo "21"
else:
{.linearScanEnd.}
echo "default"

View File

@@ -1,8 +1,12 @@
discard """
output: ""
"""
import macros, strutils
# https://github.com/nim-lang/Nim/issues/1512
proc macrobust0(raw_input: string) =
proc macrobust0(input: string): string =
var output = ""
proc p1(a:string) =
output.add(a)
@@ -27,13 +31,9 @@ proc macrobust0(raw_input: string) =
proc p19(a:string) = p18(a)
proc p20(a:string) = p19(a)
let input = $raw_input
for a in input.split():
p20(a)
p19(a)
p18(a)
p17(a)
p16(a)
@@ -53,11 +53,9 @@ proc macrobust0(raw_input: string) =
p2(a)
p1(a)
result = output
echo output
macro macrobust(raw_input: untyped): untyped =
macro macrobust(input: static[string]): untyped =
var output = ""
proc p1(a:string) =
output.add(a)
@@ -82,12 +80,9 @@ macro macrobust(raw_input: untyped): untyped =
proc p19(a:string) = p18(a)
proc p20(a:string) = p19(a)
let input = $raw_input
for a in input.split():
p20(a)
p19(a)
p18(a)
p17(a)
p16(a)
@@ -105,11 +100,11 @@ macro macrobust(raw_input: untyped): untyped =
p4(a)
p3(a)
p2(a)
p1(a)
echo output
discard result
result = newLit(output)
macrobust """
const input = """
fdsasadfsdfa sadfsdafsdaf
dsfsdafdsfadsfa fsdaasdfasdf
fsdafsadfsad asdfasdfasdf
@@ -122,16 +117,7 @@ macrobust """
sdfasdafsadf sdfasdafsdaf sdfasdafsdaf
"""
let str1 = macrobust(input)
let str2 = macrobust0(input)
macrobust0 """
fdsasadfsdfa sadfsdafsdaf
dsfsdafdsfadsfa fsdaasdfasdf
fsdafsadfsad asdfasdfasdf
fdsasdfasdfa sadfsadfsadf
sadfasdfsdaf sadfsdafsdaf dsfasdaf
sadfsdafsadf fdsasdafsadf fdsasadfsdaf
sdfasadfsdafdfsa sadfsadfsdaf
sdafsdaffsda sdfasadfsadf
fsdasdafsdfa sdfasdfafsda
sdfasdafsadf sdfasdafsdaf sdfasdafsdaf
"""
doAssert str1 == str2

View File

@@ -1,3 +1,10 @@
discard """
output: '''
@[2000-01-01T00:00:00+00:00, 2001-01-01T00:00:00+00:00, 2002-01-01T00:00:00+00:00, 2003-01-01T00:00:00+00:00, 2004-01-01T00:00:00+00:00, 2005-01-01T00:00:00+00:00, 2006-01-01T00:00:00+00:00, 2007-01-01T00:00:00+00:00, 2008-01-01T00:00:00+00:00, 2009-01-01T00:00:00+00:00, 2010-01-01T00:00:00+00:00, 2011-01-01T00:00:00+00:00, 2012-01-01T00:00:00+00:00, 2013-01-01T00:00:00+00:00, 2014-01-01T00:00:00+00:00, 2015-01-01T00:00:00+00:00]
@[2000-01-01T00:00:00+00:00, 2001-01-01T00:00:00+00:00, 2002-01-01T00:00:00+00:00, 2003-01-01T00:00:00+00:00, 2004-01-01T00:00:00+00:00, 2005-01-01T00:00:00+00:00, 2006-01-01T00:00:00+00:00, 2007-01-01T00:00:00+00:00, 2008-01-01T00:00:00+00:00, 2009-01-01T00:00:00+00:00, 2010-01-01T00:00:00+00:00, 2011-01-01T00:00:00+00:00, 2012-01-01T00:00:00+00:00, 2013-01-01T00:00:00+00:00, 2014-01-01T00:00:00+00:00, 2015-01-01T00:00:00+00:00]
'''
"""
# bug #2073
import sequtils

View File

@@ -14,6 +14,7 @@ proc testExceptions(id: int, sleep: float) =
numbers.add(id)
raise (ref ValueError)()
except:
suspend(sleep)
numbers.add(id)
suspend(sleep)
numbers.add(id)
@@ -22,6 +23,6 @@ proc testExceptions(id: int, sleep: float) =
start(proc() = testExceptions(1, 0.01))
start(proc() = testExceptions(2, 0.011))
run()
coro.run()
doAssert(stackCheckValue == 1100220033, "Thread stack got corrupted")
doAssert(numbers == @[1, 2, 1, 2, 1, 2, 1, 2, 1, 2], "Coroutines executed in incorrect order")

View File

@@ -1,5 +1,6 @@
discard """
targets: "cpp"
action: compile
"""
import tables, lists

View File

@@ -1,4 +1,8 @@
discard """
output: '''
hi
'''
"""
import mdefaultprocparam
p()

View File

@@ -1,3 +1,6 @@
# Test for the compiler to be able to compile a Nim file with spaces in it.
discard """
output: "Successful"
"""
# Test for the compiler to be able to compile a Nim file with spaces in the directory name.
echo("Successful")

View File

@@ -1,3 +1,10 @@
discard """
output: '''
1
1
'''
"""
# Test the discardable pragma
proc p(x, y: int): int {.discardable.} =

View File

@@ -1,3 +1,8 @@
discard """
action: compile
"""
# XXX: it is not actually tested if the effects are inferred
type
PMenu = ref object

View File

@@ -1,3 +1,7 @@
discard """
action: compile
"""
#bug #712
import tables

View File

@@ -1,3 +1,13 @@
discard """
output: '''
Test
abcxyz123
'''
"""
proc fakeReadLine(): string =
"abcxyz123"
type
TMaybe[T] = object
case empty: bool
@@ -12,7 +22,7 @@ proc Nothing[T](): TMaybe[T] =
result.empty = true
proc safeReadLine(): TMaybe[string] =
var r = stdin.readLine()
var r = fakeReadLine()
if r == "": return Nothing[string]()
else: return Just(r)
@@ -21,3 +31,4 @@ when isMainModule:
echo(Test.value)
var mSomething = safeReadLine()
echo(mSomething.value)
mSomething = safeReadLine()

View File

@@ -1,5 +1,6 @@
discard """
cmd: "nim $target --hints:on --threads:on $options $file"
action: compile
"""
type
@@ -36,4 +37,3 @@ when isMainModule:
echo("test")
joinThread(thr)
os.sleep(3000)

View File

@@ -1,3 +1,16 @@
discard """
output: '''
Length correct
Correct
Correct
Correct
Correct
Correct
Correct
Correct
Correct
'''
"""
type
TIdObj* = object of RootObj
@@ -19,4 +32,3 @@ proc myNewString(L: int): string {.inline.} =
echo("Wrong")
var s = myNewString(8)

View File

@@ -1,3 +1,10 @@
discard """
output: '''
[Suite] memoization
'''
"""
# This file needs to be called 'test' nim to provoke a clash
# with the unittest.test name. Issue #
@@ -14,4 +21,3 @@ proc fib(n: int): int = 40
suite "memoization":
test "recursive function memoization":
check fastFib(40) == fib(40)

View File

@@ -1,3 +1,10 @@
discard """
output: '''
This exe: /home/arne/proj/nim/Nim/tests/misc/tcmdline
Number of parameters: 0
tests/misc/tcmdline
'''
"""
# Test the command line
import

View File

@@ -1,3 +1,9 @@
discard """
output: '''
1
2
'''
"""
proc p(a, b: int, c: proc ()) =
c()

View File

@@ -1,3 +1,7 @@
discard """
disabled: true
"""
import os
proc getDllName: string =
@@ -12,5 +16,3 @@ proc myImport2(s: int) {.cdecl, importc, dynlib: getDllName().}
myImport("test2")
myImport2(12)

View File

@@ -1,3 +1,7 @@
discard """
action: compile
"""
type
Bar = object
x: int

View File

@@ -1,18 +1,25 @@
discard """
outputsub: "is newer than"
"""
# test the new LastModificationTime() proc
let
file1 = "tests/testdata/data.csv"
file2 = "tests/testdata/doc1.xml"
import
os, times, strutils
proc main() =
var
a, b: Time
a = getLastModificationTime(paramStr(1))
b = getLastModificationTime(paramStr(2))
a = getLastModificationTime(file1)
b = getLastModificationTime(file2)
writeLine(stdout, $a)
writeLine(stdout, $b)
if a < b:
write(stdout, "$2 is newer than $1\n" % [paramStr(1), paramStr(2)])
write(stdout, "$2 is newer than $1\n" % [file1, file2])
else:
write(stdout, "$1 is newer than $2\n" % [paramStr(1), paramStr(2)])
write(stdout, "$1 is newer than $2\n" % [file1, file2])
main()

View File

@@ -1,3 +1,10 @@
discard """
output: '''
Hello!(x: 1, y: 2, z: 3)
(x: 1.0, y: 2.0)
'''
"""
# Test nested loops and some other things
proc andTest() =
@@ -84,4 +91,3 @@ proc main[T]() =
echo myType2
main[int]()

View File

@@ -1,3 +1,10 @@
discard """
outputsub: '''
Simple tree node allocation worked!
Simple cycle allocation worked!
'''
"""
# Test the implementation of the new operator
# and the code generation for gc walkers
# (and the garbage collector):

View File

@@ -1,3 +1,11 @@
discard """
nimout: '''
tprep.nim(25, 9) Hint: Case 2 [User]
tprep.nim(27, 11) Hint: Case 2.3 [User]
'''
outputsub: ""
"""
# Test the features that used to belong to the preprocessor
import

View File

@@ -17,10 +17,7 @@ proc echoSeq(a: seq[int]) =
for i in low(a)..high(a):
echo(a[i])
var
list: seq[int]
list = QuickSort(@[89,23,15,23,56,123,356,12,7,1,6,2,9,4,3])
echoSeq(list)
let list = QuickSort(@[89,23,15,23,56,123,356,12,7,1,6,2,9,4,3])
let expected = @[1, 2, 3, 4, 6, 7, 9, 12, 15, 23, 56, 89, 123, 356]
doAssert list == expected

View File

@@ -1,3 +1,28 @@
discard """
output: '''
false
false
false
false
false
false
false
false
false
false
128
1
2
3
4
255
17
45
19000
4294967288
'''
"""
# implements and tests an efficient radix tree
## another method to store an efficient array of pointers:

View File

@@ -1,3 +1,11 @@
discard """
output: '''
test the improved readline handling that does not care whether its
Macintosh, Unix or Windows text format.
'''
"""
# test the improved readline handling that does not care whether its
# Macintosh, Unix or Windows text format.
@@ -8,5 +16,6 @@ var
if open(inp, "tests/misc/treadln.nim"):
while not endOfFile(inp):
line = readLine(inp)
echo("#" & line & "#")
if line.len >= 2 and line[0] == '#' and line[1] == ' ':
echo line[2..^1]
close(inp)

View File

@@ -1,3 +1,10 @@
discard """
output: '''
mylist
'''
"""
type
TListItemType* = enum
RedisNil, RedisString
@@ -15,7 +22,8 @@ proc seq*() =
proc lrange*(key: string): TRedisList =
var foo: TListItem
foo.kind = RedisNil
foo.kind = RedisString
foo.str = key
result = @[foo]
when isMainModule:

View File

@@ -1,3 +1,23 @@
discard """
exitcode: 1
output: '''
Traceback (most recent call last)
tstrace.nim(36) tstrace
tstrace.nim(28) recTest
tstrace.nim(28) recTest
tstrace.nim(28) recTest
tstrace.nim(28) recTest
tstrace.nim(28) recTest
tstrace.nim(28) recTest
tstrace.nim(28) recTest
tstrace.nim(28) recTest
tstrace.nim(28) recTest
tstrace.nim(28) recTest
tstrace.nim(31) recTest
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
'''
"""
# Test the new stacktraces (great for debugging!)
{.push stack_trace: on.}

View File

@@ -23,4 +23,4 @@ proc editDistance(a, b: string): int =
c[(i-1)*n + (j-1)] = min(x,min(y,z))
return c[n*m]
write(stdout, editDistance("abc", "abd"))
doAssert editDistance("abc", "abd") == 3

View File

@@ -12,13 +12,13 @@ let t4 = (v2 mod 2'u64).uint64 # works
# bug #2550
var x: uint # doesn't work
echo x mod 2 == 0
doAssert x mod 2 == 0
var y: uint64 # doesn't work
echo y mod 2 == 0
doAssert y mod 2 == 0
var z: uint32 # works
echo z mod 2 == 0
doAssert z mod 2 == 0
var a: int # works
echo a mod 2 == 0
doAssert a mod 2 == 0

View File

@@ -1,3 +1,7 @@
discard """
action: compile
"""
# Test various aspects
# bug #572

View File

@@ -1,6 +1,8 @@
discard """
msg: "Warning: cannot prove that field 'x.s' is accessible [ProveField]"
line:51
action: run
output: "abc abc"
"""
import strutils

View File

@@ -1,7 +1,10 @@
discard """
action: compile
"""
# bug #4671
{.experimental.}
{.this: self.}
type
SomeObj = object
f: int

View File

@@ -1,5 +1,5 @@
discard """
ccodeCheck: "\\i @'deepCopy(' .*"
ccodeCheck: "@'genericDeepCopy(' .*"
action: compile
"""

View File

@@ -1,11 +1,6 @@
discard """
sortoutput: true
output: '''
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
0
1
2
@@ -16,6 +11,12 @@ Hello 6
7
8
9
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
'''
"""

View File

@@ -1,5 +1,14 @@
import unittest
import hashes
discard """
output: '''
[Suite] hashes
[Suite] hashing
'''
"""
import unittest, hashes
suite "hashes":
suite "hashing":

View File

@@ -1,3 +1,6 @@
discard """
output: "[Suite] httpcore"
"""
import unittest

View File

@@ -1,5 +1,11 @@
discard """
output: '''
{"data":[1]}
'''
"""
# Test case for https://github.com/nim-lang/Nim/issues/6385
import mjsonexternproc
# import json
foo(1)
foo(1)

View File

@@ -1,3 +1,7 @@
discard """
disabled: true
"""
## JSON tests based on https://github.com/nst/JSONTestSuite
import unittest,

View File

@@ -1,14 +1,18 @@
discard """
outputsub: ""
"""
import
unittest, osproc, streams, os, strformat
unittest, osproc, streams, os, strformat, strutils
const STRING_DATA = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
const TEST_FILE = "tests/testdata/string.txt"
proc echoLoop(str: string): string =
result = ""
var process = startProcess(findExe("tests/system/helpers/readall_echo"))
let exe = findExe("tests/system/helpers/readall_echo")
echo "exe: ", exe
var process = startProcess(exe)
var input = process.inputStream
input.write(str)
input.close()
@@ -22,10 +26,9 @@ suite "io":
test "stdin":
check:
echoLoop(STRING_DATA) == STRING_DATA
echoLoop(STRING_DATA[0..3999]) == STRING_DATA[0..3999]
test "file":
check:
readFile(TEST_FILE) == STRING_DATA
readFile(TEST_FILE).strip == STRING_DATA
proc verifyFileSize(sz: int64) =

View File

@@ -1,3 +1,7 @@
discard """
output: "0"
"""
# bug #5135
proc fail*[E](e: E): void =

View File

@@ -1,13 +1,17 @@
# bug #1940
discard """
nimout: '''===
nimout: '''
===
merge (A) with (B)
merge (A B) with (C)
merge (A B C) with (D)
merge (A B C D) with (E)
merge (A B C D E) with (F)
==='''
===
'''
output: "A B C D E F"
"""
type SqlStmt = tuple

View File

@@ -1,3 +1,7 @@
discard """
action: compile
"""
var
e = "abc"

View File

@@ -1,4 +1,15 @@
discard """
output: '''
0
1
2
3
0
1
2
3
'''
"""
# bug #1915
import macros

View File

@@ -1,5 +1,8 @@
discard """
exitcode: 1
outputsub: "0"
"""
import tconfusinglocal
fail "foo"

View File

@@ -1,3 +1,11 @@
discard """
output: '''
1
yay
12
'''
"""
template withOpenFile(f: untyped, filename: string, mode: FileMode,
actions: untyped): untyped =

View File

@@ -1,7 +1,8 @@
discard """
action: compile
"""
import db_sqlite
var db: DbConn
exec(db, sql"create table blabla()")

View File

@@ -1,3 +1,7 @@
discard """
output: "4"
"""
type
TFoo = object
@@ -25,4 +29,3 @@ echo f.second[1]
#echo `second[]`(f,1)
# this is the only way I could use it, but not what I expected

View File

@@ -1,3 +1,9 @@
discard """
output: '''
M=1000, D=500, C=100, L=50, X=10, V=5, I=1
'''
"""
const romanNumbers = [
("M", 1000), ("D", 500), ("C", 100),
("L", 50), ("X", 10), ("V", 5), ("I", 1) ]
@@ -12,5 +18,3 @@ for key, val in items(romanNumbers):
proc PrintBiTuple(t: tuple[k: string, v: int]): int =
stdout.write(t.k & "=" & $t.v & ", ")
return 0

View File

@@ -1,4 +1,5 @@
discard """
action: compile
"""
import strutils
@@ -28,4 +29,3 @@ Possible Commands:
CompileDate, CompileTime]
echo HelpText

View File

@@ -1,3 +1,8 @@
discard """
nimout: "##"
"""
import macros
proc testProc: string {.compileTime.} =
@@ -14,9 +19,9 @@ when true:
const
x = testProc()
echo "##", x, "##"
doAssert x == ""
# bug #1310
static:
var i, j: set[int8] = {}
var k = i + j
var i, j: set[int8] = {}
var k = i + j

View File

@@ -7,6 +7,6 @@ const
relRes = slurp"./tslurp.nim"
absRes = slurp(getScriptDir() / "tslurp.nim")
echo relRes
echo absRes
doAssert relRes.len > 200
doAssert absRes.len > 200
doAssert relRes == absRes