summary refs log tree commit diff stats
path: root/tests/system
diff options
context:
space:
mode:
Diffstat (limited to 'tests/system')
-rw-r--r--tests/system/helpers/readall_echo.nim2
-rw-r--r--tests/system/t10307.nim24
-rw-r--r--tests/system/t20938.nim12
-rw-r--r--tests/system/t7894.nim23
-rw-r--r--tests/system/talloc.nim59
-rw-r--r--tests/system/talloc2.nim46
-rw-r--r--tests/system/tatomics1.nim9
-rw-r--r--tests/system/tcomparisons.nim51
-rw-r--r--tests/system/tconcat.nim11
-rw-r--r--tests/system/tdeepcopy.nim95
-rw-r--r--tests/system/tdollars.nim199
-rw-r--r--tests/system/techo_unicode.nim41
-rw-r--r--tests/system/temptyecho.nim6
-rw-r--r--tests/system/tensuremove.nim131
-rw-r--r--tests/system/tensuremove1.nim16
-rw-r--r--tests/system/tensuremove2.nim15
-rw-r--r--tests/system/tensuremove3.nim28
-rw-r--r--tests/system/tenum_array_repr.nim23
-rw-r--r--tests/system/tfielditerator.nim126
-rw-r--r--tests/system/tfields.nim108
-rw-r--r--tests/system/tgcnone.nim7
-rw-r--r--tests/system/tgcregions.nim6
-rw-r--r--tests/system/tgogc.nim7
-rw-r--r--tests/system/timmutableinc.nim8
-rw-r--r--tests/system/tinvalidnot.nim19
-rw-r--r--tests/system/tio.nim55
-rw-r--r--tests/system/tlocals.nim76
-rw-r--r--tests/system/tlowhigh.nim32
-rw-r--r--tests/system/tmagics.nim62
-rw-r--r--tests/system/tmemory.nim16
-rw-r--r--tests/system/tnew.nim61
-rw-r--r--tests/system/tnewderef.nim11
-rw-r--r--tests/system/tnewstring_uninitialized.nim11
-rw-r--r--tests/system/tnilconcats.nim33
-rw-r--r--tests/system/tnim_stacktrace_override.nim18
-rw-r--r--tests/system/tostring.nim125
-rw-r--r--tests/system/tparams.nim22
-rw-r--r--tests/system/trealloc.nim23
-rw-r--r--tests/system/trefs.nim15
-rw-r--r--tests/system/tsigexitcode.nim23
-rw-r--r--tests/system/tslices.nim65
-rw-r--r--tests/system/tslimsystem.nim6
-rw-r--r--tests/system/tstatic.nim58
-rw-r--r--tests/system/tstatic_callable.nim12
-rw-r--r--tests/system/tstatic_callable_error.nim14
-rw-r--r--tests/system/tsystem_misc.nim227
-rw-r--r--tests/system/tuse_version16.nim49
-rw-r--r--tests/system/tvarargslen.nim60
48 files changed, 2146 insertions, 0 deletions
diff --git a/tests/system/helpers/readall_echo.nim b/tests/system/helpers/readall_echo.nim
new file mode 100644
index 000000000..2891ef3ae
--- /dev/null
+++ b/tests/system/helpers/readall_echo.nim
@@ -0,0 +1,2 @@
+when true:
+  echo(stdin.readAll)
diff --git a/tests/system/t10307.nim b/tests/system/t10307.nim
new file mode 100644
index 000000000..b5a93c5c6
--- /dev/null
+++ b/tests/system/t10307.nim
@@ -0,0 +1,24 @@
+discard """
+  cmd: "nim c --mm:refc -d:useGcAssert $file"
+  output: '''running someProc(true)
+res: yes
+yes
+running someProc(false)
+res: 
+
+'''
+"""
+
+proc someProc(x:bool):cstring =
+  var res:string = ""
+  if x:
+    res = "yes"
+  echo "res: ", res
+  GC_ref(res)
+  result = res
+
+echo "running someProc(true)"
+echo someProc(true)
+
+echo "running someProc(false)"
+echo someProc(false)
diff --git a/tests/system/t20938.nim b/tests/system/t20938.nim
new file mode 100644
index 000000000..7341cbb91
--- /dev/null
+++ b/tests/system/t20938.nim
@@ -0,0 +1,12 @@
+discard """
+  cmd: "nim c --mm:refc $file"
+  action: "compile"
+"""
+
+template foo(x: typed) =
+  discard x
+
+foo:
+  var x = "hello"
+  x.shallowCopy("test")
+  true
diff --git a/tests/system/t7894.nim b/tests/system/t7894.nim
new file mode 100644
index 000000000..60dbe86cb
--- /dev/null
+++ b/tests/system/t7894.nim
@@ -0,0 +1,23 @@
+discard """
+disabled: true
+"""
+
+# CI integration servers are out of memory for this test
+
+const size = 250000000
+
+proc main() =
+
+  var saved = newSeq[seq[int8]]()
+
+  for i in 0..22:
+    # one of these is 0.25GB.
+    #echo i
+    var x = newSeq[int8](size)
+    saved.add(x)
+
+  for x in saved:
+    #echo x.len
+    doAssert x.len == size
+
+main()
diff --git a/tests/system/talloc.nim b/tests/system/talloc.nim
new file mode 100644
index 000000000..a81fef481
--- /dev/null
+++ b/tests/system/talloc.nim
@@ -0,0 +1,59 @@
+# was: appveyor is "out of memory"
+
+var x: ptr int
+
+x = cast[ptr int](alloc(7))
+doAssert x != nil
+x = cast[ptr int](x.realloc(2))
+doAssert x != nil
+x.dealloc()
+
+x = createU(int, 3)
+doAssert x != nil
+x.dealloc()
+
+x = create(int, 4)
+doAssert cast[ptr array[4, int]](x)[0] == 0
+doAssert cast[ptr array[4, int]](x)[1] == 0
+doAssert cast[ptr array[4, int]](x)[2] == 0
+doAssert cast[ptr array[4, int]](x)[3] == 0
+
+x = x.resize(4)
+doAssert x != nil
+x.dealloc()
+
+x = cast[ptr int](allocShared(100))
+doAssert x != nil
+deallocShared(x)
+
+x = createSharedU(int, 3)
+doAssert x != nil
+x.deallocShared()
+
+x = createShared(int, 3)
+doAssert x != nil
+doAssert cast[ptr array[3, int]](x)[0] == 0
+doAssert cast[ptr array[3, int]](x)[1] == 0
+doAssert cast[ptr array[3, int]](x)[2] == 0
+
+doAssert x != nil
+x = cast[ptr int](x.resizeShared(2))
+doAssert x != nil
+x.deallocShared()
+
+x = create(int, 10)
+doAssert x != nil
+x = x.resize(12)
+doAssert x != nil
+x.dealloc()
+
+x = createShared(int, 1)
+doAssert x != nil
+x = x.resizeShared(1)
+doAssert x != nil
+x.deallocShared()
+
+x = cast[ptr int](alloc0(125 shl 23))
+dealloc(x)
+x = cast[ptr int](alloc0(126 shl 23))
+dealloc(x)
diff --git a/tests/system/talloc2.nim b/tests/system/talloc2.nim
new file mode 100644
index 000000000..9d1687f34
--- /dev/null
+++ b/tests/system/talloc2.nim
@@ -0,0 +1,46 @@
+discard """
+disabled: "windows"
+disabled: "openbsd"
+joinable: false
+disabled: 32bit
+"""
+# no point to test this on system with smaller address space
+# was: appveyor is "out of memory"
+
+const
+  nmax = 2*1024*1024*1024
+
+proc test(n: int) =
+  var a = alloc0(9999)
+  var t = cast[ptr UncheckedArray[int8]](alloc(n))
+  var b = alloc0(9999)
+  t[0] = 1
+  t[1] = 2
+  t[n-2] = 3
+  t[n-1] = 4
+  dealloc(a)
+  dealloc(t)
+  dealloc(b)
+
+# allocator adds 48 bytes to BigChunk
+# BigChunk allocator edges at 2^n * (1 - s) for s = [1..32]/64
+proc test2(n: int) =
+  let d = n div 256  # cover edges and more
+  for i in countdown(128,1):
+    for j in [-4096, -64, -49, -48, -47, -32, 0, 4096]:
+      let b = n + j - i*d
+      if b>0 and b<=nmax:
+        test(b)
+        #echo b, ": ", getTotalMem(), " ", getOccupiedMem(), " ", getFreeMem()
+
+proc test3 =
+  var n = 1
+  while n <= nmax:
+    test2(n)
+    n *= 2
+  n = nmax
+  while n >= 1:
+    test2(n)
+    n = n div 2
+
+test3()
diff --git a/tests/system/tatomics1.nim b/tests/system/tatomics1.nim
new file mode 100644
index 000000000..217fd07fa
--- /dev/null
+++ b/tests/system/tatomics1.nim
@@ -0,0 +1,9 @@
+discard """
+  targets: "c cpp js"
+"""
+
+var x = 10
+atomicInc(x)
+doAssert x == 11
+atomicDec(x)
+doAssert x == 10
diff --git a/tests/system/tcomparisons.nim b/tests/system/tcomparisons.nim
new file mode 100644
index 000000000..a661b14a1
--- /dev/null
+++ b/tests/system/tcomparisons.nim
@@ -0,0 +1,51 @@
+discard """
+  targets: "c cpp js"
+"""
+
+template main =
+  block: # proc equality
+    var prc: proc(): int {.closure.}
+    prc = nil
+    doAssert prc == nil
+    doAssert prc.isNil
+    prc = proc(): int =
+      result = 123
+    doAssert prc != nil
+    doAssert not prc.isNil
+    doAssert prc == prc
+    let prc2 = prc
+    doAssert prc == prc2
+    doAssert prc2 != nil
+    doAssert not prc2.isNil
+    doAssert not prc.isNil
+    prc = proc(): int =
+      result = 456
+    doAssert prc != nil
+    doAssert not prc.isNil
+    doAssert prc != prc2
+  block: # iterator equality
+    when nimvm: discard # vm does not support closure iterators
+    else:
+      when not defined(js): # js also does not support closure iterators
+        var iter: iterator(): int {.closure.}
+        iter = nil
+        doAssert iter == nil
+        doAssert iter.isNil
+        iter = iterator(): int =
+          yield 123
+        doAssert iter != nil
+        doAssert not iter.isNil
+        doAssert iter == iter
+        let iter2 = iter
+        doAssert iter == iter2
+        doAssert iter2 != nil
+        doAssert not iter2.isNil
+        doAssert not iter.isNil
+        iter = iterator(): int =
+          yield 456
+        doAssert iter != nil
+        doAssert not iter.isNil
+        doAssert iter != iter2
+
+static: main()
+main()
diff --git a/tests/system/tconcat.nim b/tests/system/tconcat.nim
new file mode 100644
index 000000000..fdce3ea00
--- /dev/null
+++ b/tests/system/tconcat.nim
@@ -0,0 +1,11 @@
+discard """
+  output: "DabcD"
+"""
+
+const
+  x = "abc"
+
+var v = "D" & x & "D"
+
+echo v
+
diff --git a/tests/system/tdeepcopy.nim b/tests/system/tdeepcopy.nim
new file mode 100644
index 000000000..92ba48115
--- /dev/null
+++ b/tests/system/tdeepcopy.nim
@@ -0,0 +1,95 @@
+discard """
+  matrix: "--mm:refc; --mm:orc --deepcopy:on"
+  output: "ok"
+"""
+
+import tables, lists
+
+type
+  ListTable[K, V] = object
+    valList: DoublyLinkedList[V]
+    table: Table[K, DoublyLinkedNode[V]]
+
+  ListTableRef*[K, V] = ref ListTable[K, V]
+
+proc initListTable*[K, V](initialSize = 64): ListTable[K, V] =
+  result.valList = initDoublyLinkedList[V]()
+  result.table = initTable[K, DoublyLinkedNode[V]]()
+
+proc newListTable*[K, V](initialSize = 64): ListTableRef[K, V] =
+  new(result)
+  result[] = initListTable[K, V](initialSize)
+
+proc `[]=`*[K, V](t: var ListTable[K, V], key: K, val: V) =
+  if key in t.table:
+    t.table[key].value = val
+  else:
+    let node = newDoublyLinkedNode(val)
+    t.valList.append(node)
+    t.table[key] = node
+
+proc `[]`*[K, V](t: ListTable[K, V], key: K): var V {.inline.} =
+  result = t.table[key].value
+
+proc len*[K, V](t: ListTable[K, V]): Natural {.inline.} =
+  result = t.table.len
+
+iterator values*[K, V](t: ListTable[K, V]): V =
+  for val in t.valList.items():
+    yield val
+
+proc `[]=`*[K, V](t: ListTableRef[K, V], key: K, val: V) =
+  t[][key] = val
+
+proc `[]`*[K, V](t: ListTableRef[K, V], key: K): var V {.inline.} =
+  t[][key]
+
+proc len*[K, V](t: ListTableRef[K, V]): Natural {.inline.} =
+  t[].len
+
+iterator values*[K, V](t: ListTableRef[K, V]): V =
+  for val in t[].values:
+    yield val
+
+proc main() =
+  type SomeObj = ref object
+
+  for outer in 0..10_000:
+    let myObj = new(SomeObj)
+    let table = newListTable[int, SomeObj]()
+
+    table[0] = myObj
+    for i in 1..100:
+      table[i] = new(SomeObj)
+
+    var myObj2: SomeObj
+    for val in table.values():
+      if myObj2.isNil:
+        myObj2 = val
+    doAssert(myObj == myObj2) # passes
+
+    var tableCopy: ListTableRef[int, SomeObj]
+    deepCopy(tableCopy, table)
+
+    let myObjCopy = tableCopy[0]
+    var myObjCopy2: SomeObj = nil
+    for val in tableCopy.values():
+      if myObjCopy2.isNil:
+        myObjCopy2 = val
+
+    #echo cast[int](myObj)
+    #echo cast[int](myObjCopy)
+    #echo cast[int](myObjCopy2)
+
+    doAssert(myObjCopy == myObjCopy2) # fails
+
+
+type
+  PtrTable = object
+    counter, max: int
+    data: array[0..99, (pointer, pointer)]
+
+doAssert(sizeof(PtrTable) == 2*sizeof(int)+sizeof(pointer)*2*100)
+
+main()
+echo "ok"
diff --git a/tests/system/tdollars.nim b/tests/system/tdollars.nim
new file mode 100644
index 000000000..eabee81b3
--- /dev/null
+++ b/tests/system/tdollars.nim
@@ -0,0 +1,199 @@
+discard """
+  matrix: "--mm:refc; --mm:orc; --backend:cpp; --backend:js --jsbigint64:off -d:nimStringHash2; --backend:js --jsbigint64:on"
+"""
+
+#[
+if https://github.com/nim-lang/Nim/pull/14043 is merged (or at least its
+tests/system/tostring.nim diff subset), merge
+tests/system/tostring.nim into this file, named after dollars.nim
+
+The goal is to increase test coverage across backends while minimizing test code
+duplication (which always results in weaker test coverage in practice).
+]#
+
+import std/unittest
+import std/private/jsutils
+template test[T](a: T, expected: string) =
+  check $a == expected
+  var b = a
+  check $b == expected
+  static:
+    doAssert $a == expected
+
+template testType(T: typedesc) =
+  when T is bool:
+    test true, "true"
+    test false, "false"
+  elif T is char:
+    test char, "\0"
+    test char.high, static($T.high)
+  else:
+    test T.default, "0"
+    test 1.T, "1"
+    test T.low, static($T.low)
+    test T.high, static($T.high)
+
+block: # `$`(SomeInteger)
+  # direct tests
+  check $0'u8 == "0"
+  check $255'u8 == "255"
+  check $(-127'i8) == "-127"
+
+  # known limitation: Error: number out of range: '128'i8',
+  # see https://github.com/timotheecour/Nim/issues/125
+  # check $(-128'i8) == "-128"
+
+  check $int8.low == "-128"
+  check $int8(-128) == "-128"
+  check $cast[int8](-128) == "-128"
+
+  var a = 12345'u16
+  check $a == "12345"
+  check $12345678'u64 == "12345678"
+  check $12345678'i64 == "12345678"
+  check $(-12345678'i64) == "-12345678"
+
+  # systematic tests
+  testType uint8
+  testType uint16
+  testType uint32
+  testType uint
+
+  testType int8
+  testType int16
+  testType int32
+
+  testType int
+  testType bool
+
+  whenJsNoBigInt64: discard
+  do:
+    testType uint64
+    testType int64
+    testType BiggestInt
+
+block: # #14350, #16674, #16686 for JS
+  var cstr: cstring
+  doAssert cstr == cstring(nil)
+  doAssert cstr == nil
+  doAssert cstr.isNil
+  doAssert cstr != cstring("")
+  doAssert cstr.len == 0
+
+  when defined(js):
+    cstr.add(cstring("abc"))
+    doAssert cstr == cstring("abc")
+
+    var nil1, nil2: cstring = nil
+
+    nil1.add(nil2)
+    doAssert nil1 == cstring(nil)
+    doAssert nil2 == cstring(nil)
+
+    nil1.add(cstring(""))
+    doAssert nil1 == cstring("")
+    doAssert nil2 == cstring(nil)
+
+    nil1.add(nil2)
+    doAssert nil1 == cstring("")
+    doAssert nil2 == cstring(nil)
+
+    nil2.add(nil1)
+    doAssert nil1 == cstring("")
+    doAssert nil2 == cstring("")
+
+block:
+  when defined(js): # bug #18591
+    let a1 = -1'i8
+    let a2 = uint8(a1)
+    # if `uint8(a1)` changes meaning to `cast[uint8](a1)` in future, update this test;
+    # until then, this is the correct semantics.
+    let a3 = $a2
+    doAssert a2 == 255'u8
+    doAssert a3 == "255"
+    proc intToStr(a: uint8): cstring {.importjs: "(# + \"\")".}
+    doAssert $intToStr(a2) == "255"
+  else:
+    block:
+      let x = -1'i8
+      let y = uint32(x)
+      doAssert $y == "4294967295"
+    block:
+      let x = -1'i16
+      let y = uint32(x)
+      doAssert $y == "4294967295"
+    block:
+      let x = -1'i32
+      let y = uint32(x)
+      doAssert $y == "4294967295"
+    block:
+      proc foo1(arg: int): string =
+        let x = uint32(arg)
+        $x
+      doAssert $foo1(-1) == "4294967295"
+
+  block:
+    let x = 4294967295'u32
+    doAssert $x == "4294967295"
+  block:
+    doAssert $(4294967295'u32) == "4294967295"
+
+proc main()=
+  block:
+    let a = -0.0
+    doAssert $a == "-0.0"
+    doAssert $(-0.0) == "-0.0"
+
+  block:
+    let a = 0.0
+    doAssert $a == "0.0"
+    doAssert $(0.0) == "0.0"
+
+  block:
+    let b = -0
+    doAssert $b == "0"
+    doAssert $(-0) == "0"
+
+  block:
+    let b = 0
+    doAssert $b == "0"
+    doAssert $(0) == "0"
+
+  doAssert $uint32.high == "4294967295"
+
+  block: # addInt
+    var res = newStringOfCap(24)
+    template test2(a, b) =
+      res.setLen(0)
+      res.addInt a
+      doAssert res == b
+
+    for i in 0 .. 9:
+      res.addInt int64(i)
+    doAssert res == "0123456789"
+
+    res.setLen(0)
+    for i in -9 .. 0:
+      res.addInt int64(i)
+    doAssert res == "-9-8-7-6-5-4-3-2-10"
+
+    whenJsNoBigInt64: discard
+    do:
+      test2 high(int64), "9223372036854775807"
+      test2 low(int64), "-9223372036854775808"
+    test2 high(int32), "2147483647"
+    test2 low(int32), "-2147483648"
+    test2 high(int16), "32767"
+    test2 low(int16), "-32768"
+    test2 high(int8), "127"
+    test2 low(int8), "-128"
+
+  block:
+    const
+      a: array[3, char] = ['N', 'i', 'm']
+      aStr = $(a)
+
+    doAssert aStr == """['N', 'i', 'm']"""
+
+static: main()
+main()
diff --git a/tests/system/techo_unicode.nim b/tests/system/techo_unicode.nim
new file mode 100644
index 000000000..cb7c49c68
--- /dev/null
+++ b/tests/system/techo_unicode.nim
@@ -0,0 +1,41 @@
+discard """
+  output: '''ÄhmÖÜ
+abasdfdsmÄhmaИ
+Иnastystring
+A你好
+ИnastystringA你好
+ÖÜhmabasdfdsmÄhmaИOK'''
+  disabled: "posix"
+  joinable: "false"
+"""
+
+import winlean
+
+echo "ÄhmÖÜ"
+echo "abasdfdsmÄhmaИ"
+echo "Иnastystring"
+echo "A你好"
+
+write stdout, "Иnastystring"
+writeLine stdout, "A你好"
+stdout.flushFile()
+
+let handle = getOsFileHandle(stdout)
+var a = "ÖÜhmabasdfdsmÄhmaИ"
+var ac = 0'i32
+discard writeFile(handle, addr a[0], int32(len(a)), addr ac, nil)
+stdout.flushFile()
+
+import os
+
+let str = "some nulls: \0\0\0 (three of them)"
+
+let fpath = getTempDir() / "file_with_nulls.bin"
+
+writeFile(fpath, str)
+
+doAssert(getFileSize(fpath) == 31)
+doAssert(readFile(fpath) == str)
+removeFile(fpath)
+
+echo "OK"
diff --git a/tests/system/temptyecho.nim b/tests/system/temptyecho.nim
new file mode 100644
index 000000000..a3c407897
--- /dev/null
+++ b/tests/system/temptyecho.nim
@@ -0,0 +1,6 @@
+discard """
+output: "\n"
+"""
+
+echo()
+
diff --git a/tests/system/tensuremove.nim b/tests/system/tensuremove.nim
new file mode 100644
index 000000000..668d5aed1
--- /dev/null
+++ b/tests/system/tensuremove.nim
@@ -0,0 +1,131 @@
+discard """
+  targets: "c js"
+  matrix: "--cursorinference:on; --cursorinference:off"
+"""
+
+block:
+  type
+    X = object
+      s: string
+
+  proc `=copy`(x: var X, y: X) =
+    x.s = "copied " & y.s
+
+  proc `=sink`(x: var X, y: X) =
+    `=destroy`(x)
+    wasMoved(x)
+    x.s = "moved " & y.s
+
+  proc consume(x: sink X) =
+    discard x.s
+
+  proc main =
+    let m = "abcdefg"
+    var x = X(s: ensureMove m)
+    consume(ensureMove x)
+
+  static: main()
+  main()
+
+block:
+  type
+    String = object
+      id: string
+
+  proc hello =
+    var s = String(id: "1")
+    var m = ensureMove s
+    doAssert m.id == "1"
+
+  hello()
+
+block:
+  type
+    String = object
+      id: string
+
+  proc hello =
+    var n = "1"
+    var s = String(id: ensureMove n)
+    var m = ensureMove s
+    doAssert m.id == "1"
+
+  hello()
+
+block:
+  type
+    String = object
+      id: string
+
+  proc hello =
+    var n = "1"
+    var s = [ensureMove n]
+    var m = ensureMove s
+    doAssert m[0] == "1"
+
+  hello()
+
+block:
+  type
+    String = object
+      id: string
+
+  proc hello =
+    var n = "1"
+    var s = @[ensureMove n]
+    var m = ensureMove s
+    doAssert m[0] == "1"
+
+  hello()
+
+block:
+  type
+    String = object
+      id: string
+
+  proc hello =
+    var s = String(id: "1")
+    var m = ensureMove s.id
+    doAssert m == "1"
+
+  hello()
+
+block:
+  proc foo =
+    var x = 1
+    let y = ensureMove x # move
+    when not defined(js):
+      doAssert (y, x) == (1, 0) # (1, 0)
+  foo()
+
+block:
+  proc foo =
+    var x = 1
+    let y = ensureMove x # move
+    doAssert y == 1
+  foo()
+
+block:
+  proc foo =
+    var x = @[1, 2, 3]
+    let y = ensureMove x[0] # move
+    doAssert y == 1
+    when not defined(js):
+      doAssert x == @[0, 2, 3]
+  foo()
+
+block:
+  proc foo =
+    var x = [1, 2, 3]
+    let y = ensureMove x[0] # move
+    doAssert y == 1
+    when not defined(js):
+      doAssert x == @[0, 2, 3]
+  foo()
+
+block:
+  proc foo =
+    var x = @["1", "2", "3"]
+    let y = ensureMove x[0] # move
+    doAssert y == "1"
+  foo()
diff --git a/tests/system/tensuremove1.nim b/tests/system/tensuremove1.nim
new file mode 100644
index 000000000..b7e19c4fb
--- /dev/null
+++ b/tests/system/tensuremove1.nim
@@ -0,0 +1,16 @@
+discard """
+  errormsg: "cannot move 's', which introduces an implicit copy"
+  matrix: "--cursorinference:on; --cursorinference:off"
+"""
+
+type
+  String = object
+    id: string
+
+proc hello =
+  var s = String(id: "1")
+  var m = ensureMove s
+  discard m
+  discard s
+
+hello()
\ No newline at end of file
diff --git a/tests/system/tensuremove2.nim b/tests/system/tensuremove2.nim
new file mode 100644
index 000000000..39bbeb22e
--- /dev/null
+++ b/tests/system/tensuremove2.nim
@@ -0,0 +1,15 @@
+discard """
+  errormsg: "Nested expressions cannot be moved: 'if true: s else: String()'"
+"""
+
+type
+  String = object
+    id: string
+
+proc hello =
+  var s = String(id: "1")
+  var m = ensureMove(if true: s else: String())
+  discard m
+  discard s
+
+hello()
\ No newline at end of file
diff --git a/tests/system/tensuremove3.nim b/tests/system/tensuremove3.nim
new file mode 100644
index 000000000..eca032673
--- /dev/null
+++ b/tests/system/tensuremove3.nim
@@ -0,0 +1,28 @@
+discard """
+  errormsg: "cannot move 'x', passing 'x' to a sink parameter introduces an implicit copy"
+  matrix: "--cursorinference:on; --cursorinference:off"
+"""
+
+block:
+  type
+    X = object
+      s: string
+
+  proc `=copy`(x: var X, y: X) =
+    x.s = "copied " & y.s
+
+  proc `=sink`(x: var X, y: X) =
+    `=destroy`(x)
+    wasMoved(x)
+    x.s = "moved " & y.s
+
+  proc consume(x: sink X) =
+    discard x.s
+
+  proc main =
+    var s = "abcdefg"
+    var x = X(s: ensureMove s)
+    consume(ensureMove x)
+    discard x
+
+  main()
\ No newline at end of file
diff --git a/tests/system/tenum_array_repr.nim b/tests/system/tenum_array_repr.nim
new file mode 100644
index 000000000..39b1a5f9a
--- /dev/null
+++ b/tests/system/tenum_array_repr.nim
@@ -0,0 +1,23 @@
+discard """
+  output: '''
+1
+[a, b]
+2
+[c, d]
+4
+[e, f]'''
+"""
+
+# issue 5045
+
+type size1 = enum a, b
+echo sizeof(size1)
+echo repr([a, b])
+
+type size2 = enum c=0, d=20000
+echo sizeof(size2)
+echo repr([c, d])
+
+type size4 = enum e=0, f=2000000000
+echo sizeof(size4)
+echo repr([e, f])
diff --git a/tests/system/tfielditerator.nim b/tests/system/tfielditerator.nim
new file mode 100644
index 000000000..7e063c6cf
--- /dev/null
+++ b/tests/system/tfielditerator.nim
@@ -0,0 +1,126 @@
+discard """
+  output: '''
+a char: true
+a char: false
+an int: 5
+an int: 6
+a string: abc
+false
+true
+true
+false
+true
+a: a
+b: b
+x: 5
+y: 6
+z: abc
+a char: true
+a char: false
+an int: 5
+an int: 6
+a string: abc
+a string: I'm root!
+CMP false
+CMP true
+CMP true
+CMP false
+CMP true
+CMP true
+a: a
+b: b
+x: 5
+y: 6
+z: abc
+thaRootMan: I'm root!
+myDisc: enC
+c: Z
+enC
+Z
+'''
+"""
+
+block titerator1:
+  type
+    TMyTuple = tuple[a, b: char, x, y: int, z: string]
+
+  proc p(x: char) = echo "a char: ", x <= 'a'
+  proc p(x: int) = echo "an int: ", x
+  proc p(x: string) = echo "a string: ", x
+
+  var x: TMyTuple = ('a', 'b', 5, 6, "abc")
+  var y: TMyTuple = ('A', 'b', 5, 9, "abc")
+
+  for f in fields(x):
+    p f
+
+  for a, b in fields(x, y):
+    echo a == b
+
+  for key, val in fieldPairs(x):
+    echo key, ": ", val
+
+  doAssert x != y
+  doAssert x == x
+  doAssert(not (x < x))
+  doAssert x <= x
+  doAssert y < x
+  doAssert y <= x
+
+
+block titerator2:
+  type
+    SomeRootObj = object of RootObj
+      thaRootMan: string
+    TMyObj = object of SomeRootObj
+      a, b: char
+      x, y: int
+      z: string
+
+    TEnum = enum enA, enB, enC
+    TMyCaseObj = object
+      case myDisc: TEnum
+      of enA: a: int
+      of enB: b: string
+      of enC: c: char
+
+  proc p(x: char) = echo "a char: ", x <= 'a'
+  proc p(x: int) = echo "an int: ", x
+  proc p(x: string) = echo "a string: ", x
+
+  proc myobj(a, b: char, x, y: int, z: string): TMyObj =
+    result.a = a; result.b = b; result.x = x; result.y = y; result.z = z
+    result.thaRootMan = "I'm root!"
+
+  var x = myobj('a', 'b', 5, 6, "abc")
+  var y = myobj('A', 'b', 5, 9, "abc")
+
+  for f in fields(x):
+    p f
+
+  for a, b in fields(x, y):
+    echo "CMP ", a == b
+
+  for key, val in fieldPairs(x):
+    echo key, ": ", val
+
+  var co = TMyCaseObj(myDisc: enC, c: 'Z')
+  for key, val in fieldPairs(co):
+    echo key, ": ", val
+
+  for val in fields(co):
+    echo val
+
+block:
+  type
+    Enum = enum A, B
+    Object = object
+      case a: Enum
+      of A:
+        integer: int
+      of B:
+        time: string
+
+  let x = A
+  let s = Object(a: x)
+  doAssert s.integer == 0
diff --git a/tests/system/tfields.nim b/tests/system/tfields.nim
new file mode 100644
index 000000000..0bf3a4e1a
--- /dev/null
+++ b/tests/system/tfields.nim
@@ -0,0 +1,108 @@
+discard """
+  output: '''
+n
+n
+(one: 1, two: 2, three: 3)
+1
+2
+3
+(one: 4, two: 5, three: 6)
+4
+(one: 7, two: 8, three: 9)
+7
+8
+9
+(foo: 38, other: "string here")
+43
+100
+90
+'''
+"""
+
+
+block tindex:
+  type
+    TMyTuple = tuple[a, b: int]
+
+  proc indexOf(t: typedesc, name: string): int =
+    ## takes a tuple and looks for the field by name.
+    ## returs index of that field.
+    var
+      d: t
+      i = 0
+    for n, x in fieldPairs(d):
+      if n == name: return i
+      i.inc
+    raise newException(ValueError, "No field " & name & " in type " &
+      astToStr(t))
+
+  doAssert TMyTuple.indexOf("b") == 1
+
+
+
+block ttemplate:
+  # bug #1902
+  # This works.
+  for name, value in (n: "v").fieldPairs:
+    echo name
+
+  template wrapper(): void =
+    for name, value in (n: "v").fieldPairs:
+      echo name
+  wrapper()
+
+
+
+block tbreak:
+  # bug #2134
+  type
+    TestType = object
+      one: int
+      two: int
+      three: int
+
+  var
+    ab = TestType(one:1, two:2, three:3)
+    ac = TestType(one:4, two:5, three:6)
+    ad = TestType(one:7, two:8, three:9)
+    tstSeq = [ab, ac, ad]
+
+  for tstElement in mitems(tstSeq):
+    echo tstElement
+    for tstField in fields(tstElement):
+      #for tstField in [1,2,4,6]:
+      echo tstField
+      if tstField == 4:
+        break
+
+
+
+block timplicit_with_partial:
+  type
+    Base = ref object of RootObj
+    Foo {.partial.} = ref object of Base
+
+  proc my(f: Foo) =
+    #var f.next = f
+    let f.foo = 38
+    let f.other = "string here"
+    echo f[]
+    echo f.foo + 5
+
+  var g: Foo
+  new(g)
+  my(g)
+
+  type
+    FooTask {.partial.} = ref object of RootObj
+
+  proc foo(t: FooTask) {.liftLocals: t.} =
+    var x = 90
+    if true:
+      var x = 10
+      while x < 100:
+        inc x
+      echo x
+    echo x
+
+  foo(FooTask())
\ No newline at end of file
diff --git a/tests/system/tgcnone.nim b/tests/system/tgcnone.nim
new file mode 100644
index 000000000..1ccb9e29c
--- /dev/null
+++ b/tests/system/tgcnone.nim
@@ -0,0 +1,7 @@
+discard """
+  matrix: "--mm:none -d:useMalloc"
+"""
+# bug #15617
+# bug #22262
+let x = 4
+doAssert x == 4
diff --git a/tests/system/tgcregions.nim b/tests/system/tgcregions.nim
new file mode 100644
index 000000000..e14865be3
--- /dev/null
+++ b/tests/system/tgcregions.nim
@@ -0,0 +1,6 @@
+discard """
+cmd: "nim c --gc:regions $file"
+"""
+
+# issue #12597
+# it just tests that --gc:regions compiles. Nothing else.   :'(
diff --git a/tests/system/tgogc.nim b/tests/system/tgogc.nim
new file mode 100644
index 000000000..fd45bb120
--- /dev/null
+++ b/tests/system/tgogc.nim
@@ -0,0 +1,7 @@
+discard """
+  disabled: "windows"
+  cmd: "nim c --gc:go $file"
+  action: "compile"
+"""
+# bug #11447
+echo "Go GC test"
diff --git a/tests/system/timmutableinc.nim b/tests/system/timmutableinc.nim
new file mode 100644
index 000000000..e857800b3
--- /dev/null
+++ b/tests/system/timmutableinc.nim
@@ -0,0 +1,8 @@
+discard """
+  errormsg: "type mismatch: got <int>"
+  file: "timmutableinc.nim"
+  line: 8
+"""
+var x = 0
+
+inc(x+1)
diff --git a/tests/system/tinvalidnot.nim b/tests/system/tinvalidnot.nim
new file mode 100644
index 000000000..df0291a8a
--- /dev/null
+++ b/tests/system/tinvalidnot.nim
@@ -0,0 +1,19 @@
+discard """
+  errormsg: "type mismatch"
+  file: "tinvalidnot.nim"
+  line: 14
+"""
+# BUG: following compiles, but should not:
+
+proc nodeOfDegree(x: int): bool =
+  result = false
+
+proc main =
+  for j in 0..2:
+    for i in 0..10:
+      if not nodeOfDegree(1) >= 0: #ERROR_MSG type mismatch
+        echo "Yes"
+      else:
+        echo "No"
+
+main()
diff --git a/tests/system/tio.nim b/tests/system/tio.nim
new file mode 100644
index 000000000..52a21837a
--- /dev/null
+++ b/tests/system/tio.nim
@@ -0,0 +1,55 @@
+discard """
+outputsub: ""
+disabled: true
+"""
+
+import
+  unittest, osproc, streams, os, strformat, strutils
+const STRING_DATA = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
+
+const TEST_FILE = "tests/testdata/string.txt"
+
+proc echoLoop(str: string): string =
+  result = ""
+  let exe = findExe("tests/system/helpers/readall_echo")
+  echo "exe: ", exe
+  var process = startProcess(exe)
+  var input = process.inputStream
+  input.write(str)
+  input.close()
+  var output = process.outputStream
+  discard process.waitForExit
+  while not output.atEnd:
+    result.add(output.readLine)
+
+block: # io
+  block: # readAll
+    block: # stdin
+      check:
+        echoLoop(STRING_DATA) == STRING_DATA
+    block: # file
+      check:
+        readFile(TEST_FILE).strip == STRING_DATA
+
+
+proc verifyFileSize(sz: int64) =
+  # issue 7121, large file size (2-4GB and >4Gb)
+  const fn = "tmpfile112358"
+  let size_in_mb = sz div 1_000_000
+
+  when defined(windows):
+    discard execProcess(&"fsutil file createnew {fn} {sz}" )
+  else:
+    discard execProcess(&"dd if=/dev/zero of={fn} bs=1000000 count={size_in_mb}")
+
+  doAssert os.getFileSize(fn) == sz # Verify OS filesize by string
+
+  var f = open(fn)
+  doAssert f.getFileSize() == sz # Verify file handle filesize
+  f.close()
+
+  os.removeFile(fn)
+
+#disable tests for automatic testers
+#for s in [50_000_000'i64, 3_000_000_000, 5_000_000_000]:
+#  verifyFileSize(s)
diff --git a/tests/system/tlocals.nim b/tests/system/tlocals.nim
new file mode 100644
index 000000000..e59976102
--- /dev/null
+++ b/tests/system/tlocals.nim
@@ -0,0 +1,76 @@
+discard """
+  matrix: "--mm:refc; --mm:orc"
+  output: '''(x: "string here", a: 1)
+b is 5
+x is 12'''
+"""
+
+proc simple[T](a: T) =
+  var
+    x = "string here"
+  echo locals()
+
+simple(1)
+
+type Foo2[T]=object
+  a2: T
+
+proc numFields*(T: typedesc[tuple|object]): int=
+  var t:T
+  for _ in t.fields: inc result
+
+proc test(baz: int, qux: var int): int =
+  var foo: Foo2[int]
+  let bar = "abc"
+  let c1 = locals()
+  doAssert numFields(c1.foo.type) == 1
+  doAssert c1.bar == "abc"
+  doAssert c1.baz == 123
+  doAssert c1.result == 0
+  doAssert c1.qux == 456
+
+var x1 = 456
+discard test(123, x1)
+
+# bug #11958
+proc foo() =
+  var a = 5
+  proc bar() {.nimcall.} =
+    var b = 5
+    for k, v in fieldpairs(locals()):
+      echo k, " is ", v
+
+  bar()
+foo()
+
+
+proc foo2() =
+  var a = 5
+  proc bar2() {.nimcall.} =
+    for k, v in fieldpairs(locals()):
+      echo k, " is ", v
+
+  bar2()
+foo2()
+
+
+proc foo3[T](y: T) =
+  var a = 5
+  proc bar2[T](x: T) {.nimcall.} =
+    for k, v in fieldpairs(locals()):
+      echo k, " is ", v
+
+  bar2(y)
+
+foo3(12)
+
+block: # bug #12682
+  template foo(): untyped =
+    var c1 = locals()
+    1
+
+  proc testAll()=
+    doAssert foo() == 1
+    let c2=locals()
+
+  testAll()
diff --git a/tests/system/tlowhigh.nim b/tests/system/tlowhigh.nim
new file mode 100644
index 000000000..6ae871255
--- /dev/null
+++ b/tests/system/tlowhigh.nim
@@ -0,0 +1,32 @@
+discard """
+    action: run
+    output: '''
+18446744073709551615
+9223372036854775807
+4294967295
+0
+0
+'''
+"""
+
+var x: range[-1'f32..1'f32]
+doAssert x.low == -1'f32
+doAssert x.high == 1'f32
+doAssert x.type.low == -1'f32
+doAssert x.type.high == 1'f32
+var y: range[-1'f64..1'f64]
+doAssert y.low == -1'f64
+doAssert y.high == 1'f64
+doAssert y.type.low == -1'f64
+doAssert y.type.high == 1'f64
+
+# bug #11972
+var num: uint8
+doAssert num.high.float == 255.0
+
+echo high(uint64)
+echo high(int64)
+echo high(uint32)
+
+echo low(uint64)
+echo low(uint32)
diff --git a/tests/system/tmagics.nim b/tests/system/tmagics.nim
new file mode 100644
index 000000000..6088c9600
--- /dev/null
+++ b/tests/system/tmagics.nim
@@ -0,0 +1,62 @@
+discard """
+  matrix: "--mm:refc"
+  output: '''
+true
+true
+false
+true
+true
+false
+true
+'''
+joinable: false
+"""
+
+block tlowhigh:
+  type myEnum = enum e1, e2, e3, e4, e5
+  var a: array[myEnum, int]
+
+  for i in low(a) .. high(a):
+    a[i] = 0
+
+  proc sum(a: openArray[int]): int =
+    result = 0
+    for i in low(a)..high(a):
+      inc(result, a[i])
+
+  doAssert sum([1, 2, 3, 4]) == 10
+
+
+block t8693:
+  type Foo = int | float
+
+  proc bar(t1, t2: typedesc): bool =
+    echo (t1 is t2)
+    (t2 is t1)
+
+  proc bar[T](x: T, t2: typedesc): bool =
+    echo (T is t2)
+    (t2 is T)
+
+  doAssert bar(int, Foo) == false
+  doAssert bar(4, Foo) == false
+  doAssert bar(any, int)
+  doAssert bar(int, any) == false
+  doAssert bar(Foo, Foo)
+  doAssert bar(any, Foo)
+  doAssert bar(Foo, any) == false
+
+block t9442:
+  var v1: ref char
+  var v2: string
+  var v3: seq[char]
+  GC_ref(v1)
+  GC_unref(v1)
+  GC_ref(v2)
+  GC_unref(v2)
+  GC_ref(v3)
+  GC_unref(v3)
+
+block: # bug #12229
+  proc foo(T: typedesc) = discard
+  foo(ref)
diff --git a/tests/system/tmemory.nim b/tests/system/tmemory.nim
new file mode 100644
index 000000000..553037011
--- /dev/null
+++ b/tests/system/tmemory.nim
@@ -0,0 +1,16 @@
+import std/assertions
+
+block: # cmpMem
+  type
+    SomeHash = array[15, byte]
+
+  var
+    a: SomeHash
+    b: SomeHash
+
+  a[^1] = byte(1)
+  let c = a
+
+  doAssert cmpMem(a.addr, b.addr, sizeof(SomeHash)) > 0
+  doAssert cmpMem(b.addr, a.addr, sizeof(SomeHash)) < 0
+  doAssert cmpMem(a.addr, c.addr, sizeof(SomeHash)) == 0
diff --git a/tests/system/tnew.nim b/tests/system/tnew.nim
new file mode 100644
index 000000000..c28c1187f
--- /dev/null
+++ b/tests/system/tnew.nim
@@ -0,0 +1,61 @@
+discard """
+matrix: "--mm:refc; --mm:orc"
+outputsub: '''
+Simple tree node allocation worked!
+Simple cycle allocation worked!
+'''
+joinable: false
+"""
+
+# Test the implementation of the new operator
+# and the code generation for gc walkers
+# (and the garbage collector):
+
+type
+  PNode = ref TNode
+  TNode = object
+    data: int
+    str: string
+    le, ri: PNode
+
+  TStressTest = ref array[0..45, array[1..45, TNode]]
+
+proc finalizer(n: PNode) =
+  write(stdout, n.data)
+  write(stdout, " is now freed\n")
+
+proc newNode(data: int, le, ri: PNode): PNode =
+  when defined(gcDestructors): # using finalizer breaks the test for orc
+    new(result)
+  else:
+    new(result, finalizer)
+  result.le = le
+  result.ri = ri
+  result.data = data
+
+# now loop and build a tree
+proc main() =
+  var
+    i = 0
+    p: TStressTest
+  while i < 1000:
+    var n: PNode
+
+    n = newNode(i, nil, newNode(i + 10000, nil, nil))
+    inc(i)
+  new(p)
+
+  write(stdout, "Simple tree node allocation worked!\n")
+  i = 0
+  while i < 1000:
+    var m = newNode(i + 20000, nil, nil)
+    var k = newNode(i + 30000, nil, nil)
+    m.le = m
+    m.ri = k
+    k.le = m
+    k.ri = k
+    inc(i)
+
+  write(stdout, "Simple cycle allocation worked!\n")
+
+main()
diff --git a/tests/system/tnewderef.nim b/tests/system/tnewderef.nim
new file mode 100644
index 000000000..3394dbddf
--- /dev/null
+++ b/tests/system/tnewderef.nim
@@ -0,0 +1,11 @@
+discard """
+  output: 3
+
+"""
+
+var x: ref int
+new(x)
+x[] = 3
+
+echo x[]
+
diff --git a/tests/system/tnewstring_uninitialized.nim b/tests/system/tnewstring_uninitialized.nim
new file mode 100644
index 000000000..9bc0e1622
--- /dev/null
+++ b/tests/system/tnewstring_uninitialized.nim
@@ -0,0 +1,11 @@
+discard """
+  matrix: "--mm:refc;"
+"""
+
+# bug #22555
+var x = newStringUninit(10)
+doAssert x.len == 10
+for i in 0..<x.len:
+  x[i] = chr(ord('a') + i)
+
+doAssert x == "abcdefghij"
diff --git a/tests/system/tnilconcats.nim b/tests/system/tnilconcats.nim
new file mode 100644
index 000000000..69fc3913c
--- /dev/null
+++ b/tests/system/tnilconcats.nim
@@ -0,0 +1,33 @@
+discard """
+  output: '''@["", "", "", "", "", "", "", "meh"]'''
+  exitcode: "0"
+"""
+
+when true:
+  var ab: string
+  ab &= "more"
+
+  doAssert ab == "more"
+
+  var x: seq[string]
+
+  setLen(x, 7)
+
+  x.add "meh"
+
+  var s: string
+  var z = "abc"
+  var zz: string
+  s &= "foo" & z & zz
+
+  doAssert s == "fooabc"
+
+  echo x
+
+  # casting an empty string as sequence with shallow() should not segfault
+  var s2: string
+  when defined(gcRefc):
+    shallow(s2)
+  s2 &= "foo"
+  doAssert s2 == "foo"
+
diff --git a/tests/system/tnim_stacktrace_override.nim b/tests/system/tnim_stacktrace_override.nim
new file mode 100644
index 000000000..c75da9d9b
--- /dev/null
+++ b/tests/system/tnim_stacktrace_override.nim
@@ -0,0 +1,18 @@
+discard """
+  cmd: "nim c -d:nimStacktraceOverride $file"
+  output: '''begin
+Traceback (most recent call last, using override)
+Error: unhandled exception: stack trace produced [ValueError]
+'''
+  exitcode: 1
+"""
+
+import asyncfutures
+
+proc main =
+  echo "begin"
+  if true:
+    raise newException(ValueError, "stack trace produced")
+  echo "unreachable"
+
+main()
diff --git a/tests/system/tostring.nim b/tests/system/tostring.nim
new file mode 100644
index 000000000..bb6e453fb
--- /dev/null
+++ b/tests/system/tostring.nim
@@ -0,0 +1,125 @@
+doAssert "@[23, 45]" == $(@[23, 45])
+doAssert "[32, 45]" == $([32, 45])
+doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"])
+doAssert """["", "foo", "bar"]""" == $(["", "foo", "bar"])
+doAssert """["", "foo", "bar"]""" == $(@["", "foo", "bar"].toOpenArray(0, 2))
+
+# bug #2395
+let alphaSet: set[char] = {'a'..'c'}
+doAssert "{'a', 'b', 'c'}" == $alphaSet
+doAssert "2.3242" == $(2.3242)
+doAssert "2.982" == $(2.982)
+doAssert "123912.1" == $(123912.1)
+doAssert "123912.1823" == $(123912.1823)
+doAssert "5.0" == $(5.0)
+doAssert "1e+100" == $(1e100)
+doAssert "inf" == $(1e1000000)
+doAssert "-inf" == $(-1e1000000)
+doAssert "nan" == $(0.0/0.0)
+
+# nil tests
+# maybe a bit inconsistent in types
+var x: seq[string]
+doAssert "@[]" == $(x)
+
+var y: string
+doAssert "" == $(y)
+
+type
+  Foo = object
+    a: int
+    b: string
+
+var foo1: Foo
+
+# nil string should be an some point in time equal to the empty string
+doAssert(($foo1)[0..9] == "(a: 0, b: ")
+
+const
+  data = @['a','b', '\0', 'c','d']
+  dataStr = $data
+
+# ensure same result when on VM or when at program execution
+doAssert dataStr == $data
+
+import strutils
+# array test
+
+let arr = ['H','e','l','l','o',' ','W','o','r','l','d','!','\0']
+doAssert $arr == "['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\\x00']"
+doAssert $cast[cstring](addr arr) == "Hello World!"
+
+proc takes(c: cstring) =
+  doAssert c == cstring""
+
+proc testm() =
+  var x: string
+  # nil is mapped to "":
+  takes(x)
+
+testm()
+
+# nil tests
+var xx: seq[string]
+var yy: string
+doAssert xx == @[]
+doAssert yy == ""
+
+proc bar(arg: cstring) =
+  doAssert arg[0] == '\0'
+
+proc baz(arg: openArray[char]) =
+  doAssert arg.len == 0
+
+proc stringCompare() =
+  var a,b,c,d,e,f,g: string
+  a.add 'a'
+  doAssert a == "a"
+  b.add "bee"
+  doAssert b == "bee"
+  b.add g
+  doAssert b == "bee"
+  c.addFloat 123.456
+  doAssert c == "123.456"
+  d.addInt 123456
+  doAssert d == "123456"
+
+  doAssert e == ""
+  doAssert "" == e
+  doAssert f == g
+  doAssert "" == ""
+
+  g.setLen(10)
+  doAssert g == "\0\0\0\0\0\0\0\0\0\0"
+  doAssert "" != "\0\0\0\0\0\0\0\0\0\0"
+
+  var nilstring: string
+  #bar(nilstring)
+  baz(nilstring)
+
+stringCompare()
+var nilstring: string
+bar(nilstring)
+
+static:
+  stringCompare()
+
+# issue #8847
+var a2: cstring = "fo\"o2"
+
+block:
+  var s: string
+  s.addQuoted a2
+  doAssert s == "\"fo\\\"o2\""
+
+# issue #16650
+template fn() =
+  doAssert len(cstring"ab\0c") == 5
+  doAssert len(cstring("ab\0c")) == 2
+  when nimvm:
+    discard
+  else:
+    let c = cstring("ab\0c")
+    doAssert len(c) == 2
+fn()
+static: fn()
diff --git a/tests/system/tparams.nim b/tests/system/tparams.nim
new file mode 100644
index 000000000..b20cfce1e
--- /dev/null
+++ b/tests/system/tparams.nim
@@ -0,0 +1,22 @@
+discard """
+joinable: false
+"""
+
+# not joinable because it executes itself with parameters
+import os
+import osproc
+import parseopt
+import sequtils
+
+let argv = commandLineParams()
+
+if argv == @[]:
+  # this won't work with spaces
+  doAssert execShellCmd(getAppFilename() & " \"foo bar\" --aa:bar=a --a=c:d --ab -c --a[baz]:doo") == 0
+else:
+  let f = toSeq(getopt())
+  doAssert f[0].kind == cmdArgument and f[0].key == "foo bar" and f[0].val == ""
+  doAssert f[1].kind == cmdLongOption and f[1].key == "aa" and f[1].val == "bar=a"
+  doAssert f[2].kind == cmdLongOption and f[2].key == "a" and f[2].val == "c:d"
+  doAssert f[3].kind == cmdLongOption and f[3].key == "ab" and f[3].val == ""
+  doAssert f[4].kind == cmdShortOption and f[4].key == "c" and f[4].val == ""
diff --git a/tests/system/trealloc.nim b/tests/system/trealloc.nim
new file mode 100644
index 000000000..1d3e00aff
--- /dev/null
+++ b/tests/system/trealloc.nim
@@ -0,0 +1,23 @@
+discard """
+  output: '''success'''
+  joinable: false
+  disabled: "openbsd"
+"""
+
+# bug #4818
+
+# Test that this completes without OOM.
+
+const BUFFER_SIZE = 5000
+var buffer = cast[ptr uint16](alloc(BUFFER_SIZE))
+
+var total_size: int64 = 0
+for i in 0 .. 1000:
+  let size = BUFFER_SIZE * i
+  #echo "requesting ", size
+  total_size += size.int64
+  buffer = cast[ptr uint16](realloc(buffer, size))
+  #echo totalSize, " total: ", getTotalMem(), " occupied: ", getOccupiedMem(), " free: ", getFreeMem()
+
+dealloc(buffer)
+echo "success"
diff --git a/tests/system/trefs.nim b/tests/system/trefs.nim
new file mode 100644
index 000000000..8c36aec52
--- /dev/null
+++ b/tests/system/trefs.nim
@@ -0,0 +1,15 @@
+discard """
+  targets: "c js"
+"""
+
+# bug #21317
+proc parseHook*(v: var ref int) =
+  var a: ref int
+  new(a)
+  a[] = 123
+  v = a
+
+proc fromJson2*(): ref int =
+  parseHook(result)
+
+doAssert fromJson2()[] == 123
diff --git a/tests/system/tsigexitcode.nim b/tests/system/tsigexitcode.nim
new file mode 100644
index 000000000..249256b40
--- /dev/null
+++ b/tests/system/tsigexitcode.nim
@@ -0,0 +1,23 @@
+discard """
+  joinable: false
+  disabled: windows
+"""
+
+import os, osproc, posix, strutils
+
+proc main() =
+  if paramCount() > 0:
+    let signal = cint parseInt paramStr(1)
+    discard posix.raise(signal)
+  else:
+    # synchronize this list with lib/system/except.nim:registerSignalHandler()
+    let sigs = [SIGINT, SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, SIGPIPE]
+    for s in sigs:
+      let (_, exitCode) = execCmdEx(quoteShellCommand [getAppFilename(), $s])
+      if s == SIGPIPE:
+        # SIGPIPE should be ignored
+        doAssert exitCode == 0, $(exitCode, s)
+      else:
+        doAssert exitCode == 128+s, $(exitCode, s)
+
+main()
diff --git a/tests/system/tslices.nim b/tests/system/tslices.nim
new file mode 100644
index 000000000..d0c68f8cb
--- /dev/null
+++ b/tests/system/tslices.nim
@@ -0,0 +1,65 @@
+discard """
+output: '''
+456456
+456456
+456456
+Zugr5nd
+egerichtetd
+verichtetd
+'''
+"""
+
+# Test the new slices.
+
+var mystr = "Abgrund"
+# mystr[..1] = "Zu" # deprecated
+mystr[0..1] = "Zu"
+
+mystr[4..4] = "5"
+
+type
+  TEnum = enum e1, e2, e3, e4, e5, e6
+
+var myarr: array[TEnum, int] = [1, 2, 3, 4, 5, 6]
+myarr[e1..e3] = myarr[e4..e6]
+# myarr[..e3] = myarr[e4..e6] # deprecated
+myarr[0..e3] = myarr[e4..e6]
+
+for x in items(myarr): stdout.write(x)
+echo()
+
+var myarr2: array[0..5, int] = [1, 2, 3, 4, 5, 6]
+myarr2[0..2] = myarr2[3..5]
+
+for x in items(myarr2): stdout.write(x)
+echo()
+
+
+var myseq = @[1, 2, 3, 4, 5, 6]
+myseq[0..2] = myseq[^3 .. ^1]
+
+for x in items(myseq): stdout.write(x)
+echo()
+
+echo mystr
+
+mystr[4..4] = "u"
+
+# test full replacement
+# mystr[.. ^2] = "egerichtet"  # deprecated
+mystr[0 .. ^2] = "egerichtet"
+
+echo mystr
+
+mystr[0..2] = "ve"
+echo mystr
+
+var s = "abcdef"
+s[1 .. ^2] = "xyz"
+assert s == "axyzf"
+
+# issue mentioned in PR #19219
+type Foo = distinct uint64
+# < here calls `pred` which used to cause a codegen error
+# `pred` compiles because distinct ordinals are considered ordinal
+const slice = 0 ..< 42.Foo
diff --git a/tests/system/tslimsystem.nim b/tests/system/tslimsystem.nim
new file mode 100644
index 000000000..4815306b5
--- /dev/null
+++ b/tests/system/tslimsystem.nim
@@ -0,0 +1,6 @@
+discard """
+  output: "123"
+  matrix: "-d:nimPreviewSlimSystem --mm:refc; -d:nimPreviewSlimSystem --mm:arc"
+"""
+
+echo 123
\ No newline at end of file
diff --git a/tests/system/tstatic.nim b/tests/system/tstatic.nim
new file mode 100644
index 000000000..6e2893e2b
--- /dev/null
+++ b/tests/system/tstatic.nim
@@ -0,0 +1,58 @@
+discard """
+  targets: "c cpp js"
+"""
+
+import std/strutils
+
+# bug #6133
+template main() =
+  block:
+    block:
+      proc foo(q: string, a: int): int =
+        result = q.len
+
+      proc foo(q: static[string]): int =
+        result = foo(q, 5)
+
+      doAssert foo("123") == 3
+
+    block:
+      type E = enum A
+
+      if false:
+        var e = A
+        discard $e
+
+      proc foo(a: string): int =
+        len(a) # 16640
+
+      proc foo(a: static[bool]): int {.used.} =
+        discard
+
+      doAssert foo("") == 0
+
+    block:
+      proc foo(a: string): int =
+        len(a)
+
+      proc foo(a: static[bool]): int {.used.} =
+        discard
+
+      doAssert foo("abc") == 3
+
+    block:
+      proc parseInt(f: static[bool]): int {.used.} = discard
+
+      doAssert "123".parseInt == 123
+  block:
+    type
+      MyType = object
+        field: float32
+      AType[T: static MyType] = distinct range[0f32 .. T.field]
+    var a: AType[MyType(field: 5f32)]
+    proc n(S: static Slice[int]): range[S.a..S.b] = discard
+    assert typeof(n 1..2) is range[1..2]
+
+
+static: main()
+main()
diff --git a/tests/system/tstatic_callable.nim b/tests/system/tstatic_callable.nim
new file mode 100644
index 000000000..92d1fca8d
--- /dev/null
+++ b/tests/system/tstatic_callable.nim
@@ -0,0 +1,12 @@
+# bug #16987
+
+proc getNum(a: int): int = a
+
+# Below calls "doAssert getNum(123) == 123" at compile time.
+static:
+  doAssert getNum(123) == 123
+
+# Below calls evaluate the "getNum(123)" at compile time, but the
+# results of those calls get used at run time.
+doAssert (static getNum(123)) == 123
+doAssert (static(getNum(123))) == 123
diff --git a/tests/system/tstatic_callable_error.nim b/tests/system/tstatic_callable_error.nim
new file mode 100644
index 000000000..c6f1e3d07
--- /dev/null
+++ b/tests/system/tstatic_callable_error.nim
@@ -0,0 +1,14 @@
+# bug #16987
+
+discard """
+errormsg: "cannot evaluate at compile time: inp"
+nimout: '''
+tstatic_callable_error.nim(14, 21) Error: cannot evaluate at compile time: inp'''
+"""
+
+
+# line 10
+proc getNum(a: int): int = a
+
+let inp = 123
+echo (static getNum(inp))
diff --git a/tests/system/tsystem_misc.nim b/tests/system/tsystem_misc.nim
new file mode 100644
index 000000000..1debb7c48
--- /dev/null
+++ b/tests/system/tsystem_misc.nim
@@ -0,0 +1,227 @@
+discard """
+  output:'''1
+1
+2
+3
+11
+12
+13
+14
+15
+2
+3
+4
+2
+1
+2
+3
+2
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+2
+'''
+"""
+
+
+block:
+  const a2 = $(int)
+  const a3 = $int
+  doAssert a2 == "int"
+  doAssert a3 == "int"
+
+  proc fun[T: typedesc](t: T) =
+    const a2 = $(t)
+    const a3 = $t
+    doAssert a2 == "int"
+    doAssert a3 == "int"
+  fun(int)
+
+# check high/low implementations
+doAssert high(int) > low(int)
+doAssert high(int8) > low(int8)
+doAssert high(int16) > low(int16)
+doAssert high(int32) > low(int32)
+doAssert high(int64) > low(int64)
+# doAssert high(uint) > low(uint) # reconsider depending on issue #6620
+doAssert high(uint8) > low(uint8)
+doAssert high(uint16) > low(uint16)
+doAssert high(uint32) > low(uint32)
+# doAssert high(uint64) > low(uint64) # reconsider depending on issue #6620
+doAssert high(float) > low(float)
+doAssert high(float32) > low(float32)
+doAssert high(float64) > low(float64)
+
+proc foo(a: openArray[int]) =
+  for x in a: echo x
+
+foo(toOpenArray([1, 2, 3], 0, 0))
+
+foo(toOpenArray([1, 2, 3], 0, 2))
+
+var arr: array[8..12, int] = [11, 12, 13, 14, 15]
+
+foo(toOpenArray(arr, 8, 12))
+
+var seqq = @[1, 2, 3, 4, 5]
+foo(toOpenArray(seqq, 1, 3))
+
+# empty openArray issue #7904
+foo(toOpenArray(seqq, 0, -1))
+foo(toOpenArray(seqq, 1, 0))
+doAssertRaises(IndexDefect):
+  foo(toOpenArray(seqq, 0, -2))
+
+foo(toOpenArray(arr, 9, 8))
+foo(toOpenArray(arr, 0, -1))
+foo(toOpenArray(arr, 1, 0))
+doAssertRaises(IndexDefect):
+  foo(toOpenArray(arr, 10, 8))
+
+# test openArray of openArray
+proc oaEmpty(a: openArray[int]) =
+  foo(toOpenArray(a, 0, -1))
+
+proc oaFirstElm(a: openArray[int]) =
+  foo(toOpenArray(a, 0, 0))
+
+oaEmpty(toOpenArray(seqq, 0, -1))
+oaEmpty(toOpenArray(seqq, 1, 0))
+oaEmpty(toOpenArray(seqq, 1, 2))
+oaFirstElm(toOpenArray(seqq, 1, seqq.len-1))
+
+var arrNeg: array[-3 .. -1, int] = [1, 2, 3]
+foo(toOpenArray(arrNeg, -3, -1))
+foo(toOpenArray(arrNeg, 0, -1))
+foo(toOpenArray(arrNeg, -3, -4))
+doAssertRaises(IndexDefect):
+  foo(toOpenArray(arrNeg, -4, -1))
+doAssertRaises(IndexDefect):
+  foo(toOpenArray(arrNeg, -1, 0))
+doAssertRaises(IndexDefect):
+  foo(toOpenArray(arrNeg, -1, -3))
+doAssertRaises(Exception):
+  raise newException(Exception, "foo")
+
+block:
+  var didThrow = false
+  try:
+    doAssertRaises(IndexDefect): # should fail since it's wrong exception
+      raise newException(FieldDefect, "foo")
+  except AssertionDefect:
+    # ok, throwing was correct behavior
+    didThrow = true
+  doAssert didThrow
+
+type seqqType = ptr UncheckedArray[int]
+let qData = cast[seqqType](addr seqq[0])
+oaFirstElm(toOpenArray(qData, 1, 3))
+
+proc foo(a: openArray[byte]) =
+  for x in a: echo x
+
+let str = "0123456789"
+foo(toOpenArrayByte(str, 0, str.high))
+
+
+template boundedOpenArray[T](x: seq[T], first, last: int): openArray[T] =
+  toOpenarray(x, max(0, first), min(x.high, last))
+
+# bug #9281
+
+proc foo[T](x: openArray[T]) =
+  echo x.len
+
+let a = @[1, 2, 3]
+
+# a.boundedOpenArray(1, 2).foo()  # Works
+echo a.boundedOpenArray(1, 2).len # Internal compiler error
+
+block: # `$`*[T: tuple|object](x: T)
+  doAssert $(foo1:0, bar1:"a") == """(foo1: 0, bar1: "a")"""
+  doAssert $(foo1:0, ) == """(foo1: 0)"""
+  doAssert $(0, "a") == """(0, "a")"""
+  doAssert $(0, ) == "(0,)"
+  type Foo = object
+    x:int
+    x2:float
+  doAssert $Foo(x:2) == "(x: 2, x2: 0.0)"
+  doAssert $() == "()"
+
+# this is a call indirection to prevent `toInt` to be resolved at compile time.
+proc testToInt(arg: float64, a: int, b: BiggestInt) =
+  doAssert toInt(arg) == a
+  doAssert toBiggestInt(arg) == b
+
+testToInt(0.45, 0, 0)    # should round towards 0
+testToInt(-0.45, 0, 0)   # should round towards 0
+testToInt(0.5, 1, 1)     # should round away from 0
+testToInt(-0.5, -1, -1)  # should round away from 0
+testToInt(13.37, 13, 13)    # should round towards 0
+testToInt(-13.37, -13, -13) # should round towards 0
+testToInt(7.8, 8, 8)     # should round away from 0
+testToInt(-7.8, -8, -8)  # should round away from 0
+
+# test min/max for correct NaN handling
+
+proc testMinMax(a,b: float32) =
+  doAssert max(float32(a),float32(b)) == 0'f32
+  doAssert min(float32(a),float32(b)) == 0'f32
+  doAssert max(float64(a),float64(b)) == 0'f64
+  doAssert min(float64(a),float64(b)) == 0'f64
+
+testMinMax(0.0, NaN)
+testMinMax(NaN, 0.0)
+
+
+block:
+  type Foo = enum
+    k1, k2
+  var
+    a = {k1}
+    b = {k1,k2}
+  doAssert a < b
+
+
+block: # Ordinal
+  doAssert int is Ordinal
+  doAssert uint is Ordinal
+  doAssert int64 is Ordinal
+  doAssert uint64 is Ordinal
+  doAssert char is Ordinal
+  type Foo = enum k1, k2
+  doAssert Foo is Ordinal
+  doAssert Foo is SomeOrdinal
+  doAssert enum is SomeOrdinal
+
+  # these fail:
+  # doAssert enum is Ordinal # fails
+  # doAssert Ordinal is SomeOrdinal
+  # doAssert SomeOrdinal is Ordinal
+
+block:
+  proc p() = discard
+
+  doAssert not compiles(echo p.rawProc.repr)
+  doAssert not compiles(echo p.rawEnv.repr)
+  doAssert not compiles(echo p.finished)
+
+proc bug23223 = # bug #23223
+  var stuff = "hello"
+  stuff.insert ""
+  doAssert stuff == "hello"
+
+bug23223()
+
+block: # bug #23894
+  let v = high(uint) div 2
+  let s = v + 1 # 9223372036854775808
+  let m = succ v
+  doAssert s == m
diff --git a/tests/system/tuse_version16.nim b/tests/system/tuse_version16.nim
new file mode 100644
index 000000000..802b617ad
--- /dev/null
+++ b/tests/system/tuse_version16.nim
@@ -0,0 +1,49 @@
+discard """
+  matrix: "-d:NimMajor=1 -d:NimMinor=6 -d:NimPatch=100"
+"""
+
+{.warning[UnusedImport]: off.}
+
+import std/[
+  # Core:
+  bitops, typetraits, lenientops, macros, volatile,
+
+  # Algorithms:
+  algorithm, sequtils,
+
+  # Collections:
+  critbits, deques, heapqueue, intsets, lists, options, sets,
+  sharedlist, tables,
+
+  # Strings:
+  editdistance, wordwrap, parseutils, ropes,
+  pegs, strformat, strmisc, strscans, strtabs,
+  strutils, unicode, unidecode,
+
+  # Generic operator system services:
+  os, streams,
+
+  # Math libraries:
+  complex, math, mersenne, random, rationals, stats, sums,
+
+  # Internet protocols:
+  httpcore, mimetypes, uri,
+
+  # Parsers:
+  htmlparser, json, lexbase, parsecfg, parsecsv, parsesql, parsexml,
+
+  # XML processing:
+  xmltree, xmlparser,
+
+  # Generators:
+  htmlgen,
+
+  # Hashing:
+  base64, hashes,
+
+  # Miscellaneous:
+  colors, sugar, varints,
+]
+
+
+doAssert NimVersion == "1.6.100"
diff --git a/tests/system/tvarargslen.nim b/tests/system/tvarargslen.nim
new file mode 100644
index 000000000..24b54a1e0
--- /dev/null
+++ b/tests/system/tvarargslen.nim
@@ -0,0 +1,60 @@
+discard """
+  output: '''
+tvarargslen.nim:35:2 (1, 2)
+tvarargslen.nim:36:2 12
+tvarargslen.nim:37:2 1
+tvarargslen.nim:38:8 
+done
+'''
+"""
+## line 10
+
+template myecho*(a: varargs[untyped]) =
+  ## shows a useful debugging echo-like proc that is dependency-free (no dependency
+  ## on macros.nim) so can be used in more contexts
+  const info = instantiationInfo(-1, false)
+  const loc = info.filename & ":" & $info.line & ":" & $info.column & " "
+  when varargsLen(a) > 0:
+    echo(loc, a)
+  else:
+    echo(loc)
+
+template fun*(a: varargs[untyped]): untyped =
+  varargsLen(a)
+
+template fun2*(a: varargs[typed]): untyped =
+  a.varargsLen
+
+template fun3*(a: varargs[int]): untyped =
+  a.varargsLen
+
+template fun4*(a: varargs[untyped]): untyped =
+  len(a)
+
+proc main()=
+  myecho (1, 2)
+  myecho 1, 2
+  myecho 1
+  myecho()
+
+  doAssert fun() == 0
+  doAssert fun('a') == 1
+  doAssert fun("asdf", 1) == 2
+
+  doAssert fun2() == 0
+  doAssert fun2('a') == 1
+  doAssert fun2("asdf", 1) == 2
+
+  doAssert fun3() == 0
+  doAssert fun3(10) == 1
+  doAssert fun3(10, 11) == 2
+
+  ## shows why `varargsLen` can't be named `len`
+  doAssert fun4("abcdef") == len("abcdef")
+
+  ## workaround for BUG:D20191218T171447 whereby if testament expected output ends
+  ## in space, testament strips it from expected output but not actual output,
+  ## which leads to a mismatch when running test via megatest
+  echo "done"
+
+main()