Skip to content

Commit a36efb5

Browse files
authored
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
1 parent b7ad29e commit a36efb5

File tree

7 files changed

+73
-106
lines changed

7 files changed

+73
-106
lines changed

testament/specs.nim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ proc parseSpec*(filename: string): TSpec =
253253
var p: CfgParser
254254
open(p, ss, filename, 1)
255255
var flags: HashSet[string]
256+
var nimoutFound = false
256257
while true:
257258
var e = next(p)
258259
case e.kind
@@ -309,6 +310,7 @@ proc parseSpec*(filename: string): TSpec =
309310
result.action = actionReject
310311
of "nimout":
311312
result.nimout = e.value
313+
nimoutFound = true
312314
of "nimoutfull":
313315
result.nimoutFull = parseCfgBool(e.value)
314316
of "batchable":
@@ -401,6 +403,9 @@ proc parseSpec*(filename: string): TSpec =
401403
if skips.anyIt(it in result.file):
402404
result.err = reDisabled
403405

406+
if nimoutFound and result.nimout.len == 0 and not result.nimoutFull:
407+
result.parseErrors.addLine "empty `nimout` is vacuously true, use `nimoutFull:true` if intentional"
408+
404409
result.inCurrentBatch = isCurrentBatch(testamentData0, filename) or result.unbatchable
405410
if not result.inCurrentBatch:
406411
result.err = reDisabled
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
discard """
2-
targets: "c"
3-
output: "test AObj"
4-
action: "compile"
5-
exitcode: 0
6-
timeout: 60.0
7-
"""
1+
# bug #9091
2+
83
import streams
94

105
block:
@@ -18,6 +13,8 @@ block:
1813
let mi = new Mine
1914

2015
str.write(mi)
16+
str.setPosition 0
17+
doAssert str.readAll == "sure"
2118

2219
block:
2320
type
@@ -27,10 +24,10 @@ block:
2724
proc foo(a: int): string = ""
2825

2926
proc test(args: varargs[string, foo]) =
30-
echo "varargs"
27+
doAssert false
3128

3229
proc test(a: AObj) =
33-
echo "test AObj"
30+
discard
3431

3532
let x = AObj()
3633
test(x)

tests/misc/t9710.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
discard """
2+
matrix: "--debugger:native"
3+
"""
4+
# bug #9710
5+
for i in 1 || 200:
6+
discard i

tests/stdlib/t9710.nim

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/stdlib/tgetprotobyname.nim

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
discard """
2-
cmd: "nim c -r --styleCheck:hint --panics:on $options $file"
3-
targets: "c"
4-
nimout: ""
5-
action: "run"
6-
exitcode: 0
7-
timeout: 60.0
8-
"""
9-
101
import nativesockets
112

12-
133
when not defined(netbsd):
144
# Ref: https://github.com/nim-lang/Nim/issues/15452 - NetBSD doesn't define an `ip` protocol
155
doAssert getProtoByName("ip") == 0

tests/stdlib/tnativesockets.nim

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
1-
discard """
2-
cmd: "nim c -r --styleCheck:hint --panics:on $options $file"
3-
targets: "c"
4-
nimout: ""
5-
action: "run"
6-
exitcode: 0
7-
timeout: 60.0
8-
"""
9-
10-
import nativesockets
1+
import std/nativesockets
2+
import stdtest/testutils
113

4+
block:
5+
let hostname = getHostname()
6+
doAssert hostname.len > 0
127

138
when defined(windows):
14-
doAssert toInt(IPPROTO_IP) == 0.cint
15-
doAssert toInt(IPPROTO_ICMP) == 1.cint
16-
doAssert toInt(IPPROTO_TCP) == 6.cint
17-
doAssert toInt(IPPROTO_UDP) == 17.cint
18-
doAssert toInt(IPPROTO_IPV6) == 41.cint
19-
doAssert toInt(IPPROTO_ICMPV6) == 58.cint
20-
doAssert toInt(IPPROTO_RAW) == 20.cint
9+
assertAll:
10+
toInt(IPPROTO_IP) == 0
11+
toInt(IPPROTO_ICMP) == 1
12+
toInt(IPPROTO_TCP) == 6
13+
toInt(IPPROTO_UDP) == 17
14+
toInt(IPPROTO_IPV6) == 41
15+
toInt(IPPROTO_ICMPV6) == 58
16+
toInt(IPPROTO_RAW) == 20
2117

22-
# no changes to enum value
23-
doAssert ord(IPPROTO_TCP) == 6
24-
doAssert ord(IPPROTO_UDP) == 17
25-
doAssert ord(IPPROTO_IP) == 18
26-
doAssert ord(IPPROTO_IPV6) == 19
27-
doAssert ord(IPPROTO_RAW) == 20
28-
doAssert ord(IPPROTO_ICMP) == 21
29-
doAssert ord(IPPROTO_ICMPV6) == 22
18+
# no changes to enum value
19+
ord(IPPROTO_TCP) == 6
20+
ord(IPPROTO_UDP) == 17
21+
ord(IPPROTO_IP) == 18
22+
ord(IPPROTO_IPV6) == 19
23+
ord(IPPROTO_RAW) == 20
24+
ord(IPPROTO_ICMP) == 21
25+
ord(IPPROTO_ICMPV6) == 22

tests/stdlib/tvarints.nim

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
discard """
2-
cmd: "nim c -r --styleCheck:hint --panics:on $options $file"
3-
matrix: "-d:danger; -d:release"
4-
targets: "c cpp"
5-
nimout: ""
6-
action: "run"
7-
exitcode: 0
8-
timeout: 60.0
9-
"""
10-
111
import std/varints
122

3+
# xxx doesn't work with js: tvarints.nim(18, 14) `wrLen == rdLen` [AssertionDefect]
134

145
block:
156
var dest: array[50, byte]
@@ -39,46 +30,39 @@ block:
3930
block:
4031
var hugeIntArray: array[50, byte]
4132
var readedInt: uint64
42-
doAssert writeVu64(hugeIntArray, 0.uint64) == readVu64(hugeIntArray, readedInt)
43-
doAssert readedInt == 0.uint64
44-
doAssert writeVu64(hugeIntArray, uint64.high) == readVu64(hugeIntArray, readedInt)
45-
doAssert readedInt == uint64.high
46-
doAssert writeVu64(hugeIntArray, uint64(int64.high)) == readVu64(hugeIntArray, readedInt)
47-
doAssert readedInt == uint64(int64.high)
48-
doAssert writeVu64(hugeIntArray, uint64(int32.high)) == readVu64(hugeIntArray, readedInt)
49-
doAssert readedInt == uint64(int32.high)
50-
doAssert writeVu64(hugeIntArray, uint64(int16.high)) == readVu64(hugeIntArray, readedInt)
51-
doAssert readedInt == uint64(int16.high)
52-
doAssert writeVu64(hugeIntArray, uint64(int8.high)) == readVu64(hugeIntArray, readedInt)
53-
doAssert readedInt == uint64(int8.high)
54-
doAssert writeVu64(hugeIntArray, cast[uint64](0.0)) == readVu64(hugeIntArray, readedInt)
55-
doAssert readedInt == cast[uint64](0.0)
56-
doAssert writeVu64(hugeIntArray, cast[uint64](-0.0)) == readVu64(hugeIntArray, readedInt)
57-
doAssert readedInt == cast[uint64](-0.0)
58-
doAssert writeVu64(hugeIntArray, cast[uint64](0.1)) == readVu64(hugeIntArray, readedInt)
59-
doAssert readedInt == cast[uint64](0.1)
60-
doAssert writeVu64(hugeIntArray, cast[uint64](0.9555555555555555555555501)) == readVu64(hugeIntArray, readedInt)
61-
doAssert readedInt == cast[uint64](0.9555555555555555555555501)
62-
doAssert writeVu64(hugeIntArray, cast[uint64](+Inf)) == readVu64(hugeIntArray, readedInt)
63-
doAssert readedInt == cast[uint64](+Inf)
64-
doAssert writeVu64(hugeIntArray, cast[uint64](NegInf)) == readVu64(hugeIntArray, readedInt)
65-
doAssert readedInt == cast[uint64](NegInf)
66-
doAssert writeVu64(hugeIntArray, cast[uint64](Nan)) == readVu64(hugeIntArray, readedInt)
67-
doAssert readedInt == cast[uint64](Nan)
68-
doAssert writeVu64(hugeIntArray, cast[uint64](3.1415926535897932384626433)) == readVu64(hugeIntArray, readedInt)
69-
doAssert readedInt == cast[uint64](3.1415926535897932384626433)
70-
doAssert writeVu64(hugeIntArray, cast[uint64](2.71828182845904523536028747)) == readVu64(hugeIntArray, readedInt)
71-
doAssert readedInt == cast[uint64](2.71828182845904523536028747)
33+
34+
template chk(a) =
35+
let b = cast[uint64](a)
36+
doAssert writeVu64(hugeIntArray, b) == readVu64(hugeIntArray, readedInt)
37+
doAssert readedInt == b
38+
39+
chk 0
40+
chk uint64.high
41+
chk int64.high
42+
chk int32.high
43+
chk int16.high
44+
chk int16.high
45+
chk int8.high
46+
chk 0.0
47+
chk -0.0
48+
chk 0.1
49+
chk Inf
50+
chk NegInf
51+
chk Nan
52+
chk 3.1415926535897932384626433
7253

7354
block:
74-
doAssert encodeZigzag(decodeZigzag(0.uint64)) == 0.uint64
75-
doAssert encodeZigzag(decodeZigzag(uint64(uint32.high))) == uint64(uint32.high)
76-
doAssert encodeZigzag(decodeZigzag(uint64(int32.high))) == uint64(int32.high)
77-
doAssert encodeZigzag(decodeZigzag(uint64(int16.high))) == uint64(int16.high)
78-
doAssert encodeZigzag(decodeZigzag(uint64(int8.high))) == uint64(int8.high)
79-
doAssert encodeZigzag(decodeZigzag(cast[uint64](0.0))) == cast[uint64](0.0)
80-
doAssert encodeZigzag(decodeZigzag(cast[uint64](0.1))) == cast[uint64](0.1)
81-
doAssert encodeZigzag(decodeZigzag(cast[uint64](0.9555555555555555555555501))) == cast[uint64](0.9555555555555555555555501)
82-
doAssert encodeZigzag(decodeZigzag(cast[uint64](+Inf))) == cast[uint64](+Inf)
83-
doAssert encodeZigzag(decodeZigzag(cast[uint64](3.1415926535897932384626433))) == cast[uint64](3.1415926535897932384626433)
84-
doAssert encodeZigzag(decodeZigzag(cast[uint64](2.71828182845904523536028747))) == cast[uint64](2.71828182845904523536028747)
55+
template chk(a) =
56+
let b = cast[uint64](a)
57+
doAssert encodeZigzag(decodeZigzag(b)) == b
58+
chk 0
59+
chk uint32.high
60+
chk int32.high
61+
chk int16.high
62+
chk int8.high
63+
chk 0.0
64+
chk 0.1
65+
chk 0.9555555555555555555555501
66+
chk Inf
67+
chk 3.1415926535897932384626433
68+
chk 2.71828182845904523536028747

0 commit comments

Comments
 (0)