some love for the testsuite; fixed regressions

This commit is contained in:
Araq 2015-03-01 21:41:21 +01:00
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) result = semStmt(c, x)
# since a proc annotation can set pragmas, we process these here again. # since a proc annotation can set pragmas, we process these here again.
# This is required for SqueakNim-like export pragmas. # 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) pragma(c, result[namePos].sym, result[pragmasPos], validPragmas)
return return

View file

@ -1270,9 +1270,11 @@ proc paramTypesMatchAux(m: var TCandidate, f, argType: PType,
of isGeneric: of isGeneric:
inc(m.genericMatches) inc(m.genericMatches)
when true: 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) result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c)
elif arg.typ != nil and arg.typ.isEmptyContainer: elif arg.typ.isEmptyContainer:
result = arg.copyTree result = arg.copyTree
result.typ = getInstantiatedType(c, arg, m, f) result.typ = getInstantiatedType(c, arg, m, f)
else: else:

View file

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

View file

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

View file

@ -264,6 +264,16 @@ proc nimFloatToStr(f: float): string {.compilerproc.} =
buf[n] = '.' buf[n] = '.'
buf[n+1] = '0' buf[n+1] = '0'
buf[n+2] = '\0' buf[n+2] = '\0'
# 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 result = $buf
proc strtod(buf: cstring, endptr: ptr cstring): float64 {.importc, proc strtod(buf: cstring, endptr: ptr cstring): float64 {.importc,

View file

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

View file

@ -3,14 +3,14 @@ discard """
WARNING: false first assertion from bar WARNING: false first assertion from bar
ERROR: false second assertion from bar ERROR: false second assertion from bar
-1 -1
tests/assert/tfailedassert.nim:27 false assertion from foo tfailedassert.nim:27 false assertion from foo
''' '''
""" """
type type
TLineInfo = tuple[filename: string, line: int] TLineInfo = tuple[filename: string, line: int]
TMyError = object of E_Base TMyError = object of Exception
lineinfo: TLineInfo lineinfo: TLineInfo
EMyError = ref TMyError 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 """ discard """
cmd: "nim cpp $target" cmd: "nim cpp $file"
""" """
import rawsockets import rawsockets

View file

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

View file

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

View file

@ -1,6 +1,6 @@
discard """ discard """
line: 20 line: 23
errormsg: " usage of a type with a destructor in a non destructible context" nimout: " usage of a type with a destructor in a non destructible context"
""" """
{.experimental.} {.experimental.}
@ -19,5 +19,9 @@ proc open: TMyObj =
proc `$`(x: TMyObj): string = $x.y 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 """ discard """
file: "toop1.nim"
output: "in globalaux2: 10\ntotal globals: 2\nint value: 100\nstring value: second" output: "in globalaux2: 10\ntotal globals: 2\nint value: 100\nstring value: second"
disabled: "true"
""" """
import globalaux, globalaux2 import globalaux, globalaux2

View file

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

@ -24,7 +24,7 @@ type
of blah: of blah:
help: string help: string
else: else:
nil discard
PNode = ref TNode PNode = ref TNode
TNode = object TNode = object

View file

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

View file

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