Skip to content

Commit

Permalink
add test case for #7976
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jan 2, 2019
1 parent 7c5ae00 commit 4870d95
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/issues/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory can be used for adding a test case to a github issue, eg:
issue `#7976` would have test case named `t7976.nim`
It makes it easier to find which issue corresponds to a test caes, or vice versa, and removes the guesswork of trying to figure out an appropriate directory/filename by being more systematic.
84 changes: 84 additions & 0 deletions tests/issues/t7976.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
when defined(case1):
import strformat, typetraits
type Person = tuple[name: string, age: int]
let
person1: Person = ("Peter", 30)
person2 = (name: "Peter", age: 30)
echo fmt"Tuple person1 of type {$person1.type} = {person1}"
echo fmt"Tuple person2 of type {$person2.type} = {person2}"

when defined(case2):
import strformat, typetraits
type Person = tuple[name: string, age: int]
let
person1 = (name: "Peter", age: 30)
person2: Person = ("Peter", 30)
echo fmt"Tuple person1 of type {$person1.type} = {person1}"
echo fmt"Tuple person2 of type {$person2.type} = {person2}"

when defined(case3):
import strformat, typetraits
type Person = tuple[name: string, age: int]
let
person1: Person = ("Peter", 30)
person2 = (name: "Peter", age: 30)
echo fmt"Tuple person1 of type {$person1.type} = {person1}"
echo fmt"Tuple person2 of type {$person2.type} = {person2}"

when defined(case4):
import strformat, typetraits
type Person = tuple[name: string, age: int]
let
person1: Person = ("Peter", 30)
person2 = (name: "Peter", age: 30)
echo fmt"Tuple person1 of type {$person2.type} = {person2}" # simply moved up
echo fmt"Tuple person2 of type {$person1.type} = {person1}"

when defined(case5):
import strformat, typetraits
type Person = tuple[name: string, age: int]
let
person1: Person = ("Peter", 30)
person2 = (name: "Peter", age: 30)
echo fmt"Tuple person1 of type {name(person1.type)} = {person1}"
echo fmt"Tuple person2 of type {name(person2.type)} = {person2}"

when not defined(case_any_testcase): # main driver
# import os, strutils, osproc, nre, strformat
import os, strutils, osproc, strformat
proc assertEquals[T](lhs: T, rhs: T) =
if lhs!=rhs:
echo "lhs:{\n", lhs, "}\nrhs:{", rhs, "}"
echo "lhs:\n", lhs, "\nrhs:", rhs
doAssert false

var output = ""
proc main() =
const nim = getCurrentCompilerExe()
const self = currentSourcePath
let cases = "case1 case2 case3 case4 case5".split
for opt in cases:
let cmd = fmt"{nim} c -r --colors:off --hints:off -d:case_any_testcase -d:{opt} {self}"
output.add "test case: " & opt & "\n"
let ret = execCmdEx(cmd, {poStdErrToStdOut, poEvalCommand})
doAssert ret.exitCode == 0
output.add ret.output
let expected = """
test case: case1
Tuple person1 of type Person = (name: "Peter", age: 30)
Tuple person2 of type tuple[name: string, age: int] = (name: "Peter", age: 30)
test case: case2
Tuple person1 of type tuple[name: string, age: int] = (name: "Peter", age: 30)
Tuple person2 of type Person = (name: "Peter", age: 30)
test case: case3
Tuple person1 of type Person = (name: "Peter", age: 30)
Tuple person2 of type tuple[name: string, age: int] = (name: "Peter", age: 30)
test case: case4
Tuple person1 of type tuple[name: string, age: int] = (name: "Peter", age: 30)
Tuple person2 of type Person = (name: "Peter", age: 30)
test case: case5
Tuple person1 of type Person = (name: "Peter", age: 30)
Tuple person2 of type tuple[name: string, age: int] = (name: "Peter", age: 30)
"""
assertEquals(output, expected)
main()

0 comments on commit 4870d95

Please sign in to comment.