make tests green again

This commit is contained in:
Andreas Rumpf
2017-11-18 23:03:16 +01:00
parent a9ac241691
commit 1548743856
5 changed files with 20 additions and 14 deletions

View File

@@ -127,7 +127,7 @@ proc evalTypeTrait(traitCall: PNode, operand: PType, context: PSym): PNode =
of "not":
return typeWithSonsResult(tyNot, @[operand])
of "name":
result = newStrNode(nkStrLit, operand.typeToString(preferName))
result = newStrNode(nkStrLit, operand.typeToString(preferTypeName))
result.typ = newType(tyString, context)
result.info = traitCall.info
of "arity":

View File

@@ -14,7 +14,8 @@ import
type
TPreferedDesc* = enum
preferName, preferDesc, preferExported, preferModuleInfo, preferGenericArg
preferName, preferDesc, preferExported, preferModuleInfo, preferGenericArg,
preferTypeName
proc typeToString*(typ: PType; prefer: TPreferedDesc = preferName): string
template `$`*(typ: PType): string = typeToString(typ)
@@ -394,7 +395,7 @@ const
"and", "or", "not", "any", "static", "TypeFromExpr", "FieldAccessor",
"void"]
const preferToResolveSymbols = {preferName, preferModuleInfo, preferGenericArg}
const preferToResolveSymbols = {preferName, preferTypeName, preferModuleInfo, preferGenericArg}
template bindConcreteTypeToUserTypeClass*(tc, concrete: PType) =
tc.sons.safeAdd concrete
@@ -420,7 +421,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
sfAnon notin t.sym.flags:
if t.kind == tyInt and isIntLit(t):
result = t.sym.name.s & " literal(" & $t.n.intVal & ")"
elif prefer == preferName or t.sym.owner.isNil:
elif prefer in {preferName, preferTypeName} or t.sym.owner.isNil:
result = t.sym.name.s
if t.kind == tyGenericParam and t.sons != nil and t.sonsLen > 0:
result.add ": "
@@ -518,7 +519,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
result = "openarray[" & typeToString(t.sons[0]) & ']'
of tyDistinct:
result = "distinct " & typeToString(t.sons[0],
if prefer == preferModuleInfo: preferModuleInfo else: preferName)
if prefer == preferModuleInfo: preferModuleInfo else: preferTypeName)
of tyTuple:
# we iterate over t.sons here, because t.n may be nil
if t.n != nil:
@@ -532,7 +533,8 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
elif sonsLen(t) == 0:
result = "tuple[]"
else:
result = "tuple of ("
if prefer == preferTypeName: result = "("
else: result = "tuple of ("
for i in countup(0, sonsLen(t) - 1):
add(result, typeToString(t.sons[i]))
if i < sonsLen(t) - 1: add(result, ", ")

View File

@@ -40,8 +40,7 @@ proc testVarargs(x, y, z: int): seq[int] =
result = waitFor all(a, b, c)
suite "tasyncall":
test "testFuturesWithValue":
block:
let
startTime = cpuTime()
results = testFuturesWithValue(42)
@@ -51,14 +50,14 @@ suite "tasyncall":
doAssert execTime * 1000 < taskCount * sleepDuration
doAssert results == expected
test "testFuturesWithoutValues":
block:
let startTime = cpuTime()
testFuturesWithoutValues()
let execTime = cpuTime() - startTime
doAssert execTime * 1000 < taskCount * sleepDuration
test "testVarargs":
block:
let
startTime = cpuTime()
results = testVarargs(1, 2, 3)
@@ -68,7 +67,7 @@ suite "tasyncall":
doAssert execTime * 100 < taskCount * sleepDuration
doAssert results == expected
test "all on seq[Future]":
block:
let
noIntFuturesFut = all(newSeq[Future[int]]())
noVoidFuturesFut = all(newSeq[Future[void]]())

View File

@@ -1,5 +1,6 @@
discard """
exitcode: 0
disabled: '''true'''
"""
import moverloading_typedesc
import tables

View File

@@ -1,10 +1,14 @@
discard """
file: "trat_init.nim"
exitcode: "1"
output: '''true'''
"""
import rationals
var
z = Rational[int](num: 0, den: 1)
o = initRational(num=1, den=1)
a = initRational(1, 2)
r = initRational(1, 0) # this fails - no zero denominator
try:
var
r = initRational(1, 0) # this fails - no zero denominator
except AssertionError:
echo "true"