summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/compile/tcommontype.nim20
-rw-r--r--tests/manyloc/argument_parser/ex_wget.nim87
-rw-r--r--tests/manyloc/argument_parser/ex_wget.nimrod.cfg1
-rw-r--r--tests/manyloc/keineschweine/keineschweine.nimrod.cfg1
-rw-r--r--tests/manyloc/nake/nake.nim83
-rw-r--r--tests/manyloc/nake/nakefile.nim (renamed from tests/manyloc/keineschweine/nakefile.nim)2
-rw-r--r--tests/manyloc/nake/nakefile.nimrod.cfg (renamed from tests/manyloc/keineschweine/nakefile.nimrod.cfg)0
-rw-r--r--tests/reject/temptycaseobj.nim2
-rw-r--r--tests/reject/tind1.nim2
-rw-r--r--tests/reject/tmissingnl.nim2
-rw-r--r--tests/run/tstmtexprs.nim66
-rw-r--r--tests/specials.nim3
12 files changed, 264 insertions, 5 deletions
diff --git a/tests/compile/tcommontype.nim b/tests/compile/tcommontype.nim
new file mode 100644
index 000000000..8215ebd5e
--- /dev/null
+++ b/tests/compile/tcommontype.nim
@@ -0,0 +1,20 @@
+type
+  TAnimal=object {.inheritable.}
+  PAnimal=ref TAnimal
+
+  TDog=object of TAnimal
+  PDog=ref TDog
+
+  TCat=object of TAnimal
+  PCat=ref TCat
+
+  TAnimalArray=array[0..2,PAnimal]
+
+proc newDog():PDog = new(result)
+proc newCat():PCat = new(result)
+proc test(a:openarray[PAnimal])=
+  echo("dummy")
+
+#test(newDog(),newCat()) #does not work
+var myarray:TAnimalArray=[newDog(),newCat(),newDog()] #does not work
+#var myarray2:TAnimalArray=[newDog(),newDog(),newDog()] #does not work either
diff --git a/tests/manyloc/argument_parser/ex_wget.nim b/tests/manyloc/argument_parser/ex_wget.nim
new file mode 100644
index 000000000..d36947b34
--- /dev/null
+++ b/tests/manyloc/argument_parser/ex_wget.nim
@@ -0,0 +1,87 @@
+import argument_parser, tables, strutils, parseutils
+
+## Example defining a subset of wget's functionality
+
+const
+  PARAM_VERSION = @["-V", "--version"]
+  PARAM_HELP = @["-h", "--help"]
+  PARAM_BACKGROUND = @["-b", "--background"]
+  PARAM_OUTPUT = @["-o", "--output"]
+  PARAM_NO_CLOBBER = @["-nc", "--no-clobber"]
+  PARAM_PROGRESS = "--progress"
+  PARAM_NO_PROXY = "--no-proxy"
+
+
+template P(tnames: varargs[string], thelp: string, ttype = PK_EMPTY,
+    tcallback: Tparameter_callback = nil) =
+  ## Helper to avoid repetition of parameter adding boilerplate.
+  params.add(new_parameter_specification(ttype, custom_validator = tcallback,
+    help_text = thelp, names = tnames))
+
+
+template got(param: varargs[string]) =
+  ## Just dump the detected options on output.
+  if result.options.hasKey(param[0]): echo("Found option '$1'." % [param[0]])
+
+
+proc parse_progress(parameter: string; value: var Tparsed_parameter): string =
+  ## Custom parser and validator of progress types for PARAM_PROGRESS.
+  ##
+  ## If the user specifies the PARAM_PROGRESS option this proc will be called
+  ## so we can validate the input. The proc returns a non empty string if
+  ## something went wrong with the description of the error, otherwise
+  ## execution goes ahead.
+  ##
+  ## This validator only accepts values without changing the final output.
+  if value.str_val == "bar" or value.str_val == "dot":
+    return
+
+  result = "The string $1 is not valid, use bar or dot." % [value.str_val]
+
+
+proc process_commandline(): Tcommandline_results =
+  ## Parses the commandline.
+  ##
+  ## Returns a Tcommandline_results with at least two positional parameter,
+  ## where the last parameter is implied to be the destination of the copying.
+  var params: seq[Tparameter_specification] = @[]
+
+  P(PARAM_VERSION, "Shows the version of the program")
+  P(PARAM_HELP, "Shows this help on the commandline", PK_HELP)
+  P(PARAM_BACKGROUND, "Continues execution in the background")
+  P(PARAM_OUTPUT, "Specifies a specific output file name", PK_STRING)
+  P(PARAM_NO_CLOBBER, "Skip downloads that would overwrite existing files")
+  P(PARAM_PROGRESS, "Select progress look (bar or dot)",
+    PK_STRING, parse_progress)
+  P(PARAM_NO_PROXY, "Don't use proxies even if available")
+
+  result = parse(params)
+
+  if result.positional_parameters.len < 1:
+    echo "Missing URL(s) to download"
+    echo_help(params)
+    quit()
+
+  got(PARAM_NO_CLOBBER)
+  got(PARAM_BACKGROUND)
+  got(PARAM_NO_PROXY)
+
+  if result.options.hasKey(PARAM_VERSION[0]):
+    echo "Version 3.1415"
+    quit()
+
+  if result.options.hasKey(PARAM_OUTPUT[0]):
+    if result.positional_parameters.len > 1:
+      echo "Error: can't use $1 option with multiple URLs" % [PARAM_OUTPUT[0]]
+      echo_help(params)
+      quit()
+    echo "Will download to $1" % [result.options[PARAM_OUTPUT[0]].str_val]
+
+  if result.options.hasKey(PARAM_PROGRESS):
+    echo "Will use progress type $1" % [result.options[PARAM_PROGRESS].str_val]
+
+
+when isMainModule:
+  let args = process_commandline()
+  for param in args.positional_parameters:
+    echo "Downloading $1" % param.str_val
diff --git a/tests/manyloc/argument_parser/ex_wget.nimrod.cfg b/tests/manyloc/argument_parser/ex_wget.nimrod.cfg
new file mode 100644
index 000000000..4ea571d31
--- /dev/null
+++ b/tests/manyloc/argument_parser/ex_wget.nimrod.cfg
@@ -0,0 +1 @@
+# This file exists only to mark 'ex_wget' as the project file
diff --git a/tests/manyloc/keineschweine/keineschweine.nimrod.cfg b/tests/manyloc/keineschweine/keineschweine.nimrod.cfg
index 048285ad9..ca6c75f6e 100644
--- a/tests/manyloc/keineschweine/keineschweine.nimrod.cfg
+++ b/tests/manyloc/keineschweine/keineschweine.nimrod.cfg
@@ -6,3 +6,4 @@ path = "dependencies/enet"
 path = "dependencies/genpacket"
 path = "enet_server"
 debugger = off
+warning[SmallLshouldNotBeUsed] = off
diff --git a/tests/manyloc/nake/nake.nim b/tests/manyloc/nake/nake.nim
new file mode 100644
index 000000000..eade28c70
--- /dev/null
+++ b/tests/manyloc/nake/nake.nim
@@ -0,0 +1,83 @@
+discard """
+DO AS THOU WILST PUBLIC LICENSE
+
+Whoever should stumble upon this document is henceforth and forever
+entitled to DO AS THOU WILST with aforementioned document and the
+contents thereof. 
+
+As said in the Olde Country, `Keepe it Gangster'."""
+
+import strutils, parseopt, tables, os
+
+type
+  PTask* = ref object
+    desc*: string
+    action*: TTaskFunction
+  TTaskFunction* = proc() {.closure.}
+var 
+  tasks* = initTable[string, PTask](16)
+
+proc newTask*(desc: string; action: TTaskFunction): PTask
+proc runTask*(name: string) {.inline.}
+proc shell*(cmd: varargs[string, `$`]): int {.discardable.}
+proc cd*(dir: string) {.inline.}
+
+template nakeImports*(): stmt {.immediate.} =
+  import tables, parseopt, strutils, os
+
+template task*(name: string; description: string; body: stmt): stmt {.dirty, immediate.} =
+  block:
+    var t = newTask(description, proc() {.closure.} =
+      body)
+    tasks[name] = t
+
+proc newTask*(desc: string; action: TTaskFunction): PTask =
+  new(result)
+  result.desc = desc
+  result.action = action
+proc runTask*(name: string) = tasks[name].action()
+
+proc shell*(cmd: varargs[string, `$`]): int =
+  result = execShellCmd(cmd.join(" "))
+proc cd*(dir: string) = setCurrentDir(dir)
+template withDir*(dir: string; body: stmt): stmt =
+  ## temporary cd
+  ## withDir "foo":
+  ##   # inside foo
+  ## #back to last dir
+  var curDir = getCurrentDir()
+  cd(dir)
+  body
+  cd(curDir)
+
+when isMainModule:
+  if not existsFile("nakefile.nim"):
+    echo "No nakefile.nim found. Current working dir is ", getCurrentDir()
+    quit 1
+  var args = ""
+  for i in 1..paramCount():
+    args.add paramStr(i)
+    args.add " "
+  quit(shell("nimrod", "c", "-r", "nakefile.nim", args))
+else:
+  addQuitProc(proc() {.noconv.} =
+    var 
+      task: string
+      printTaskList: bool
+    for kind, key, val in getOpt():
+      case kind
+      of cmdLongOption, cmdShortOption:
+        case key.tolower
+        of "tasks", "t":
+          printTaskList = true
+        else: 
+          echo "Unknown option: ", key, ": ", val
+      of cmdArgument:
+        task = key
+      else: nil
+    if printTaskList or task.isNil or not(tasks.hasKey(task)):
+      echo "Available tasks:"
+      for name, task in pairs(tasks):
+        echo name, " - ", task.desc
+      quit 0
+    tasks[task].action())
diff --git a/tests/manyloc/keineschweine/nakefile.nim b/tests/manyloc/nake/nakefile.nim
index f175321b9..700f9ab49 100644
--- a/tests/manyloc/keineschweine/nakefile.nim
+++ b/tests/manyloc/nake/nakefile.nim
@@ -76,7 +76,7 @@ task "testskel", "create skeleton test dir for testing":
 
 task "clean", "cleanup generated files":
   var dirs = @["nimcache", "server"/"nimcache"]
-  dirs.each(proc(x: var string) =
+  dirs.map(proc(x: var string) =
     if existsDir(x): removeDir(x))
 
 task "download", "download game assets":
diff --git a/tests/manyloc/keineschweine/nakefile.nimrod.cfg b/tests/manyloc/nake/nakefile.nimrod.cfg
index 6f3e86fe6..6f3e86fe6 100644
--- a/tests/manyloc/keineschweine/nakefile.nimrod.cfg
+++ b/tests/manyloc/nake/nakefile.nimrod.cfg
diff --git a/tests/reject/temptycaseobj.nim b/tests/reject/temptycaseobj.nim
index 5977cb92b..5c012746e 100644
--- a/tests/reject/temptycaseobj.nim
+++ b/tests/reject/temptycaseobj.nim
@@ -1,6 +1,6 @@
 discard """
   line: 11
-  errormsg: "identifier expected, but found '[same indentation]'"
+  errormsg: "identifier expected, but found 'keyword of'"
 """
 
 type
diff --git a/tests/reject/tind1.nim b/tests/reject/tind1.nim
index f3f3cacf7..f3fd952cc 100644
--- a/tests/reject/tind1.nim
+++ b/tests/reject/tind1.nim
@@ -1,6 +1,6 @@
 discard """
   line: 24
-  errormsg: "invalid indentation"
+  errormsg: "expression expected, but found 'keyword else'"
 """
 
 import macros
diff --git a/tests/reject/tmissingnl.nim b/tests/reject/tmissingnl.nim
index c2f97a807..33b7debf1 100644
--- a/tests/reject/tmissingnl.nim
+++ b/tests/reject/tmissingnl.nim
@@ -1,7 +1,7 @@
 discard """
   file: "tmissingnl.nim"
   line: 7
-  errormsg: "newline expected, but found 'keyword var'"
+  errormsg: "invalid indentation"
 """
 
 import strutils var s: seq[int] = @[0, 1, 2, 3, 4, 5, 6]
diff --git a/tests/run/tstmtexprs.nim b/tests/run/tstmtexprs.nim
new file mode 100644
index 000000000..a69acd98b
--- /dev/null
+++ b/tests/run/tstmtexprs.nim
@@ -0,0 +1,66 @@
+discard """
+  output: '''(bar: bar)
+1244
+6
+abcdefghijklmnopqrstuvwxyz
+145 23'''
+"""
+
+import strutils
+
+when true:
+  proc test(foo: proc (x, y: int): bool) =
+    echo foo(5, 5)
+
+
+  type Foo = object
+    bar: string
+
+  proc newfoo(): Foo =
+    result.bar = "bar"
+
+  echo($newfoo())
+   
+
+  proc retInt(x, y: int): int = 
+    if (var yy = 0; yy != 0):
+      echo yy
+    else:
+      echo(try: parseInt("1244") except EINvalidValue: -1)
+    result = case x
+             of 23: 3
+             of 64: 
+                    case y
+                    of 1: 2
+                    of 2: 3
+                    of 3: 6
+                    else: 8
+             else: 1
+
+  echo retInt(64, 3)
+
+  proc buildString(): string =
+    result = ""
+    for x in 'a'..'z':
+      result.add(x)
+
+  echo buildString()
+
+#test(
+#  proc (x, y: int): bool =
+#  if x == 5: return true
+#  if x == 2: return false
+#  if y == 78: return true
+#)
+
+proc q(): int {.discardable.} = 145
+proc p(): int =
+  q()
+
+proc p2(a: int): int =
+  # result enforces a void context:
+  if a == 2:
+    result = 23
+  q()
+
+echo p(), " ", p2(2)
diff --git a/tests/specials.nim b/tests/specials.nim
index 30bb6f423..156a289d2 100644
--- a/tests/specials.nim
+++ b/tests/specials.nim
@@ -216,7 +216,8 @@ proc compileManyLoc(r: var TResults, options: string) =
   for kind, dir in os.walkDir("tests/manyloc"):
     if kind == pcDir:
       let mainfile = findMainFile(dir)
-      compileSingleTest(r, mainfile, options)
+      if mainfile != ".nim":
+        compileSingleTest(r, mainfile, options)
 
 proc compileSpecialTests(r: var TResults, options: string) =
   compileRodFiles(r, options)