some test cleanups & category reorganization (#22010)

* clean up some test categories

* mention exact slice issue

* magics into system

* move trangechecks into overflow

* move tmemory to system

* try fix CI

* try fix CI

* final CI fix
This commit is contained in:
metagn
2023-06-06 07:54:07 +03:00
committed by GitHub
parent 2ab948ce53
commit b97d603cd0
134 changed files with 189 additions and 374 deletions

View File

@@ -0,0 +1,10 @@
import mambsym2 # import TExport
type
TExport* = enum x, y, z
TOtherEnum* = enum mDec, mInc, mAssign
proc ha() =
var
x: TExport # no error
discard

View File

@@ -0,0 +1,3 @@
type
TExport* = enum a, b, c

View File

@@ -0,0 +1,7 @@
import mambsys2 # import TExport
type
TExport* = enum x, y, z
proc foo*(x: int) =
discard

View File

@@ -0,0 +1,4 @@
type
TExport* = enum x, y, z # exactly the same type!
proc foo*(x: int) = discard

10
tests/lookups/mbind3.nim Normal file
View File

@@ -0,0 +1,10 @@
# Module A
var
lastId = 0
template genId*: int =
bind lastId
inc(lastId)
lastId

View File

@@ -0,0 +1,19 @@
discard """
action: reject
cmd: "nim check $file"
nimout: '''
tambprocvar.nim(15, 11) Error: ambiguous identifier 'foo' -- use one of the following:
tambprocvar.foo: proc (x: int){.noSideEffect, gcsafe.}
tambprocvar.foo: proc (x: float){.noSideEffect, gcsafe.}
'''
"""
block:
proc foo(x: int) = discard
proc foo(x: float) = discard
let x = foo
block:
let x = `+` #[tt.Error
^ ambiguous identifier '+' -- use one of the following:]#

13
tests/lookups/tambsym.nim Normal file
View File

@@ -0,0 +1,13 @@
discard """
errormsg: "ambiguous identifier"
file: "tambsym.nim"
line: 11
"""
# Test ambiguous symbols
import mambsym1, mambsym2
var
v: TExport #ERROR_MSG ambiguous identifier
v = y

View File

@@ -0,0 +1,21 @@
discard """
output: "7"
"""
# Test overloading of procs with locals
type
TMyType = object
len: int
data: string
proc len(x: TMyType): int {.inline.} = return x.len
proc x(s: TMyType, len: int) =
writeLine(stdout, len(s))
var
m: TMyType
m.len = 7
m.data = "1234"
x(m, 5) #OUT 7

View File

@@ -0,0 +1,16 @@
discard """
errormsg: "ambiguous enum field"
file: "tambsym3.nim"
line: 14
"""
# Test ambiguous symbols
import mambsym1, times
{.hint[AmbiguousEnum]: on.}
{.hintAsError[AmbiguousEnum]: on.}
var
v = mDec #ERROR_MSG ambiguous identifier
writeLine(stdout, ord(v))

10
tests/lookups/tambsys.nim Normal file
View File

@@ -0,0 +1,10 @@
discard """
output: ""
"""
# Test ambiguous symbols
import mambsys1, mambsys2
var
v: mambsys1.TExport
mambsys2.foo(3) #OUT

78
tests/lookups/tbind.nim Normal file
View File

@@ -0,0 +1,78 @@
discard """
output: '''
3
1
1
1
5
'''
"""
block tbind:
# Test the new ``bind`` keyword for templates
proc p1(x: int8, y: int): int = return x + y
template tempBind(x, y): untyped =
bind p1
p1(x, y)
proc p1(x: int, y: int8): int = return x - y
# This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6,
# because it is not ambiguous there. But it is ambiguous after line 8.
echo tempBind(1'i8, 2'i8) #OUT 3
import mbind3
echo genId() #OUT 1
import strtabs
block tbinoverload:
template t() =
block:
bind newStringTable
discard {"Content-Type": "text/html"}.newStringTable()
discard {:}.newStringTable
#discard {"Content-Type": "text/html"}.newStringTable()
t()
block tmixin:
type
TFoo1 = object of RootObj
v: int
TFoo2 = object of TFoo1
v2: int
proc test(f: TFoo1) =
echo "1"
proc Foo[T](f: T) =
mixin test
test(f)
var
a: TFoo1
b: TFoo2
proc test(f: TFoo2) =
echo "2"
Foo(a)
Foo(b)
# issue #11811
proc p(a : int) =
echo a
proc printVar*[T:int|float|string](a : T) =
bind p
p(a)
printVar(5)

16
tests/lookups/tgensym.nim Normal file
View File

@@ -0,0 +1,16 @@
discard """
output: "123100"
"""
template hygienic(val) =
var x = val
stdout.write x
var x = 100
hygienic 1
hygienic 2
hygienic 3
echo x

View File

@@ -0,0 +1,54 @@
discard """
output: '''true'''
"""
# We need to open the gensym'ed symbol again so that the instantiation
# creates a fresh copy; but this is wrong the very first reason for gensym
# is that scope rules cannot be used! So simply removing 'sfGenSym' does
# not work. Copying the symbol does not work either because we're already
# the owner of the symbol! What we need to do is to copy the symbol
# in the generic instantiation process...
type
TA = object
x: int
TB = object
x: string
template genImpl() =
var gensymed: T
when T is TB:
gensymed.x = "abc"
else:
gensymed.x = 123
result = move gensymed
proc gen[T](x: T): T =
genImpl()
var
a: TA
b: TB
let x = gen(a)
let y = gen(b)
doAssert x.x == 123
doAssert y.x == "abc"
# test symbol equality
import macros
static:
let sym1 = genSym()
let sym2 = genSym()
let sym3 = sym1
let nimsym = sym1.symbol
doAssert sym1 == sym1
doAssert sym2 != sym3
doAssert sym2.symbol != sym3.symbol
doAssert sym3 == sym1
doAssert sym1.symbol == sym1.symbol
doAssert nimsym == nimsym
echo "true"

View File

@@ -0,0 +1,10 @@
discard """
errormsg: "type mismatch: got <typedesc[float], string>"
line: 10
"""
proc foo(T: typedesc; some: T) =
echo($some)
foo int, 4
foo float, "bad"

View File

@@ -0,0 +1,23 @@
discard """
errormsg: "type mismatch: got <proc (s: TScgi: ScgiState or AsyncScgiState) | proc (client: AsyncSocket, headers: StringTableRef, input: string){.noSideEffect, gcsafe.}>"
line: 23
"""
# Fake ScgiState objects, from now-deprecated scgi module
type
ScgiState* = object of RootObj ## SCGI state object
AsyncScgiState* = object of RootObj ## SCGI state object
#bug #442
import asyncnet, strtabs
proc handleSCGIRequest[TScgi: ScgiState | AsyncScgiState](s: TScgi) =
discard
proc handleSCGIRequest(client: AsyncSocket, headers: StringTableRef,
input: string) =
discard
proc test(handle: proc (client: AsyncSocket, headers: StringTableRef,
input: string), b: int) =
discard
test(handleSCGIRequest)

View File

@@ -0,0 +1,15 @@
discard """
errormsg: "ambiguous call"
file: "told_bind_expr.nim"
line: 13
"""
# Pre-0.9 deprecated bind expression syntax
proc p1(x: int8, y: int): int = return x + y
proc p1(x: int, y: int8): int = return x - y
template tempBind(x, y): untyped =
(bind p1(x, y)) #ERROR_MSG ambiguous call
echo tempBind(1'i8, 2'i8)