Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Apr 29, 2021
1 parent 684ab9c commit 6f45f75
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 36 deletions.
6 changes: 4 additions & 2 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):

const
errTypeMismatch = "type mismatch: got <"
errButExpected = "but expected one of: "
errButExpected = "but expected one of:"
errUndeclaredField = "undeclared field: '$1'"
errUndeclaredRoutine = "attempting to call undeclared routine: '$1'"
errBadRoutine = "attempting to call routine: '$1'$2"
Expand Down Expand Up @@ -338,7 +338,9 @@ proc getMsgDiagnostic(c: PContext, flags: TExprFlags, n, f: PNode): string =
discard
else:
typeHint = " for type " & getProcHeader(c.config, sym)
result = errUndeclaredField % ident & typeHint & " " & result
if result.len > 0:
result = " " & result
result = errUndeclaredField % ident & typeHint & result
else:
if result.len == 0: result = errUndeclaredRoutine % ident
else: result = errBadRoutine % [ident, result]
Expand Down
25 changes: 20 additions & 5 deletions testament/testament.nim
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ Tests failed and allowed to fail: $3 / $1 <br />
Tests skipped: $4 / $1 <br />
""" % [$x.total, $x.passed, $x.failedButAllowed, $x.skipped]

import std/tempfiles
proc showDiff(a, b: string) =
# PRTEMP FACTOR MOVE std/private/gitutils.nim
let (fda, patha) = createTempFile("", "")
let (fdb, pathb) = createTempFile("", "")
defer:
close fda
removeFile(patha)
close fdb
removeFile(pathb)
writeFile(patha, a)
writeFile(pathb, b)
# discard execShellCmd("diff -uNdr $1 $2" % [patha.quoteShell, pathb.quoteShell])
discard execShellCmd("git diff --no-index $1 $2" % [patha.quoteShell, pathb.quoteShell])

proc addResult(r: var TResults, test: TTest, target: TTarget,
expected, given: string, successOrig: TResultEnum, allowFailure = false) =
# test.name is easier to find than test.name.extractFilename
Expand Down Expand Up @@ -303,11 +318,11 @@ proc addResult(r: var TResults, test: TTest, target: TTarget,
# expected is empty, no reason to print it.
echo given
else:
maybeStyledEcho fgYellow, "Expected:"
maybeStyledEcho styleBright, expected, "\n"
maybeStyledEcho fgYellow, "Gotten:"
maybeStyledEcho styleBright, given, "\n"

# maybeStyledEcho fgYellow, "Expected:"
# maybeStyledEcho styleBright, expected, "\n"
# maybeStyledEcho fgYellow, "Gotten:"
# maybeStyledEcho styleBright, given, "\n"
showDiff(expected, given)

if backendLogging and (isAppVeyor or isAzure):
let (outcome, msg) =
Expand Down
38 changes: 19 additions & 19 deletions tests/concepts/texplain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ proc e(o: ExplainedConcept): int
required type for o: ExplainedConcept
but expression '10' is of type: int literal(10)
texplain.nim(128, 6) ExplainedConcept: undeclared field: 'foo'
texplain.nim(128, 6) ExplainedConcept: undeclared field: '.'
texplain.nim(128, 6) ExplainedConcept: expression '.' cannot be called
texplain.nim(128, 6) ExplainedConcept: expression '' has no type (or is ambiguous)
texplain.nim(128, 6) ExplainedConcept: expression 'error' has no type (or is ambiguous)
texplain.nim(128, 5) ExplainedConcept: concept predicate failed
texplain.nim(129, 6) ExplainedConcept: undeclared field: 'bar'
texplain.nim(129, 6) ExplainedConcept: undeclared field: '.'
texplain.nim(129, 6) ExplainedConcept: expression '.' cannot be called
texplain.nim(129, 6) ExplainedConcept: expression '' has no type (or is ambiguous)
texplain.nim(129, 6) ExplainedConcept: expression 'error' has no type (or is ambiguous)
texplain.nim(128, 5) ExplainedConcept: concept predicate failed
texplain.nim(168, 10) Hint: Non-matching candidates for e(10)
Expand All @@ -29,14 +25,10 @@ proc e(o: ExplainedConcept): int
required type for o: ExplainedConcept
but expression '10' is of type: int literal(10)
texplain.nim(128, 6) ExplainedConcept: undeclared field: 'foo'
texplain.nim(128, 6) ExplainedConcept: undeclared field: '.'
texplain.nim(128, 6) ExplainedConcept: expression '.' cannot be called
texplain.nim(128, 6) ExplainedConcept: expression '' has no type (or is ambiguous)
texplain.nim(128, 6) ExplainedConcept: expression 'error' has no type (or is ambiguous)
texplain.nim(128, 5) ExplainedConcept: concept predicate failed
texplain.nim(129, 6) ExplainedConcept: undeclared field: 'bar'
texplain.nim(129, 6) ExplainedConcept: undeclared field: '.'
texplain.nim(129, 6) ExplainedConcept: expression '.' cannot be called
texplain.nim(129, 6) ExplainedConcept: expression '' has no type (or is ambiguous)
texplain.nim(129, 6) ExplainedConcept: expression 'error' has no type (or is ambiguous)
texplain.nim(128, 5) ExplainedConcept: concept predicate failed
texplain.nim(172, 20) Error: type mismatch: got <NonMatchingType>
Expand Down Expand Up @@ -88,14 +80,10 @@ proc f(o: NestedConcept)
required type for o: NestedConcept
but expression 'y' is of type: MatchingType
texplain.nim(132, 6) RegularConcept: undeclared field: 'foo'
texplain.nim(132, 6) RegularConcept: undeclared field: '.'
texplain.nim(132, 6) RegularConcept: expression '.' cannot be called
texplain.nim(132, 6) RegularConcept: expression '' has no type (or is ambiguous)
texplain.nim(132, 6) RegularConcept: expression 'error' has no type (or is ambiguous)
texplain.nim(132, 5) RegularConcept: concept predicate failed
texplain.nim(133, 6) RegularConcept: undeclared field: 'bar'
texplain.nim(133, 6) RegularConcept: undeclared field: '.'
texplain.nim(133, 6) RegularConcept: expression '.' cannot be called
texplain.nim(133, 6) RegularConcept: expression '' has no type (or is ambiguous)
texplain.nim(133, 6) RegularConcept: expression 'error' has no type (or is ambiguous)
texplain.nim(132, 5) RegularConcept: concept predicate failed
texplain.nim(136, 5) NestedConcept: concept predicate failed
Expand All @@ -121,7 +109,19 @@ expression: f(y)'''



# line 120 HERE












# line 124 HERE

type
ExplainedConcept {.explain.} = concept o
Expand Down
3 changes: 1 addition & 2 deletions tests/errmsgs/tsigmatch2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ proc foo(i: Foo): string
but expression '1.2' is of type: float64
expression: foo(1.2)
tsigmatch2.nim(40, 14) Error: expression '' has no type (or is ambiguous)
tsigmatch2.nim(40, 14) Error: expression 'error' has no type (or is ambiguous)
tsigmatch2.nim(46, 7) Error: type mismatch: got <int literal(1)>
but expected one of:
proc foo(args: varargs[string, myproc])
Expand Down Expand Up @@ -44,4 +44,3 @@ block:
let temp = 12.isNil
proc foo(args: varargs[string, myproc]) = discard
foo 1
static: echo "done"
8 changes: 4 additions & 4 deletions tests/errmsgs/tundeclared_routine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ nimout: '''
tundeclared_routine.nim(24, 17) Error: attempting to call routine: 'myiter'
found tundeclared_routine.myiter(a: string) [iterator declared in tundeclared_routine.nim(22, 12)]
found tundeclared_routine.myiter() [iterator declared in tundeclared_routine.nim(23, 12)]
tundeclared_routine.nim(24, 17) Error: expression 'error' has no type (or is ambiguous)
tundeclared_routine.nim(29, 28) Error: invalid pragma: myPragma
tundeclared_routine.nim(36, 13) Error: undeclared field: 'bar3' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(33, 8)]
found tundeclared_routine.bar3() [iterator declared in tundeclared_routine.nim(35, 12)]
tundeclared_routine.nim(36, 13) Error: expression 'error' has no type (or is ambiguous)
tundeclared_routine.nim(41, 13) Error: undeclared field: 'bar4' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(39, 8)]
tundeclared_routine.nim(44, 15) Error: attempting to call routine: 'bad5'
tundeclared_routine.nim(41, 13) Error: expression 'error' has no type (or is ambiguous)
tundeclared_routine.nim(44, 11) Error: undeclared identifier: 'bad5'
'''
"""





# line 20
block:
iterator myiter(a:string): int = discard
Expand Down
8 changes: 4 additions & 4 deletions tests/objects/t17437.nim
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
discard """
cmd: "nim check $file"
cmd: "nim check --hints:off $file"
errormsg: ""
nimout: '''
t17437.nim(20, 16) Error: undeclared identifier: 'x'
t17437.nim(20, 16) Error: expression 'x' has no type (or is ambiguous)
t17437.nim(20, 16) Error: expression 'error x' has no type (or is ambiguous)
t17437.nim(20, 19) Error: incorrect object construction syntax
t17437.nim(20, 19) Error: incorrect object construction syntax
t17437.nim(20, 12) Error: expression '' has no type (or is ambiguous)
t17437.nim(20, 12) Error: expression 'error' has no type (or is ambiguous)
'''
"""

Expand All @@ -17,6 +17,6 @@ type
x, y: int

proc m =
var v = V(x: x, y)
var v = V(x: x, y) # PRTEMP error x

m()

0 comments on commit 6f45f75

Please sign in to comment.