summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/async/tasynceverror.nim66
-rw-r--r--tests/async/tgenericasync.nim14
-rw-r--r--tests/collections/ttables.nim33
-rw-r--r--tests/generics/tstatictalias.nim20
-rw-r--r--tests/js/tconsole.nim13
-rw-r--r--tests/macros/tdump.nim13
-rw-r--r--tests/osproc/tafalse.nim3
-rw-r--r--tests/osproc/texitcode.nim18
-rw-r--r--tests/osproc/tworkingdir.nim16
-rw-r--r--tests/stdlib/tgetfileinfo.nim40
-rw-r--r--tests/stdlib/ttime.nim25
-rw-r--r--tests/template/tconfusinglocal.nim13
-rw-r--r--tests/testament/categories.nim17
-rw-r--r--tests/testament/tester.nim2
-rw-r--r--tests/vm/tgorge.bat1
-rw-r--r--tests/vm/tgorge.nim12
-rw-r--r--tests/vm/tgorge.sh2
17 files changed, 237 insertions, 71 deletions
diff --git a/tests/async/tasynceverror.nim b/tests/async/tasynceverror.nim
deleted file mode 100644
index dd05c831b..000000000
--- a/tests/async/tasynceverror.nim
+++ /dev/null
@@ -1,66 +0,0 @@
-discard """
-  file: "tasynceverror.nim"
-  exitcode: 1
-  outputsub: "Error: unhandled exception: "
-"""
-# error message is actually different on OSX
-import
-    asyncdispatch,
-    asyncnet,
-    nativesockets,
-    os
-
-
-const
-    testHost = "127.0.0.1"
-    testPort = Port(17357)
-
-
-when defined(windows) or defined(nimdoc):
-    # TODO: just make it work on Windows for now.
-    quit("Error: unhandled exception: Connection reset by peer")
-else:
-    proc createListenSocket(host: string, port: Port): TAsyncFD =
-        result = newAsyncNativeSocket()
-
-        SocketHandle(result).setSockOptInt(SOL_SOCKET, SO_REUSEADDR, 1)
-
-        var aiList = getAddrInfo(host, port, AF_INET)
-        if SocketHandle(result).bindAddr(aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32:
-          dealloc(aiList)
-          raiseOSError(osLastError())
-        dealloc(aiList)
-
-        if SocketHandle(result).listen(1) < 0'i32:
-            raiseOSError(osLastError())
-
-
-    proc testAsyncSend() {.async.} =
-        var
-            ls = createListenSocket(testHost, testPort)
-            s = newAsyncSocket()
-
-        await s.connect(testHost, testPort)
-
-        var ps = await ls.accept()
-        closeSocket(ls)
-
-        await ps.send("test 1", flags={})
-        s.close()
-        # This send should raise EPIPE
-        await ps.send("test 2", flags={})
-        SocketHandle(ps).close()
-
-
-    # The bug was, when the poll function handled EvError for us,
-    # our callbacks may never get executed, thus making the event
-    # loop block indefinitely. This is a timer to keep everything
-    # rolling. 400 ms is an arbitrary value, should be enough though.
-    proc timer() {.async.} =
-        await sleepAsync(400)
-        echo("Timer expired.")
-        quit(2)
-
-
-    asyncCheck(testAsyncSend())
-    waitFor(timer())
diff --git a/tests/async/tgenericasync.nim b/tests/async/tgenericasync.nim
new file mode 100644
index 000000000..ab704238a
--- /dev/null
+++ b/tests/async/tgenericasync.nim
@@ -0,0 +1,14 @@
+discard """
+  output: '''123
+abc'''
+"""
+
+# bug #4856
+
+import asyncdispatch
+
+proc say[T](t: T): Future[void] {.async.} =
+  echo $t
+
+waitFor(say(123))
+waitFor(say("abc"))
diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim
index 59fef4920..4f286d0ed 100644
--- a/tests/collections/ttables.nim
+++ b/tests/collections/ttables.nim
@@ -95,9 +95,24 @@ block orderedTableTest1:
   for key, val in mpairs(t): val = 99
   for val in mvalues(t): assert val == 99
 
+block orderedTableTest2:
+  var
+    s = initOrderedTable[string, int]()
+    t = initOrderedTable[string, int]()
+  assert s == t
+  for key, val in items(data): t[key] = val
+  assert s != t
+  for key, val in items(sorteddata): s[key] = val
+  assert s != t
+  t.clear()
+  assert s != t
+  for key, val in items(sorteddata): t[key] = val
+  assert s == t
+
 block countTableTest1:
   var s = data.toTable
   var t = initCountTable[string]()
+  
   for k in s.keys: t.inc(k)
   for k in t.keys: assert t[k] == 1
   t.inc("90", 3)
@@ -115,6 +130,24 @@ block countTableTest1:
     else: break
     inc i
 
+block countTableTest2:
+  var
+    s = initCountTable[int]()
+    t = initCountTable[int]()
+  assert s == t
+  s.inc(1)
+  assert s != t
+  t.inc(2)
+  assert s != t
+  t.inc(1)
+  assert s != t
+  s.inc(2)
+  assert s == t
+  s.inc(1)
+  assert s != t
+  t.inc(1)
+  assert s == t
+
 block mpairsTableTest1:
   var t = initTable[string, int]()
   t["a"] = 1
diff --git a/tests/generics/tstatictalias.nim b/tests/generics/tstatictalias.nim
new file mode 100644
index 000000000..98751b8cb
--- /dev/null
+++ b/tests/generics/tstatictalias.nim
@@ -0,0 +1,20 @@
+discard """
+  output: '''G:0,1:0.1
+G:0,1:0.1
+H:1:0.1'''
+"""
+
+type
+  G[i,j:static[int]] = object
+    v:float
+  H[j:static[int]] = G[0,j]
+proc p[i,j:static[int]](x:G[i,j]) = echo "G:",i,",",j,":",x.v
+proc q[j:static[int]](x:H[j]) = echo "H:",j,":",x.v
+
+var
+  g0 = G[0,1](v: 0.1)
+  h0:H[1] = g0
+p(g0)
+p(h0)
+q(h0)
+# bug #4863
diff --git a/tests/js/tconsole.nim b/tests/js/tconsole.nim
new file mode 100644
index 000000000..f6da71c20
--- /dev/null
+++ b/tests/js/tconsole.nim
@@ -0,0 +1,13 @@
+discard """
+  output: '''Hello, console
+1 2 3
+1 'hi' 1.1'''
+"""
+
+# This file tests the JavaScript console
+
+import jsconsole
+
+console.log("Hello, console")
+console.log(1, 2, 3)
+console.log(1, "hi", 1.1)
\ No newline at end of file
diff --git a/tests/macros/tdump.nim b/tests/macros/tdump.nim
new file mode 100644
index 000000000..e4c14dc6b
--- /dev/null
+++ b/tests/macros/tdump.nim
@@ -0,0 +1,13 @@
+discard """
+  output: '''x = 10
+x + y = 30
+'''
+"""
+
+import future
+
+let
+  x = 10
+  y = 20
+dump x
+dump(x + y)
\ No newline at end of file
diff --git a/tests/osproc/tafalse.nim b/tests/osproc/tafalse.nim
new file mode 100644
index 000000000..24fd4fb2e
--- /dev/null
+++ b/tests/osproc/tafalse.nim
@@ -0,0 +1,3 @@
+# 'tafalse.nim' to ensure it is compiled before texitcode.nim
+import system
+quit(QuitFailure)
diff --git a/tests/osproc/texitcode.nim b/tests/osproc/texitcode.nim
new file mode 100644
index 000000000..1e83658c2
--- /dev/null
+++ b/tests/osproc/texitcode.nim
@@ -0,0 +1,18 @@
+discard """
+  file: "texitcode.nim"
+  output: ""
+"""
+import osproc, os
+
+const filename = when defined(Windows): "tafalse.exe" else: "tafalse"
+let dir = getCurrentDir() / "tests" / "osproc"
+doAssert fileExists(dir / filename)
+
+var p = startProcess(filename, dir)
+doAssert(waitForExit(p) == QuitFailure)
+
+p = startProcess(filename, dir)
+var running = true
+while running:
+  running = running(p)
+doAssert(waitForExit(p) == QuitFailure)
diff --git a/tests/osproc/tworkingdir.nim b/tests/osproc/tworkingdir.nim
new file mode 100644
index 000000000..84ba3375c
--- /dev/null
+++ b/tests/osproc/tworkingdir.nim
@@ -0,0 +1,16 @@
+discard """
+  file: "tworkingdir.nim"
+  output: ""
+"""
+
+import osproc, os
+when defined(windows):
+  # Windows don't have this issue, so we won't test it.
+  discard
+else:
+  let dir1 = getCurrentDir()
+  var process = startProcess("/usr/bin/env", "/usr/bin", ["true"])
+  let dir2 = getCurrentDir()
+  discard process.waitForExit()
+  process.close()
+  doAssert(dir1 == dir2, $dir1 & " != " & $dir2)
diff --git a/tests/stdlib/tgetfileinfo.nim b/tests/stdlib/tgetfileinfo.nim
index 8a0538a5f..1c897b702 100644
--- a/tests/stdlib/tgetfileinfo.nim
+++ b/tests/stdlib/tgetfileinfo.nim
@@ -1,5 +1,5 @@
 discard """
-  output: ""
+  output: "pcDir\npcFile\npcLinkToDir\npcLinkToFile\n"
 """
 
 import os, strutils
@@ -93,4 +93,42 @@ proc testGetFileInfo =
       discard
       #echo("Handle : Invalid File : Success")
 
+  # Test kind for files, directories and symlinks.
+  block:
+    let
+      tmp = getTempDir()
+      dirPath      = tmp / "test-dir"
+      filePath     = tmp / "test-file"
+      linkDirPath  = tmp / "test-link-dir"
+      linkFilePath = tmp / "test-link-file"
+
+    createDir(dirPath)
+    writeFile(filePath, "")
+    when defined(posix):
+      createSymlink(dirPath, linkDirPath)
+      createSymlink(filePath, linkFilePath)
+
+    let
+      dirInfo = getFileInfo(dirPath)
+      fileInfo = getFileInfo(filePath)
+    when defined(posix):
+      let
+        linkDirInfo = getFileInfo(linkDirPath, followSymlink = false)
+        linkFileInfo = getFileInfo(linkFilePath, followSymlink = false)
+
+    echo dirInfo.kind
+    echo fileInfo.kind
+    when defined(posix):
+      echo linkDirInfo.kind
+      echo linkFileInfo.kind
+    else:
+      echo pcLinkToDir
+      echo pcLinkToFile
+
+    removeDir(dirPath)
+    removeFile(filePath)
+    when defined(posix):
+      removeFile(linkDirPath)
+      removeFile(linkFilePath)
+
 testGetFileInfo()
diff --git a/tests/stdlib/ttime.nim b/tests/stdlib/ttime.nim
index 3ab287c4e..065009535 100644
--- a/tests/stdlib/ttime.nim
+++ b/tests/stdlib/ttime.nim
@@ -140,4 +140,27 @@ doAssert initInterval(months = 13) == initInterval(months = 1, years = 1)
 # Bug with adding a day to a Time
 let day = 24.hours
 let tomorrow = getTime() + day
-doAssert tomorrow - getTime() == 60*60*24
\ No newline at end of file
+doAssert tomorrow - getTime() == 60*60*24
+
+doAssert milliseconds(1000 * 60) == minutes(1)
+doAssert milliseconds(1000 * 60 * 60) == hours(1)
+doAssert milliseconds(1000 * 60 * 60 * 24) == days(1)
+doAssert seconds(60 * 60) == hours(1)
+doAssert seconds(60 * 60 * 24) == days(1)
+doAssert seconds(60 * 60 + 65) == (hours(1) + minutes(1) + seconds(5))
+
+# Bug with parse not setting DST properly if the current local DST differs from
+# the date being parsed. Need to test parse dates both in and out of DST. We
+# are testing that be relying on the fact that tranforming a TimeInfo to a Time
+# and back again will correctly set the DST value. With the incorrect parse
+# behavior this will introduce a one hour offset from the named time and the
+# parsed time if the DST value differs between the current time and the date we
+# are parsing.
+#
+# Unfortunately these tests depend on the locale of the system in which they
+# are run. They will not be meaningful when run in a locale without DST. They
+# also assume that Jan. 1 and Jun. 1 will have differing isDST values.
+let dstT1 = parse("2016-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss")
+let dstT2 = parse("2016-06-01 00:00:00", "yyyy-MM-dd HH:mm:ss")
+doAssert dstT1 == getLocalTime(toTime(dstT1))
+doAssert dstT2 == getLocalTime(toTime(dstT2))
diff --git a/tests/template/tconfusinglocal.nim b/tests/template/tconfusinglocal.nim
new file mode 100644
index 000000000..9b2cdc954
--- /dev/null
+++ b/tests/template/tconfusinglocal.nim
@@ -0,0 +1,13 @@
+
+# bug #4875
+type Bar = object
+    mFoo: int
+
+template foo(a: Bar): int = a.mFoo
+
+proc main =
+    let foo = 5 # Rename this to smth else to make it work
+    var b: Bar
+    echo b.foo
+
+main()
diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim
index 3ed2f2196..809425653 100644
--- a/tests/testament/categories.nim
+++ b/tests/testament/categories.nim
@@ -115,6 +115,12 @@ proc dllTests(r: var TResults, cat: Category, options: string) =
 # ------------------------------ GC tests -------------------------------------
 
 proc gcTests(r: var TResults, cat: Category, options: string) =
+  template testWithNone(filename: untyped) =
+    testSpec r, makeTest("tests/gc" / filename, options &
+                  " --gc:none", cat, actionRun)
+    testSpec r, makeTest("tests/gc" / filename, options &
+                  " -d:release --gc:none", cat, actionRun)
+
   template testWithoutMs(filename: untyped) =
     testSpec r, makeTest("tests/gc" / filename, options, cat, actionRun)
     testSpec r, makeTest("tests/gc" / filename, options &
@@ -144,6 +150,7 @@ proc gcTests(r: var TResults, cat: Category, options: string) =
   test "gcleak"
   test "gcleak2"
   test "gctest"
+  testWithNone "gctest"
   test "gcleak3"
   test "gcleak4"
   # Disabled because it works and takes too long to run:
@@ -375,8 +382,14 @@ proc `&.?`(a, b: string): string =
 proc `&?.`(a, b: string): string =
   # candidate for the stdlib?
   result = if a.endswith(b): a else: a & b
+  
+proc processSingleTest(r: var TResults, cat: Category, options, test: string) =
+  let test = "tests" & DirSep &.? cat.string / test
+
+  if existsFile(test): testSpec r, makeTest(test, options, cat)
+  else: echo "[Warning] - ", test, " test does not exist"
 
-proc processCategory(r: var TResults, cat: Category, options: string, fileGlob: string = "t*.nim") =
+proc processCategory(r: var TResults, cat: Category, options: string) =
   case cat.string.normalize
   of "rodfiles":
     when false: compileRodFiles(r, cat, options)
@@ -417,5 +430,5 @@ proc processCategory(r: var TResults, cat: Category, options: string, fileGlob:
     # We can't test it because it depends on a third party.
     discard # TODO: Move untestable tests to someplace else, i.e. nimble repo.
   else:
-    for name in os.walkFiles("tests" & DirSep &.? cat.string / fileGlob):
+    for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"):
       testSpec r, makeTest(name, options, cat)
diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim
index 74ac58927..2734742f4 100644
--- a/tests/testament/tester.nim
+++ b/tests/testament/tester.nim
@@ -445,7 +445,7 @@ proc main() =
     let (dir, file) = splitPath(p.key.string)
     let (_, subdir) = splitPath(dir)
     var cat = Category(subdir)
-    processCategory(r, cat, p.cmdLineRest.string, file)
+    processSingleTest(r, cat, p.cmdLineRest.string, file)
   of "html":
     var commit = 0
     discard parseInt(p.cmdLineRest.string, commit)
diff --git a/tests/vm/tgorge.bat b/tests/vm/tgorge.bat
new file mode 100644
index 000000000..24d365842
--- /dev/null
+++ b/tests/vm/tgorge.bat
@@ -0,0 +1 @@
+@echo gorge test
\ No newline at end of file
diff --git a/tests/vm/tgorge.nim b/tests/vm/tgorge.nim
new file mode 100644
index 000000000..596f5d667
--- /dev/null
+++ b/tests/vm/tgorge.nim
@@ -0,0 +1,12 @@
+import os
+
+template getScriptDir(): string =
+  parentDir(instantiationInfo(-1, true).filename)
+
+const
+  execName = when defined(windows): "tgorge.bat" else: "sh tgorge.sh"
+  relOutput = gorge(execName)
+  absOutput = gorge(getScriptDir() / execName)
+
+doAssert relOutput == "gorge test"
+doAssert absOutput == "gorge test"
diff --git a/tests/vm/tgorge.sh b/tests/vm/tgorge.sh
new file mode 100644
index 000000000..ba47afeae
--- /dev/null
+++ b/tests/vm/tgorge.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "gorge test"
\ No newline at end of file