fix #16256: nimout: <empty> should give error (vacuously true); improve a few tests (#18089)

* fix #16256: nimout: <empty> should give error (vacuously true); improve some tests

* renamed:    tests/stdlib/t9710.nim -> tests/misc/t9710.nim

* improve tests

* fix non-DRY tests

* improve $nim_prs_D/tests/stdlib/t9091.nim

* renamed:    tests/stdlib/t9091.nim -> tests/misc/t9091.nim

* fixup

* address comment: doAssert => result.parseErrors
This commit is contained in:
Timothee Cour 2021-05-31 04:39:19 -07:00 • committed by GitHub
commit a36efb59b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 106 deletions

View file

@ -253,6 +253,7 @@ proc parseSpec*(filename: string): TSpec =
var p: CfgParser var p: CfgParser
open(p, ss, filename, 1) open(p, ss, filename, 1)
var flags: HashSet[string] var flags: HashSet[string]
var nimoutFound = false
while true: while true:
var e = next(p) var e = next(p)
case e.kind case e.kind
@ -309,6 +310,7 @@ proc parseSpec*(filename: string): TSpec =
result.action = actionReject result.action = actionReject
of "nimout": of "nimout":
result.nimout = e.value result.nimout = e.value
nimoutFound = true
of "nimoutfull": of "nimoutfull":
result.nimoutFull = parseCfgBool(e.value) result.nimoutFull = parseCfgBool(e.value)
of "batchable": of "batchable":
@ -401,6 +403,9 @@ proc parseSpec*(filename: string): TSpec =
if skips.anyIt(it in result.file): if skips.anyIt(it in result.file):
result.err = reDisabled result.err = reDisabled
if nimoutFound and result.nimout.len == 0 and not result.nimoutFull:
result.parseErrors.addLine "empty `nimout` is vacuously true, use `nimoutFull:true` if intentional"
result.inCurrentBatch = isCurrentBatch(testamentData0, filename) or result.unbatchable result.inCurrentBatch = isCurrentBatch(testamentData0, filename) or result.unbatchable
if not result.inCurrentBatch: if not result.inCurrentBatch:
result.err = reDisabled result.err = reDisabled

View file

@ -1,10 +1,5 @@
discard """ # bug #9091
targets: "c"
output: "test AObj"
action: "compile"
exitcode: 0
timeout: 60.0
"""
import streams import streams
block: block:
@ -18,6 +13,8 @@ block:
let mi = new Mine let mi = new Mine
str.write(mi) str.write(mi)
str.setPosition 0
doAssert str.readAll == "sure"
block: block:
type type
@ -27,10 +24,10 @@ block:
proc foo(a: int): string = "" proc foo(a: int): string = ""
proc test(args: varargs[string, foo]) = proc test(args: varargs[string, foo]) =
echo "varargs" doAssert false
proc test(a: AObj) = proc test(a: AObj) =
echo "test AObj" discard
let x = AObj() let x = AObj()
test(x) test(x)

6
tests/misc/t9710.nim Normal file
View file

@ -0,0 +1,6 @@
discard """
matrix: "--debugger:native"
"""
# bug #9710
for i in 1 || 200:
discard i

View file

@ -1,11 +0,0 @@
discard """
cmd: "nim c -r --debugger:native --panics:on $options $file"
targets: "c"
nimout: ""
action: "run"
exitcode: 0
timeout: 60.0
"""
for i in 1 || 200:
discard i

View file

@ -1,15 +1,5 @@
discard """
cmd: "nim c -r --styleCheck:hint --panics:on $options $file"
targets: "c"
nimout: ""
action: "run"
exitcode: 0
timeout: 60.0
"""
import nativesockets import nativesockets
when not defined(netbsd): when not defined(netbsd):
# Ref: https://github.com/nim-lang/Nim/issues/15452 - NetBSD doesn't define an `ip` protocol # Ref: https://github.com/nim-lang/Nim/issues/15452 - NetBSD doesn't define an `ip` protocol
doAssert getProtoByName("ip") == 0 doAssert getProtoByName("ip") == 0

View file

@ -1,29 +1,25 @@
discard """ import std/nativesockets
cmd: "nim c -r --styleCheck:hint --panics:on $options $file" import stdtest/testutils
targets: "c"
nimout: ""
action: "run"
exitcode: 0
timeout: 60.0
"""
import nativesockets
block:
let hostname = getHostname()
doAssert hostname.len > 0
when defined(windows): when defined(windows):
doAssert toInt(IPPROTO_IP) == 0.cint assertAll:
doAssert toInt(IPPROTO_ICMP) == 1.cint toInt(IPPROTO_IP) == 0
doAssert toInt(IPPROTO_TCP) == 6.cint toInt(IPPROTO_ICMP) == 1
doAssert toInt(IPPROTO_UDP) == 17.cint toInt(IPPROTO_TCP) == 6
doAssert toInt(IPPROTO_IPV6) == 41.cint toInt(IPPROTO_UDP) == 17
doAssert toInt(IPPROTO_ICMPV6) == 58.cint toInt(IPPROTO_IPV6) == 41
doAssert toInt(IPPROTO_RAW) == 20.cint toInt(IPPROTO_ICMPV6) == 58
toInt(IPPROTO_RAW) == 20
# no changes to enum value # no changes to enum value
doAssert ord(IPPROTO_TCP) == 6 ord(IPPROTO_TCP) == 6
doAssert ord(IPPROTO_UDP) == 17 ord(IPPROTO_UDP) == 17
doAssert ord(IPPROTO_IP) == 18 ord(IPPROTO_IP) == 18
doAssert ord(IPPROTO_IPV6) == 19 ord(IPPROTO_IPV6) == 19
doAssert ord(IPPROTO_RAW) == 20 ord(IPPROTO_RAW) == 20
doAssert ord(IPPROTO_ICMP) == 21 ord(IPPROTO_ICMP) == 21
doAssert ord(IPPROTO_ICMPV6) == 22 ord(IPPROTO_ICMPV6) == 22

View file

@ -1,15 +1,6 @@
discard """
cmd: "nim c -r --styleCheck:hint --panics:on $options $file"
matrix: "-d:danger; -d:release"
targets: "c cpp"
nimout: ""
action: "run"
exitcode: 0
timeout: 60.0
"""
import std/varints import std/varints
# xxx doesn't work with js: tvarints.nim(18, 14) `wrLen == rdLen` [AssertionDefect]
block: block:
var dest: array[50, byte] var dest: array[50, byte]
@ -39,46 +30,39 @@ block:
block: block:
var hugeIntArray: array[50, byte] var hugeIntArray: array[50, byte]
var readedInt: uint64 var readedInt: uint64
doAssert writeVu64(hugeIntArray, 0.uint64) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == 0.uint64 template chk(a) =
doAssert writeVu64(hugeIntArray, uint64.high) == readVu64(hugeIntArray, readedInt) let b = cast[uint64](a)
doAssert readedInt == uint64.high doAssert writeVu64(hugeIntArray, b) == readVu64(hugeIntArray, readedInt)
doAssert writeVu64(hugeIntArray, uint64(int64.high)) == readVu64(hugeIntArray, readedInt) doAssert readedInt == b
doAssert readedInt == uint64(int64.high)
doAssert writeVu64(hugeIntArray, uint64(int32.high)) == readVu64(hugeIntArray, readedInt) chk 0
doAssert readedInt == uint64(int32.high) chk uint64.high
doAssert writeVu64(hugeIntArray, uint64(int16.high)) == readVu64(hugeIntArray, readedInt) chk int64.high
doAssert readedInt == uint64(int16.high) chk int32.high
doAssert writeVu64(hugeIntArray, uint64(int8.high)) == readVu64(hugeIntArray, readedInt) chk int16.high
doAssert readedInt == uint64(int8.high) chk int16.high
doAssert writeVu64(hugeIntArray, cast[uint64](0.0)) == readVu64(hugeIntArray, readedInt) chk int8.high
doAssert readedInt == cast[uint64](0.0) chk 0.0
doAssert writeVu64(hugeIntArray, cast[uint64](-0.0)) == readVu64(hugeIntArray, readedInt) chk -0.0
doAssert readedInt == cast[uint64](-0.0) chk 0.1
doAssert writeVu64(hugeIntArray, cast[uint64](0.1)) == readVu64(hugeIntArray, readedInt) chk Inf
doAssert readedInt == cast[uint64](0.1) chk NegInf
doAssert writeVu64(hugeIntArray, cast[uint64](0.9555555555555555555555501)) == readVu64(hugeIntArray, readedInt) chk Nan
doAssert readedInt == cast[uint64](0.9555555555555555555555501) chk 3.1415926535897932384626433
doAssert writeVu64(hugeIntArray, cast[uint64](+Inf)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](+Inf)
doAssert writeVu64(hugeIntArray, cast[uint64](NegInf)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](NegInf)
doAssert writeVu64(hugeIntArray, cast[uint64](Nan)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](Nan)
doAssert writeVu64(hugeIntArray, cast[uint64](3.1415926535897932384626433)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](3.1415926535897932384626433)
doAssert writeVu64(hugeIntArray, cast[uint64](2.71828182845904523536028747)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](2.71828182845904523536028747)
block: block:
doAssert encodeZigzag(decodeZigzag(0.uint64)) == 0.uint64 template chk(a) =
doAssert encodeZigzag(decodeZigzag(uint64(uint32.high))) == uint64(uint32.high) let b = cast[uint64](a)
doAssert encodeZigzag(decodeZigzag(uint64(int32.high))) == uint64(int32.high) doAssert encodeZigzag(decodeZigzag(b)) == b
doAssert encodeZigzag(decodeZigzag(uint64(int16.high))) == uint64(int16.high) chk 0
doAssert encodeZigzag(decodeZigzag(uint64(int8.high))) == uint64(int8.high) chk uint32.high
doAssert encodeZigzag(decodeZigzag(cast[uint64](0.0))) == cast[uint64](0.0) chk int32.high
doAssert encodeZigzag(decodeZigzag(cast[uint64](0.1))) == cast[uint64](0.1) chk int16.high
doAssert encodeZigzag(decodeZigzag(cast[uint64](0.9555555555555555555555501))) == cast[uint64](0.9555555555555555555555501) chk int8.high
doAssert encodeZigzag(decodeZigzag(cast[uint64](+Inf))) == cast[uint64](+Inf) chk 0.0
doAssert encodeZigzag(decodeZigzag(cast[uint64](3.1415926535897932384626433))) == cast[uint64](3.1415926535897932384626433) chk 0.1
doAssert encodeZigzag(decodeZigzag(cast[uint64](2.71828182845904523536028747))) == cast[uint64](2.71828182845904523536028747) chk 0.9555555555555555555555501
chk Inf
chk 3.1415926535897932384626433
chk 2.71828182845904523536028747