diff options
author | Araq <rumpf_a@web.de> | 2014-04-21 00:07:40 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-04-21 00:07:40 +0200 |
commit | 2c972427399da894f91d0a4bd067b63866bb20ea (patch) | |
tree | 41317db61b4c404940816989172bc1c921b7ccf0 /tests | |
parent | e3fab47508138687cdc85553440c8313606395c3 (diff) | |
parent | 5cf8c05a226ba617a6e6de8ebe7e82c19d680b98 (diff) | |
download | Nim-2c972427399da894f91d0a4bd067b63866bb20ea.tar.gz |
Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
Diffstat (limited to 'tests')
-rw-r--r-- | tests/closure/tclosuremacro.nim | 8 | ||||
-rw-r--r-- | tests/macros/texprcolonexpr.nim | 19 | ||||
-rw-r--r-- | tests/stdlib/tgetfileinfo.nim | 93 | ||||
-rw-r--r-- | tests/system/tsysspawnbadarg.nim | 7 |
4 files changed, 123 insertions, 4 deletions
diff --git a/tests/closure/tclosuremacro.nim b/tests/closure/tclosuremacro.nim index 008078bbb..12e463316 100644 --- a/tests/closure/tclosuremacro.nim +++ b/tests/closure/tclosuremacro.nim @@ -5,6 +5,7 @@ discard """ 3 3 noReturn +6 ''' """ @@ -36,8 +37,7 @@ echo doWithOneAndTwo((x, y) => x + y) noReturn(() -> void => echo("noReturn")) -when false: - proc pass2(f: (int, int) -> int): (int) -> int = - (x: int) -> int => f(2, x) +proc pass2(f: (int, int) -> int): (int) -> int = + (x: int) -> int => f(2, x) - #echo pass2((x, y) => x + y) +echo pass2((x, y) => x + y)(4) diff --git a/tests/macros/texprcolonexpr.nim b/tests/macros/texprcolonexpr.nim new file mode 100644 index 000000000..3b2c86b77 --- /dev/null +++ b/tests/macros/texprcolonexpr.nim @@ -0,0 +1,19 @@ +discard """ + msg: ''' +Infix + Ident !"=>" + Call + Ident !"name" + Ident !"a" + ExprColonExpr + Ident !"b" + Ident !"cint" + NilLit nil +''' +""" +import macros + +macro def(x: stmt): stmt {.immediate.} = + echo treeRepr(x) + +def name(a, b:cint) => nil diff --git a/tests/stdlib/tgetfileinfo.nim b/tests/stdlib/tgetfileinfo.nim new file mode 100644 index 000000000..49a019061 --- /dev/null +++ b/tests/stdlib/tgetfileinfo.nim @@ -0,0 +1,93 @@ +discard """ + output: "" +""" + +import os, strutils +# Cases +# 1 - String : Existing File : Symlink true +# 2 - String : Existing File : Symlink false +# 3 - String : Non-existing File : Symlink true +# 4 - String : Non-existing File : Symlink false +# 5 - Handle : Valid File +# 6 - Handle : Invalid File +# 7 - Handle : Valid Handle +# 8 - Handle : Invalid Handle + +proc genBadFileName(limit = 100): string = + ## Generates a filename of a nonexistant file. + ## Returns "" if generation fails. + result = "a" + var hitLimit = true + + for i in 0..100: + if existsFile(result): + result.add("a") + else: + hitLimit = false + break + if hitLimit: + result = "" + +proc caseOneAndTwo(followLink: bool) = + try: + discard getFileInfo(getAppFilename(), followLink) + #echo("String : Existing File : Symlink $# : Success" % $followLink) + except EOS: + echo("String : Existing File : Symlink $# : Failure" % $followLink) + +proc caseThreeAndFour(followLink: bool) = + var invalidName = genBadFileName() + try: + discard getFileInfo(invalidName, true) + echo("String : Non-existing File : Symlink $# : Failure" % $followLink) + except EOS: + #echo("String : Non-existing File : Symlink $# : Success" % $followLink) + +proc testGetFileInfo = + # Case 1 + caseOneAndTwo(true) + + # Case 2 + caseOneAndTwo(false) + + # Case 3 + caseThreeAndFour(true) + + # Case 4 + caseThreeAndFour(false) + + # Case 5 and 7 + block: + let + testFile = open(getAppFilename()) + testHandle = fileHandle(testFile) + try: + discard getFileInfo(testFile) + #echo("Handle : Valid File : Success") + except EIO: + echo("Handle : Valid File : Failure") + + try: + discard getFileInfo(testHandle) + #echo("Handle : Valid File : Success") + except EIO: + echo("Handle : Valid File : Failure") + + # Case 6 and 8 + block: + let + testFile: TFile = nil + testHandle = TFileHandle(-1) + try: + discard getFileInfo(testFile) + echo("Handle : Invalid File : Failure") + except EIO, EOS: + #echo("Handle : Invalid File : Success") + + try: + discard getFileInfo(testHandle) + echo("Handle : Invalid File : Failure") + except EIO, EOS: + #echo("Handle : Invalid File : Success") + +testGetFileInfo() \ No newline at end of file diff --git a/tests/system/tsysspawnbadarg.nim b/tests/system/tsysspawnbadarg.nim new file mode 100644 index 000000000..ace074602 --- /dev/null +++ b/tests/system/tsysspawnbadarg.nim @@ -0,0 +1,7 @@ +discard """ + line: 7 + errormsg: "'spawn' takes a call expression of type void" + cmd: "nimrod $target --threads:on $options $file" +""" + +spawn(1) |