Merge branch 'devel' into araq

This commit is contained in:
Andreas Rumpf 2017-11-07 11:17:20 +01:00
commit 617ba1a209
37 changed files with 353 additions and 69 deletions

View file

@ -4,7 +4,8 @@ discard """
3
@[(Field0: 1, Field1: 2), (Field0: 3, Field1: 5)]
2
@[a, new one, c]'''
@[a, new one, c]
@[1, 2, 3]'''
"""
proc foo[T](x, y: T): T = x
@ -35,3 +36,8 @@ useOpenarray([1, 2, 3])
var z = @["a", "b", "c"]
mutOpenarray(z)
echo z
# bug #6675
var y: array[1..5, int] = [1,2,3,4,5]
y[3..5] = [1, 2, 3]
echo y[3..5]

View file

@ -0,0 +1,46 @@
###############################
#### part from Arraymancer
type
MetadataArray* = object
data*: array[8, int]
len*: int
# Commenting the converter removes the error "lib/system.nim(3536, 3) Error: for a 'var' type a variable needs to be passed"
converter toMetadataArray*(se: varargs[int]): MetadataArray {.inline.} =
result.len = se.len
for i in 0..<se.len:
result.data[i] = se[i]
when NimVersion >= "0.17.3":
type Index = int or BackwardsIndex
template `^^`(s, i: untyped): untyped =
when i is BackwardsIndex:
s.len - int(i)
else: i
else:
type Index = int
template `^^`(s, i: untyped): untyped =
i
## With Nim devel from the start of the week (~Oct30) I managed to trigger "lib/system.nim(3536, 4) Error: expression has no address"
## but I can't anymore after updating Nim (Nov5)
## Now commenting this plain compiles and removes the error "lib/system.nim(3536, 3) Error: for a 'var' type a variable needs to be passed"
proc `[]`*(a: var MetadataArray, idx: Index): var int {.inline.} =
a.data[a ^^ idx]
##############################
### Completely unrelated lib that triggers the issue
type
MySeq[T] = ref object
data: seq[T]
proc test[T](sx: MySeq[T]) =
# Removing the backward index removes the error "lib/system.nim(3536, 3) Error: for a 'var' type a variable needs to be passed"
echo sx.data[^1] # error here
let s = MySeq[int](data: @[1, 2, 3])
s.test()

View file

@ -4,6 +4,7 @@ discard """
OK AF_INET
OK AF_INET6
'''
disabled: "travis"
"""
import

View file

@ -0,0 +1,12 @@
discard """
line: 9
errormsg: "illegal capture 'x'"
"""
proc outer(arg: string) =
var x = 0
proc inner {.inline.} =
echo "inner", x
inner()
outer("abc")

View file

@ -0,0 +1,13 @@
# bug #6691
type
ConceptA = concept c
ConceptB = concept c
c.myProc(ConceptA)
Obj = object
proc myProc(obj: Obj, x: ConceptA) = discard
echo Obj is ConceptB

44
tests/js/tarrayboundscheck.nim Executable file
View file

@ -0,0 +1,44 @@
discard """
output: '''idx out of bounds: -1
month out of bounds: 0
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
month out of bounds: 13
idx out of bounds: 14
'''
"""
{.push boundChecks:on.}
# see issue #6532:
# js backend 0.17.3: array bounds check for non zero based arrays is buggy
proc test_arrayboundscheck() =
var months: array[1..12, string] =
["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
var indices = [0,1,2,3,4,5,6,7,8,9,10,11,12,13]
for i in -1 .. 14:
try:
let idx = indices[i]
try:
echo months[idx]
except:
echo "month out of bounds: ", idx
except:
echo "idx out of bounds: ", i
test_arrayboundscheck()
{.pop.}

View file

@ -1,6 +1,6 @@
discard """
line: 24
errormsg: "expression expected, but found 'keyword else'"
errormsg: "invalid indentation"
"""
import macros
@ -11,7 +11,7 @@ var x = if 4 != 5:
else:
"no"
macro mymacro(n): untyped {.immediate.} =
macro mymacro(n, b): untyped =
discard
mymacro:

View file

@ -32,3 +32,21 @@ let other = x:
echo "no"
let outer = y(5):
echo "yes"
# bug #6609
type
TextureInternalFormat = enum RED, RGB, RGBA
const channels = 4
let format =
if channels == 1:
TextureInternalFormat.RED
elif channels == 3:
TextureInternalFormat.RGB
elif channels == 4:
TextureInternalFormat.RGBA
else:
echo "Texture Format Unknown, assuming RGB" #This echo causes an error
TextureInternalFormat.RGB

View file

@ -2,6 +2,7 @@ discard """
cmd: "nim c --threads:on -d:ssl $file"
exitcode: 0
output: "OK"
disabled: "travis"
"""
import strutils

View file

@ -2,6 +2,7 @@ discard """
cmd: "nim c --threads:on $file"
exitcode: 0
output: "OK"
disabled: "travis"
"""
import os, net, nativesockets, asyncdispatch

View file

@ -418,8 +418,9 @@ proc `&?.`(a, b: string): string =
proc processSingleTest(r: var TResults, cat: Category, options, test: string) =
let test = "tests" & DirSep &.? cat.string / test
let target = if cat.string.normalize == "js": targetJS else: targetC
if existsFile(test): testSpec r, makeTest(test, options, cat)
if existsFile(test): testSpec r, makeTest(test, options, cat, target = target)
else: echo "[Warning] - ", test, " test does not exist"
proc processCategory(r: var TResults, cat: Category, options: string) =

View file

@ -12,6 +12,8 @@ import parseutils, strutils, os, osproc, streams, parsecfg
var compilerPrefix* = "compiler" / "nim "
let isTravis = existsEnv("TRAVIS")
proc cmdTemplate*(): string =
compilerPrefix & "$target --lib:lib --hints:on -d:testing $options $file"
@ -174,6 +176,8 @@ proc parseSpec*(filename: string): TSpec =
when defined(unix): result.err = reIgnored
of "posix":
when defined(posix): result.err = reIgnored
of "travis":
if isTravis: result.err = reIgnored
else:
raise newException(ValueError, "cannot interpret as a bool: " & e.value)
of "cmd":

View file

@ -439,6 +439,8 @@ proc main() =
var optPrintResults = false
var optFailing = false
var targetsStr = ""
var p = initOptParser()
p.next()
while p.kind == cmdLongoption:
@ -446,7 +448,9 @@ proc main() =
of "print", "verbose": optPrintResults = true
of "failing": optFailing = true
of "pedantic": discard "now always enabled"
of "targets": targets = parseTargets(p.val.string)
of "targets":
targetsStr = p.val.string
targets = parseTargets(targetsStr)
of "nim": compilerPrefix = p.val.string
else: quit Usage
p.next()
@ -457,7 +461,9 @@ proc main() =
case action
of "all":
let testsDir = "tests" & DirSep
let myself = quoteShell(findExe("tests" / "testament" / "tester"))
var myself = quoteShell(findExe("tests" / "testament" / "tester"))
if targetsStr.len > 0:
myself &= " '--targets:" & targetsStr & "'"
var cmds: seq[string] = @[]
let rest = if p.cmdLineRest.string.len > 0: " " & p.cmdLineRest.string else: ""
for kind, dir in walkDir(testsDir):

View file

@ -1,2 +1,9 @@
This directory contains tests which are not automatically executed
for various reasons. Mainly due to dependencies on external services.
This directory contains integration tests which are not automatically executed
for various reasons:
- dependency on external services
- dependency on files / configuration / state of the local host
- tests that are extremely slow or require large amounts of memory or storage
- tests that spawn local daemons
Integration tests can become stale very quickly. Automated ./koch tests are
strongly recommended.