some love for the testsuite; fixed regressions

This commit is contained in:
Araq
2015-03-01 21:41:21 +01:00
parent 566ee874cd
commit 24ae0c387f
19 changed files with 133 additions and 51 deletions

View File

@@ -786,7 +786,8 @@ proc semProcAnnotation(c: PContext, prc: PNode;
result = semStmt(c, x)
# since a proc annotation can set pragmas, we process these here again.
# This is required for SqueakNim-like export pragmas.
if result[namePos].kind == nkSym and result[pragmasPos].kind != nkEmpty:
if result.kind in procDefs and result[namePos].kind == nkSym and
result[pragmasPos].kind != nkEmpty:
pragma(c, result[namePos].sym, result[pragmasPos], validPragmas)
return

View File

@@ -1270,9 +1270,11 @@ proc paramTypesMatchAux(m: var TCandidate, f, argType: PType,
of isGeneric:
inc(m.genericMatches)
when true:
if skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple:
if arg.typ == nil:
result = arg
elif skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple:
result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c)
elif arg.typ != nil and arg.typ.isEmptyContainer:
elif arg.typ.isEmptyContainer:
result = arg.copyTree
result.typ = getInstantiatedType(c, arg, m, f)
else:

View File

@@ -66,9 +66,9 @@ type
ppointer = ptr pointer
pbyteArray = ptr array[0.. 0xffff, int8]
TGenSeq = object
TGenericSeq {.importc.} = object
len, space: int
PGenSeq = ptr TGenSeq
PGenSeq = ptr TGenericSeq
const
GenericSeqSize = (2 * sizeof(int))

View File

@@ -11,7 +11,7 @@ when declared(NimString):
# we are in system module:
{.pragma: codegenType, compilerproc.}
else:
{.pragma: codegenType.}
{.pragma: codegenType, importc.}
type
# This should be he same as ast.TTypeKind
@@ -65,7 +65,7 @@ type
tyBigNum,
TNimNodeKind = enum nkNone, nkSlot, nkList, nkCase
TNimNode {.codegenType, final.} = object
TNimNode {.codegenType.} = object
kind: TNimNodeKind
offset: int
typ: ptr TNimType
@@ -78,7 +78,7 @@ type
ntfAcyclic = 1, # type cannot form a cycle
ntfEnumHole = 2 # enum has holes and thus `$` for them needs the slow
# version
TNimType {.codegenType, final.} = object
TNimType {.codegenType.} = object
size: int
kind: TNimKind
flags: set[TNimTypeFlag]

View File

@@ -264,7 +264,17 @@ proc nimFloatToStr(f: float): string {.compilerproc.} =
buf[n] = '.'
buf[n+1] = '0'
buf[n+2] = '\0'
result = $buf
# On Windows nice numbers like '1.#INF', '-1.#INF' or '1.#NAN' are produced.
# We want to get rid of these here:
if buf[n-1] == 'N':
result = "nan"
elif buf[n-1] == 'F':
if buf[0] == '-':
result = "-inf"
else:
result = "inf"
else:
result = $buf
proc strtod(buf: cstring, endptr: ptr cstring): float64 {.importc,
header: "<stdlib.h>", noSideEffect.}

View File

@@ -1,6 +1,5 @@
discard """
line: 21
errormsg: "invalid type: 'Table[string, proc (string){.gcsafe.}]'"
output: "action 3 arg"
"""
import tables

View File

@@ -3,14 +3,14 @@ discard """
WARNING: false first assertion from bar
ERROR: false second assertion from bar
-1
tests/assert/tfailedassert.nim:27 false assertion from foo
tfailedassert.nim:27 false assertion from foo
'''
"""
type
TLineInfo = tuple[filename: string, line: int]
TMyError = object of E_Base
TMyError = object of Exception
lineinfo: TLineInfo
EMyError = ref TMyError

View File

@@ -0,0 +1,30 @@
discard """
output: '''255
1 1
0.5'''
"""
# bug #1181
type
TFoo = object
x: int32
proc mainowar =
var foo: TFoo
foo.x = 0xff
var arr1 = cast[ptr array[4, uint8]](addr foo)[] # Fails.
echo arr1[when cpuEndian == littleEndian: 0 else: 3]
var i = 1i32
let x = addr i
var arr2 = cast[ptr array[4, uint8]](x)[] # Fails.
echo arr2[when cpuEndian == littleEndian: 0 else: 3], " ", i
# bug #1715
var a: array[2, float32] = [0.5'f32, 0.7]
let p = addr a
var b = p[]
echo b[0]
mainowar()

View File

@@ -1,5 +1,5 @@
discard """
cmd: "nim cpp $target"
cmd: "nim cpp $file"
"""
import rawsockets

View File

@@ -1,5 +1,5 @@
discard """
cmd: "nim cpp $target"
cmd: "nim cpp $file"
"""
import typeinfo

View File

@@ -1,6 +1,5 @@
discard """
line: 9
errormsg: "'a' is deprecated [Deprecated]"
nimout: "'a' is deprecated [Deprecated]"
"""
var
@@ -8,4 +7,3 @@ var
a[8] = 1

View File

@@ -1,6 +1,6 @@
discard """
line: 20
errormsg: " usage of a type with a destructor in a non destructible context"
line: 23
nimout: " usage of a type with a destructor in a non destructible context"
"""
{.experimental.}
@@ -19,5 +19,9 @@ proc open: TMyObj =
proc `$`(x: TMyObj): string = $x.y
echo open()
proc foo =
discard open()
# XXX doesn't trigger this yet:
#echo open()

View File

@@ -0,0 +1,18 @@
discard """
output: '''hi
hi'''
"""
# bug #1742
template test(): expr =
let a = 0
defer: echo "hi"
a
let i = test()
import strutils
let x = try: parseInt("133a")
except: -1
finally: echo "hi"

View File

@@ -1,6 +1,6 @@
discard """
file: "toop1.nim"
output: "in globalaux2: 10\ntotal globals: 2\nint value: 100\nstring value: second"
disabled: "true"
"""
import globalaux, globalaux2

View File

@@ -7,8 +7,11 @@ discard """
1
2
3'''
disabled: "true"
"""
# Disabled since some versions of GCC ignore the 'packed' attribute
# Test
type

View File

@@ -0,0 +1,17 @@
discard """
output: "Version 2 was called."
disabled: true
"""
# bug #2220
type A[T] = object
type B = A[int]
proc p[X](x: X) =
echo "Version 1 was called."
proc p(x: B) =
echo "Version 2 was called."
p(B()) # This call reported as ambiguous.

View File

@@ -6,11 +6,11 @@ import marshal
template testit(x: expr) = discard $$to[type(x)]($$x)
var x: array[0..4, array[0..4, string]] = [
["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"],
["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"],
["test", "1", "2", "3", "4"]]
testit(x)
var x: array[0..4, array[0..4, string]] = [
["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"],
["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"],
["test", "1", "2", "3", "4"]]
testit(x)
var test2: tuple[name: string, s: int] = ("tuple test", 56)
testit(test2)
@@ -24,7 +24,7 @@ type
of blah:
help: string
else:
nil
discard
PNode = ref TNode
TNode = object

View File

@@ -230,17 +230,17 @@ proc testStdlib(r: var TResults, pattern, options: string, cat: Category) =
else:
testNoSpec r, makeTest(test, options, cat, actionCompile)
# ----------------------------- babel ----------------------------------------
# ----------------------------- nimble ----------------------------------------
type PackageFilter = enum
pfCoreOnly
pfExtraOnly
pfAll
let
babelExe = findExe("babel")
babelDir = getHomeDir() / ".babel"
packageDir = babelDir / "pkgs"
packageIndex = babelDir / "packages.json"
nimbleExe = findExe("nimble")
nimbleDir = getHomeDir() / ".nimble"
packageDir = nimbleDir / "pkgs"
packageIndex = nimbleDir / "packages.json"
proc waitForExitEx(p: Process): int =
var outp = outputStream(p)
@@ -255,7 +255,7 @@ proc waitForExitEx(p: Process): int =
proc getPackageDir(package: string): string =
## TODO - Replace this with dom's version comparison magic.
var commandOutput = execCmdEx("babel path $#" % package)
var commandOutput = execCmdEx("nimble path $#" % package)
if commandOutput.exitCode != QuitSuccess:
return ""
else:
@@ -268,7 +268,7 @@ iterator listPackages(filter: PackageFilter): tuple[name, url: string] =
let
name = package["name"].str
url = package["url"].str
isCorePackage = "nimrod-code" in normalize(url)
isCorePackage = "nim-lang" in normalize(url)
case filter:
of pfCoreOnly:
if isCorePackage:
@@ -279,13 +279,13 @@ iterator listPackages(filter: PackageFilter): tuple[name, url: string] =
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.")
proc testNimblePackages(r: var TResults, cat: Category, filter: PackageFilter) =
if nimbleExe == "":
echo("[Warning] - Cannot run nimble tests: Nimble binary not found.")
return
if execCmd("$# update" % babelExe) == QuitFailure:
echo("[Warning] - Cannot run babel tests: Babel update failed.")
if execCmd("$# update" % nimbleExe) == QuitFailure:
echo("[Warning] - Cannot run nimble tests: Nimble update failed.")
return
let packageFileTest = makeTest("PackageFileParsed", "", cat)
@@ -294,7 +294,7 @@ proc testBabelPackages(r: var TResults, cat: Category, filter: PackageFilter) =
var test = makeTest(name, "", cat)
echo(url)
let
installProcess = startProcess(babelExe, "", ["install", "-y", name])
installProcess = startProcess(nimbleExe, "", ["install", "-y", name])
installStatus = waitForExitEx(installProcess)
installProcess.close
if installStatus != QuitSuccess:
@@ -304,7 +304,7 @@ proc testBabelPackages(r: var TResults, cat: Category, filter: PackageFilter) =
let
buildPath = getPackageDir(name)[0.. -3]
let
buildProcess = startProcess(babelExe, buildPath, ["build"])
buildProcess = startProcess(nimbleExe, buildPath, ["build"])
buildStatus = waitForExitEx(buildProcess)
buildProcess.close
if buildStatus != QuitSuccess:
@@ -312,13 +312,13 @@ proc testBabelPackages(r: var TResults, cat: Category, filter: PackageFilter) =
r.addResult(test, "", "", reSuccess)
r.addResult(packageFileTest, "", "", reSuccess)
except JsonParsingError:
echo("[Warning] - Cannot run babel tests: Invalid package file.")
echo("[Warning] - Cannot run nimble tests: Invalid package file.")
r.addResult(packageFileTest, "", "", reBuildFailed)
# ----------------------------------------------------------------------------
const AdditionalCategories = ["debugger", "examples", "lib", "babel-core"]
const AdditionalCategories = ["debugger", "examples", "lib", "nimble-core"]
proc `&.?`(a, b: string): string =
# candidate for the stdlib?
@@ -356,12 +356,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)
of "nimble-core":
testNimblePackages(r, cat, pfCoreOnly)
of "nimble-extra":
testNimblePackages(r, cat, pfExtraOnly)
of "nimble-all":
testNimblePackages(r, cat, pfAll)
else:
for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"):
testSpec r, makeTest(name, options, cat)

View File

@@ -1,5 +1,5 @@
discard """
output: '''3060
output: '''3030
true
3'''
"""