diff options
Diffstat (limited to 'tests/misc')
95 files changed, 1143 insertions, 1577 deletions
diff --git a/tests/misc/m15316.nim b/tests/misc/m15316.nim new file mode 100644 index 000000000..188d06946 --- /dev/null +++ b/tests/misc/m15316.nim @@ -0,0 +1 @@ +proc foo = (if) diff --git a/tests/misc/m15955.nim b/tests/misc/m15955.nim new file mode 100644 index 000000000..22da345db --- /dev/null +++ b/tests/misc/m15955.nim @@ -0,0 +1,4 @@ +proc add*(a, b: int): int {.cdecl, exportc.} = + a + b +proc sub*(a, b: int): int {.cdecl, exportc.} = + a - b \ No newline at end of file diff --git a/tests/misc/m15955_main.nim b/tests/misc/m15955_main.nim new file mode 100644 index 000000000..a71af8121 --- /dev/null +++ b/tests/misc/m15955_main.nim @@ -0,0 +1,11 @@ +import stdtest/specialpaths +import std/os + +const buildLib = buildDir / "libD20220923T19380" + +{.passL: buildLib.} +proc add*(a, b: int):int {.cdecl, importc.} +proc sub*(a, b: int):int {.cdecl, importc.} + +echo add(10, 5) +echo sub(10, 5) diff --git a/tests/misc/m20149.nim b/tests/misc/m20149.nim new file mode 100644 index 000000000..942262a6e --- /dev/null +++ b/tests/misc/m20149.nim @@ -0,0 +1,2 @@ +let x = 12 +echo x diff --git a/tests/misc/m20456.nims b/tests/misc/m20456.nims new file mode 100644 index 000000000..8a9313129 --- /dev/null +++ b/tests/misc/m20456.nims @@ -0,0 +1 @@ +echo 123 \ No newline at end of file diff --git a/tests/misc/mbetterrun.nim b/tests/misc/mbetterrun.nim new file mode 100644 index 000000000..d4f427af0 --- /dev/null +++ b/tests/misc/mbetterrun.nim @@ -0,0 +1,3 @@ +const mbetterrunVal {.strdefine.} = "" +static: echo "compiling: " & mbetterrunVal +echo "running: " & mbetterrunVal diff --git a/tests/misc/mfield_defect.nim b/tests/misc/mfield_defect.nim new file mode 100644 index 000000000..53bfba40e --- /dev/null +++ b/tests/misc/mfield_defect.nim @@ -0,0 +1,30 @@ +#[ +ran from trunner +]# + + + + + + +# line 10 +type Kind = enum k0, k1, k2, k3, k4 + +type Foo = object + case kind: Kind + of k0: f0: int + of k1: f1: int + of k2: f2: int + of k3: f3: int + of k4: f4: int + +proc main()= + var foo = Foo(kind: k3, f3: 3) + let s1 = foo.f3 + doAssert s1 == 3 + let s2 = foo.f2 + +when defined case1: + static: main() +when defined case2: + main() diff --git a/tests/misc/mjsondoc.nim b/tests/misc/mjsondoc.nim new file mode 100644 index 000000000..016c8522d --- /dev/null +++ b/tests/misc/mjsondoc.nim @@ -0,0 +1,14 @@ +proc doSomething*(x, y: int): int = + ## do something + x + y + +const + a* = 1 ## echo 1234 + b* = "test" + +type + MyEnum* = enum + foo, bar + +proc foo2*[T: int, M: string, U](x: T, y: U, z: M) = + echo 1 diff --git a/tests/misc/mspellsuggest.nim b/tests/misc/mspellsuggest.nim deleted file mode 100644 index ad449554f..000000000 --- a/tests/misc/mspellsuggest.nim +++ /dev/null @@ -1,7 +0,0 @@ -proc fooBar4*(a: int) = discard -var fooBar9* = 0 - -var fooCar* = 0 -type FooBar* = int -type FooCar* = int -type GooBa* = int diff --git a/tests/misc/parsecomb.nim b/tests/misc/parsecomb.nim index 4ff2f65d2..4f149cbf6 100644 --- a/tests/misc/parsecomb.nim +++ b/tests/misc/parsecomb.nim @@ -1,3 +1,7 @@ +discard """ + matrix: "--mm:arc; --mm:refc" +""" + type Input[T] = object toks: seq[T] index: int diff --git a/tests/misc/t11634.nim b/tests/misc/t11634.nim new file mode 100644 index 000000000..390af40f4 --- /dev/null +++ b/tests/misc/t11634.nim @@ -0,0 +1,17 @@ +discard """ + action: reject +""" + +type Foo = ref object + val: int + +proc divmod(a, b: Foo): (Foo, Foo) = + ( + Foo(val: a.val div b.val), + Foo(val: a.val mod b.val) + ) + +block: + let a {.compileTime.} = Foo(val: 2) + let b {.compileTime.} = Foo(val: 3) + let (c11634 {.compileTime.}, d11634 {.compileTime.}) = divmod(a, b) diff --git a/tests/misc/t12869.nim b/tests/misc/t12869.nim new file mode 100644 index 000000000..054e28a03 --- /dev/null +++ b/tests/misc/t12869.nim @@ -0,0 +1,14 @@ +discard """ + errormsg: "type mismatch: got <openArray[int], proc (x: GenericParam, y: GenericParam): auto, SortOrder>" + line: 12 +""" + +import sugar +from algorithm import sorted, SortOrder + +let a = 5 + +proc sorted*[T](a: openArray[T], key: proc(v: T): int, order = SortOrder.Ascending): seq[T] = + sorted(a, (x, y) => key(x) < key(y), order) + +echo sorted(@[9, 1, 8, 2, 6, 4, 5, 0], (x) => (a - x).abs) diff --git a/tests/misc/t14667.nim b/tests/misc/t14667.nim new file mode 100644 index 000000000..3034e2841 --- /dev/null +++ b/tests/misc/t14667.nim @@ -0,0 +1,12 @@ +discard """ + matrix: "--cc:vcc" + disabled: "linux" + disabled: "bsd" + disabled: "osx" + disabled: "unix" + disabled: "posix" +""" + +type A = tuple +discard () +discard default(A) diff --git a/tests/misc/t15351.nim b/tests/misc/t15351.nim new file mode 100644 index 000000000..c31e604a2 --- /dev/null +++ b/tests/misc/t15351.nim @@ -0,0 +1,5 @@ +discard """ + action: "compile" +""" +var + ## TODO: broken diff --git a/tests/misc/t15955.nim b/tests/misc/t15955.nim new file mode 100644 index 000000000..7441e5398 --- /dev/null +++ b/tests/misc/t15955.nim @@ -0,0 +1,22 @@ +discard """ +joinable: false +""" + +import stdtest/specialpaths +import std/[osproc, strformat, os] + +const + nim = getCurrentCompilerExe() + buildLib = buildDir / "libD20220923T19380" + currentDir = splitFile(currentSourcePath).dir + file = currentDir / "m15955.nim" + main = currentDir / "m15955_main.nim" + + +proc runCmd(cmd: string) = + let (msg, code) = execCmdEx(cmd) + doAssert code == 0, msg + + +runCmd fmt"{nim} c -o:{buildLib} --nomain --nimMainPrefix:libA -f --app:staticlib {file}" +runCmd fmt"{nim} c -r {main}" diff --git a/tests/misc/t16244.nim b/tests/misc/t16244.nim new file mode 100644 index 000000000..5e8128736 --- /dev/null +++ b/tests/misc/t16244.nim @@ -0,0 +1,9 @@ +discard """ + errormsg: "type mismatch: got <int, float64>" + line: 9 +""" + +proc g(): auto = 1 +proc h(): auto = 1.0 + +var a = g() + h() diff --git a/tests/misc/t16264.nim b/tests/misc/t16264.nim new file mode 100644 index 000000000..afe319e6c --- /dev/null +++ b/tests/misc/t16264.nim @@ -0,0 +1,2 @@ +import times +doAssert low(Time) == fromUnix(0) \ No newline at end of file diff --git a/tests/misc/t16541.nim b/tests/misc/t16541.nim new file mode 100644 index 000000000..452327e8f --- /dev/null +++ b/tests/misc/t16541.nim @@ -0,0 +1,12 @@ +discard """ + action: "reject" + +""" + +import strutils, sugar, nre + +proc my_replace*(s: string, r: Regex, by: string | (proc (match: string): string)): string = + nre.replace(s, r, by) + +discard my_replace("abcde", re"[bcd]", match => match.to_upper) == "aBCDe" +discard my_replace("abcde", re"[bcd]", (match: string) => match.to_upper) == "aBCDe" diff --git a/tests/misc/t17286.nim b/tests/misc/t17286.nim new file mode 100644 index 000000000..3a54e624e --- /dev/null +++ b/tests/misc/t17286.nim @@ -0,0 +1,16 @@ +discard """ + cmd: "nim check -b:js $file" + action: "compile" +""" + +# bug #17286 + +import std/compilesettings + +static: + doAssert querySetting(backend) == "js" + doAssert defined(js) + doAssert not defined(c) + +import random +randomize() \ No newline at end of file diff --git a/tests/misc/t18077.nim b/tests/misc/t18077.nim new file mode 100644 index 000000000..6cd05d575 --- /dev/null +++ b/tests/misc/t18077.nim @@ -0,0 +1,21 @@ +discard """ + cmd: '''nim doc -d:nimTestsT18077b:4 --doccmd:"-d:nimTestsT18077 -d:nimTestsT18077b:3 --hints:off" $file''' + action: compile +""" + +# bug #18077 + +const nimTestsT18077b {.intdefine.} = 1 + +static: + when defined(nimdoc): + doAssert nimTestsT18077b == 4 + doAssert not defined(nimTestsT18077) + else: + doAssert defined(nimTestsT18077) + doAssert nimTestsT18077b == 3 + +runnableExamples: + const nimTestsT18077b {.intdefine.} = 2 + doAssert nimTestsT18077b == 3 + doAssert defined(nimTestsT18077) diff --git a/tests/misc/t18079.nim b/tests/misc/t18079.nim new file mode 100644 index 000000000..ae64bbff9 --- /dev/null +++ b/tests/misc/t18079.nim @@ -0,0 +1,15 @@ +discard """ + matrix: "--mm:orc" +""" + +type + Foo = object + y: int + + Bar = object + x: Foo + +proc baz(state: var Bar):int = + state.x.y = 2 + state.x.y +doAssert baz((ref Bar)(x: (new Foo)[])[]) == 2 diff --git a/tests/misc/t19046.nim b/tests/misc/t19046.nim new file mode 100644 index 000000000..b3bfec7ae --- /dev/null +++ b/tests/misc/t19046.nim @@ -0,0 +1,19 @@ +discard """ + targets: "c cpp" + matrix: "--threads:on" + disabled: "win" + disabled: "osx" + action: compile +""" + +# bug #19046 + +import std/os + +var t: Thread[void] + +proc test = discard +proc main = + createThread(t, test) + pinToCpu(t, 1) +main() \ No newline at end of file diff --git a/tests/misc/t20253.nim b/tests/misc/t20253.nim new file mode 100644 index 000000000..d47c36c55 --- /dev/null +++ b/tests/misc/t20253.nim @@ -0,0 +1,10 @@ +discard """ + errormsg: "'result' requires explicit initialization" + line: 10 +""" + +type Meow {.requiresInit.} = object + init: bool + +proc initMeow(): Meow = + discard diff --git a/tests/misc/t20289.nim b/tests/misc/t20289.nim new file mode 100644 index 000000000..5a0a269f0 --- /dev/null +++ b/tests/misc/t20289.nim @@ -0,0 +1,15 @@ +discard """ + action: reject +""" + +type E[T] = object + v: T + +template j[T](R: type E[T], x: untyped): R = R(v: x) +template d[T](O: type E, v: T): E[T] = E[T].j(v) + +proc w[T](): E[T] = + template r(k: int): auto = default(T) + E.d r + +discard w[int]() diff --git a/tests/misc/t20456_2.nim b/tests/misc/t20456_2.nim new file mode 100644 index 000000000..37e52c452 --- /dev/null +++ b/tests/misc/t20456_2.nim @@ -0,0 +1,14 @@ +discard """ + joinable: false +""" + +import std/[osproc, os, strformat] +from stdtest/specialpaths import testsDir + +when defined(nimPreviewSlimSystem): + import std/assertions + +const + nim = getCurrentCompilerExe() + file = testsDir / "misc" / "m20456.nims" +doAssert execCmd(fmt"{nim} check {file}") == 0 diff --git a/tests/misc/t20883.nim b/tests/misc/t20883.nim new file mode 100644 index 000000000..92e7929f4 --- /dev/null +++ b/tests/misc/t20883.nim @@ -0,0 +1,13 @@ +discard """ + action: reject +nimout: ''' +t20883.nim(13, 4) template/generic instantiation of `foo` from here +t20883.nim(9, 11) Error: cannot instantiate: 'U' +''' +""" + +proc foo*[U](x: U = U(1e-6)) = + echo x + +foo[float]() +foo() diff --git a/tests/misc/t21109.nim b/tests/misc/t21109.nim new file mode 100644 index 000000000..0f7980896 --- /dev/null +++ b/tests/misc/t21109.nim @@ -0,0 +1,13 @@ +discard """ + action: reject + errormsg: "type expected" + file: "iterators.nim" +""" + + +template b(j: untyped) = j +template m() = discard + +b: + for t, f in @[]: + m() diff --git a/tests/misc/t21443.nim b/tests/misc/t21443.nim new file mode 100644 index 000000000..70413c5b3 --- /dev/null +++ b/tests/misc/t21443.nim @@ -0,0 +1,6 @@ +import std/envvars + +# bug #19292 +putEnv("NimPutEnvTest", "test") +# bug #21122 +doAssert getEnv("NimPutEnvTest") == "test" diff --git a/tests/misc/t23240.nim b/tests/misc/t23240.nim new file mode 100644 index 000000000..d5edcefe8 --- /dev/null +++ b/tests/misc/t23240.nim @@ -0,0 +1,6 @@ +discard """ + cmd: "nim c foo/bar.nim" + action: "reject" + errormsg: "cannot open 'foo/'" + file: "" +""" diff --git a/tests/misc/t3482.nim b/tests/misc/t3482.nim new file mode 100644 index 000000000..33b3b8f40 --- /dev/null +++ b/tests/misc/t3482.nim @@ -0,0 +1,15 @@ +discard """ + action: reject + nimout: "t3482.nim(13, 8) Error: undeclared identifier: 'output'" +""" +# bug #3482 (correct behavior since 1.4.0, cgen error in 1.2.0) +template foo*(body: typed) = + if true: + body + +proc test = + foo: + var output = "" + echo output.len + +test() diff --git a/tests/misc/t3907.nim b/tests/misc/t3907.nim new file mode 100644 index 000000000..45fc75e81 --- /dev/null +++ b/tests/misc/t3907.nim @@ -0,0 +1,10 @@ +import std/assertions + +let a = 0 +let b = if false: -1 else: a +doAssert b == 0 + +let c: range[0..high(int)] = 0 +let d = if false: -1 else: c + +doAssert d == 0 diff --git a/tests/misc/t5540.nim b/tests/misc/t5540.nim new file mode 100644 index 000000000..6a19e70e1 --- /dev/null +++ b/tests/misc/t5540.nim @@ -0,0 +1,45 @@ +# bug #5540; works in 1.2.0 +# fails in 1.0 (Error: cannot generate VM code for) +# fails in 0.18.0 (Error: type mismatch: got <type T>) + +block: + type + Fruit = object + Yellow = object + a: int + template getColor(x: typedesc[Fruit]): typedesc = Yellow + type + Banana[T] = object + b: T + a: getColor(Fruit) + Apple[T] = object + a: T + b: getColor(T) + block: + var x: Banana[int] + doAssert x.b == 0 + doAssert x.a is Yellow + block: + var x: Apple[Fruit] + doAssert x.b is Yellow + +block: + type + Fruit = object + Yellow = object + a: int + + template getColor(x: typedesc[Fruit]): typedesc = Yellow + + type + Banana[T] = object + b: T + a: getColor(Fruit) + + Apple[T] = object + a: T + b: getColor(T) + + var x: Banana[int] + x.b = 13 + x.a.a = 17 diff --git a/tests/misc/t6549.nim b/tests/misc/t6549.nim new file mode 100644 index 000000000..1d7393318 --- /dev/null +++ b/tests/misc/t6549.nim @@ -0,0 +1,4 @@ + +const l = $(range[low(uint64) .. high(uint64)]) +const r = "range 0..18446744073709551615(uint64)" +doAssert l == r diff --git a/tests/misc/t8545.nim b/tests/misc/t8545.nim index 89957e1d3..48b886cb8 100644 --- a/tests/misc/t8545.nim +++ b/tests/misc/t8545.nim @@ -1,5 +1,6 @@ discard """ - targets: "c cpp js" + # just tests that this doesn't crash the compiler + errormsg: "cannot instantiate: 'a:type'" """ # bug #8545 diff --git a/tests/misc/t9039.nim b/tests/misc/t9039.nim new file mode 100644 index 000000000..3271cd34e --- /dev/null +++ b/tests/misc/t9039.nim @@ -0,0 +1,24 @@ +discard """ + action: reject + nimout: ''' +t9039.nim(22, 22) Error: type mismatch: got <array[0..2, int], int, array[0..1, int]> +but expression 'nesting + 1' is of type: int +''' +""" + +# bug #9039; this used to hang in 0.19.0 + + + + + +# line 15 +func default(T: typedesc[array]): T = discard +doAssert default(array[3, int]) == [0, 0, 0] +func shapeBad*[T: not char](s: openArray[T], rank: static[int], nesting = 0, parent_shape = default(array[rank, int])): array[rank, int] = + result = parent_shape + result[nesting] = s.len + when (T is seq|array): + result = shapeBad(s[0], nesting + 1, result) +let a1 = [1, 2, 3].shapeBad(rank = 1) +let a2 = [[1, 2, 3], [4, 5, 6]].shapeBad(rank = 2) diff --git a/tests/misc/t9091.nim b/tests/misc/t9091.nim new file mode 100644 index 000000000..6e7a98ca5 --- /dev/null +++ b/tests/misc/t9091.nim @@ -0,0 +1,33 @@ +# bug #9091 + +import streams + +block: + type Mine = ref object + a: int + + proc write(io: Stream, t: Mine) = + io.write("sure") + + let str = newStringStream() + let mi = new Mine + + str.write(mi) + str.setPosition 0 + doAssert str.readAll == "sure" + +block: + type + AObj = object + x: int + + proc foo(a: int): string = "" + + proc test(args: varargs[string, foo]) = + doAssert false + + proc test(a: AObj) = + discard + + let x = AObj() + test(x) diff --git a/tests/misc/t9710.nim b/tests/misc/t9710.nim new file mode 100644 index 000000000..c65cb7bf4 --- /dev/null +++ b/tests/misc/t9710.nim @@ -0,0 +1,6 @@ +discard """ + matrix: "--debugger:native" +""" +# bug #9710 +for i in 1 || 200: + discard i diff --git a/tests/misc/taddr.nim b/tests/misc/taddr.nim index bac26896d..64f95c7e3 100644 --- a/tests/misc/taddr.nim +++ b/tests/misc/taddr.nim @@ -32,6 +32,10 @@ doAssert objDeref.x == 42 # String tests obj.s = "lorem ipsum dolor sit amet" +when defined(gcArc) or defined(gcOrc): + prepareMutation(obj.s) + + var indexAddr = addr(obj.s[2]) doAssert indexAddr[] == 'r' @@ -83,7 +87,7 @@ block: # bug #14576 # lots of these used to give: Error: internal error: genAddr: 2 proc byLent[T](a: T): lent T = a - proc byPtr[T](a: T): ptr T = a.unsafeAddr + proc byPtr[T](a: T): ptr T = a.addr block: let a = (10,11) @@ -232,8 +236,17 @@ block: # bug #15939 const bar = proc2(foo) doAssert bar == "foo" +template prepareMutationForOrc(x: string) = + when defined(gcArc) or defined(gcOrc): + when nimvm: + discard + else: + prepareMutation(x) + proc test15939() = # bug #15939 (v2) template fn(a) = + when typeof(a) is string: + prepareMutationForOrc(a) let pa = a[0].addr doAssert pa != nil doAssert pa[] == 'a' @@ -253,12 +266,23 @@ proc test15939() = # bug #15939 (v2) # mycstring[ind].addr template cstringTest = var a2 = "abc" + prepareMutationForOrc(a2) var b2 = a2.cstring fn(b2) when nimvm: cstringTest() else: # can't take address of cstring element in js when not defined(js): cstringTest() +block: # bug #23499 + template volatileStore[T](dest: ptr T, val: T) = + dest[] = val + + proc foo = + var ctr = 0 + volatileStore(addr ctr, 0) + + foo() + template main = # xxx wrap all other tests here like that so they're also tested in VM test14420() diff --git a/tests/misc/tcast.nim b/tests/misc/tcast.nim index 454801a2d..73196e76c 100644 --- a/tests/misc/tcast.nim +++ b/tests/misc/tcast.nim @@ -1,6 +1,7 @@ discard """ output: ''' Hello World +Hello World Hello World''' joinable: false """ @@ -8,7 +9,7 @@ type MyProc = proc() {.cdecl.} type MyProc2 = proc() {.nimcall.} type MyProc3 = proc() #{.closure.} is implicit -proc testProc() = echo "Hello World" +proc testProc() {.exportc:"foo".} = echo "Hello World" template reject(x) = doAssert(not compiles(x)) @@ -23,6 +24,10 @@ proc callPointer(p: pointer) = ffunc0() ffunc1() + # bug #5901 + proc foo() {.importc.} + (cast[proc(a: int) {.cdecl.}](foo))(5) + callPointer(cast[pointer](testProc)) reject: discard cast[enum](0) @@ -48,7 +53,7 @@ block: var x: ref int = nil doAssert cast[int](cast[ptr int](x)) == 0 -block: +block: # cast of nil block: static: let a = cast[pointer](nil) @@ -71,7 +76,33 @@ block: static: doAssert cast[RootRef](nil).repr == "nil" - # Issue #15730, not fixed yet - # block: - # static: - # doAssert cast[cstring](nil).repr == "nil" + when false: # xxx bug #15730, not fixed yet + block: + static: + doAssert cast[cstring](nil).repr == "nil" + +template main() = + # xxx move all under here to get tested in VM + block: # cast of enum + type Koo = enum k1, k2 + type Goo = enum g1, g2 + type Boo = enum b1 = -1, b2, b3, b4 + type Coo = enum c1 = -1i8, c2, c3, c4 + when nimvm: + # xxx: Error: VM does not support 'cast' from tyEnum to tyEnum + discard + else: + doAssert cast[Koo](k2) == k2 + doAssert cast[Goo](k2) == g2 + doAssert cast[Goo](k2.ord) == g2 + + doAssert b3.ord == 1 + doAssert cast[Koo](b3) == k2 + doAssert cast[Boo](k2) == b3 + + doAssert c3.ord == 1 + doAssert cast[Koo](c3) == k2 + doAssert cast[Coo](k2) == c3 + +static: main() +main() diff --git a/tests/misc/tcolonisproc.nim b/tests/misc/tcolonisproc.nim deleted file mode 100644 index c10dabcf1..000000000 --- a/tests/misc/tcolonisproc.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ -output: ''' -1 -2 -''' -""" - -proc p(a, b: int, c: proc ()) = - c() - -when false: - # language spec changed: - p(1, 3): - echo 1 - echo 3 - -p(1, 1, proc() = - echo 1 - echo 2) diff --git a/tests/misc/tconv.nim b/tests/misc/tconv.nim index f7d15b0b5..90fae868b 100644 --- a/tests/misc/tconv.nim +++ b/tests/misc/tconv.nim @@ -1,5 +1,14 @@ +discard """ + matrix: "--warningAsError:EnumConv --warningAsError:CStringConv" +""" + +from std/enumutils import items # missing from the example code +from std/sequtils import toSeq + template reject(x) = - static: assert(not compiles(x)) + static: doAssert(not compiles(x)) +template accept(x) = + static: doAssert(compiles(x)) reject: const x = int8(300) @@ -55,3 +64,80 @@ block: # issue 3766 proc r(x: static[R]) = echo x r 3.R + + +block: # https://github.com/nim-lang/RFCs/issues/294 + type Koo = enum k1, k2 + type Goo = enum g1, g2 + + accept: Koo(k2) + accept: k2.Koo + accept: k2.int.Goo + + reject: Goo(k2) + reject: k2.Goo + reject: k2.string + + {.push warningAsError[EnumConv]:off.} + discard Goo(k2) + accept: Goo(k2) + accept: k2.Goo + reject: k2.string + {.pop.} + + reject: Goo(k2) + reject: k2.Goo + + type KooRange = range[k2..k2] + accept: KooRange(k2) + accept: k2.KooRange + let k2ranged: KooRange = k2 + accept: Koo(k2ranged) + accept: k2ranged.Koo + +reject: + # bug #18550 + proc f(c: char): cstring = + var x = newString(109*1024*1024) + x[0] = c + x + +{.push warning[AnyEnumConv]:on, warningAsError[AnyEnumConv]:on.} + +reject: + type + Foo = enum + one + three + + var va = 2 + var vb = va.Foo + +{.pop.} + +{.push warningAsError[HoleEnumConv]:on.} + +reject: + # bug #12815 + type + Hole = enum + one = 1 + three = 3 + + var va = 2 + var vb = va.Hole + +block: # bug #22844 + type + A = enum + a0 = 2 + a1 = 4 + a2 + B[T] = enum + b0 = 2 + b1 = 4 + + doAssert A.toSeq == [a0, a1, a2] + doAssert B[float].toSeq == [B[float].b0, B[float].b1] + +{.pop.} diff --git a/tests/misc/tcsharpusingstatement.nim b/tests/misc/tcsharpusingstatement.nim new file mode 100644 index 000000000..1ce553895 --- /dev/null +++ b/tests/misc/tcsharpusingstatement.nim @@ -0,0 +1,76 @@ +discard """ + output: "Using test.Closing test." +""" + +import + macros + +# This macro mimics the using statement from C# +# +# It's kept only as a test for the macro system +# Nim's destructors offer a mechanism for automatic +# disposal of resources. +# +macro autoClose(args: varargs[untyped]): untyped = + let e = callsite() + if e.len != 3: + error "Using statement: unexpected number of arguments. Got " & + $e.len & ", expected: 1 or more variable assignments and a block" + + var args = e + var body = e[2] + + var + variables : seq[NimNode] + closingCalls : seq[NimNode] + + newSeq(variables, 0) + newSeq(closingCalls, 0) + + for i in countup(1, args.len-2): + if args[i].kind == nnkExprEqExpr: + var varName = args[i][0] + var varValue = args[i][1] + + var varAssignment = newNimNode(nnkIdentDefs) + varAssignment.add(varName) + varAssignment.add(newNimNode(nnkEmpty)) # empty means no type + varAssignment.add(varValue) + variables.add(varAssignment) + + closingCalls.add(newCall(newIdentNode("close"), varName)) + else: + error "Using statement: Unexpected expression. Got " & + $args[i].kind & " instead of assignment." + + var varSection = newNimNode(nnkVarSection) + varSection.add(variables) + + var finallyBlock = newNimNode(nnkStmtList) + finallyBlock.add(closingCalls) + + result = quote do: + block: + `varSection` + try: + `body` + finally: + `finallyBlock` + +type + TResource* = object + field*: string + +proc openResource(param: string): TResource = + result.field = param + +proc close(r: var TResource) = + write(stdout, "Closing " & r.field & ".") + +proc use(r: var TResource) = + write(stdout, "Using " & r.field & ".") + +autoClose(r = openResource("test")): + use r + +write stdout, "\n" diff --git a/tests/misc/tdefine.nim b/tests/misc/tdefine.nim index f1c6e7a96..f3fa4711f 100644 --- a/tests/misc/tdefine.nim +++ b/tests/misc/tdefine.nim @@ -1,12 +1,23 @@ discard """ joinable: false -cmd: "nim c -d:booldef -d:booldef2=false -d:intdef=2 -d:strdef=foobar -r $file" +cmd: "nim c $options -d:booldef -d:booldef2=false -d:intdef=2 -d:strdef=foobar -d:namespaced.define=false -d:double.namespaced.define -r $file" +matrix: "; -d:useGenericDefine" """ -const booldef {.booldefine.} = false -const booldef2 {.booldefine.} = true -const intdef {.intdefine.} = 0 -const strdef {.strdefine.} = "" +when defined(useGenericDefine): + {.pragma: booldefine2, define.} + {.pragma: intdefine2, define.} + {.pragma: strdefine2, define.} +else: + + {.pragma: booldefine2, booldefine.} + {.pragma: intdefine2, intdefine.} + {.pragma: strdefine2, strdefine.} + +const booldef {.booldefine2.} = false +const booldef2 {.booldefine2.} = true +const intdef {.intdefine2.} = 0 +const strdef {.strdefine2.} = "" doAssert defined(booldef) doAssert defined(booldef2) @@ -17,14 +28,50 @@ doAssert not booldef2 doAssert intdef == 2 doAssert strdef == "foobar" +when defined(useGenericDefine): + block: + const uintdef {.define: "intdef".}: uint = 17 + doAssert intdef == int(uintdef) + const cstrdef {.define: "strdef".}: cstring = "not strdef" + doAssert $cstrdef == strdef + type FooBar = enum foo, bar, foobar + const enumdef {.define: "strdef".} = foo + doAssert $enumdef == strdef + doAssert enumdef == foobar + # Intentionally not defined from command line -const booldef3 {.booldefine.} = true -const intdef2 {.intdefine.} = 1 -const strdef2 {.strdefine.} = "abc" +const booldef3 {.booldefine2.} = true +const intdef2 {.intdefine2.} = 1 +const strdef2 {.strdefine2.} = "abc" type T = object - when booldef3: - field1: int - when intdef2 == 1: - field2: int - when strdef2 == "abc": - field3: int \ No newline at end of file + when booldef3: + field1: int + when intdef2 == 1: + field2: int + when strdef2 == "abc": + field3: int + +doAssert not defined(booldef3) +doAssert not defined(intdef2) +doAssert not defined(strdef2) +discard T(field1: 1, field2: 2, field3: 3) + +doAssert defined(namespaced.define) +const `namespaced.define` {.booldefine2.} = true +doAssert not `namespaced.define` +when defined(useGenericDefine): + const aliasToNamespacedDefine {.define: "namespaced.define".} = not `namespaced.define` +else: + const aliasToNamespacedDefine {.booldefine: "namespaced.define".} = not `namespaced.define` +doAssert aliasToNamespacedDefine == `namespaced.define` + +doAssert defined(double.namespaced.define) +const `double.namespaced.define` {.booldefine2.} = false +doAssert `double.namespaced.define` +when defined(useGenericDefine): + const aliasToDoubleNamespacedDefine {.define: "double.namespaced.define".} = not `double.namespaced.define` +else: + const aliasToDoubleNamespacedDefine {.booldefine: "double.namespaced.define".} = not `double.namespaced.define` +doAssert aliasToDoubleNamespacedDefine == `double.namespaced.define` + +doAssert not defined(namespaced.butnotdefined) diff --git a/tests/misc/temit.nim b/tests/misc/temit.nim deleted file mode 100644 index ee7455d4c..000000000 --- a/tests/misc/temit.nim +++ /dev/null @@ -1,15 +0,0 @@ -discard """ - output: "509" -""" -# Test the new ``emit`` pragma: - -{.emit: """ -static int cvariable = 420; - -""".} - -proc embedsC() = - var nimVar = 89 - {.emit: """printf("%d\n", cvariable + (int)`nimVar`);""".} - -embedsC() diff --git a/tests/misc/temptyecho.nim b/tests/misc/temptyecho.nim deleted file mode 100644 index a3c407897..000000000 --- a/tests/misc/temptyecho.nim +++ /dev/null @@ -1,6 +0,0 @@ -discard """ -output: "\n" -""" - -echo() - diff --git a/tests/misc/tevents.nim b/tests/misc/tevents.nim deleted file mode 100644 index 045c9fc5b..000000000 --- a/tests/misc/tevents.nim +++ /dev/null @@ -1,48 +0,0 @@ -discard """ -output: ''' -HandlePrintEvent: Output -> Handled print event -HandlePrintEvent2: Output -> printing for ME -HandlePrintEvent2: Output -> printing for ME -''' -""" - -import events - -type - PrintEventArgs = object of EventArgs - user*: string - -proc handleprintevent*(e: EventArgs) = - write(stdout, "HandlePrintEvent: Output -> Handled print event\n") - -proc handleprintevent2*(e: EventArgs) = - var args: PrintEventArgs = PrintEventArgs(e) - write(stdout, "HandlePrintEvent2: Output -> printing for " & args.user) - -var ee = initEventEmitter() - -var eventargs: PrintEventArgs -eventargs.user = "ME\n" - -##method one test - -ee.on("print", handleprintevent) -ee.on("print", handleprintevent2) - -ee.emit("print", eventargs) - -##method two test - -type - SomeObject = object of RootObj - printEvent: EventHandler - -var obj: SomeObject -obj.printEvent = initEventHandler("print") -obj.printEvent.addHandler(handleprintevent2) - -ee.emit(obj.printEvent, eventargs) - -obj.printEvent.removeHandler(handleprintevent2) - -ee.emit(obj.printEvent, eventargs) diff --git a/tests/misc/tgcregions.nim b/tests/misc/tgcregions.nim deleted file mode 100644 index e14865be3..000000000 --- a/tests/misc/tgcregions.nim +++ /dev/null @@ -1,6 +0,0 @@ -discard """ -cmd: "nim c --gc:regions $file" -""" - -# issue #12597 -# it just tests that --gc:regions compiles. Nothing else. :'( diff --git a/tests/misc/tgenconstraints.nim b/tests/misc/tgenconstraints.nim deleted file mode 100644 index 829da5173..000000000 --- a/tests/misc/tgenconstraints.nim +++ /dev/null @@ -1,31 +0,0 @@ -discard """ - errormsg: "cannot instantiate T2" - file: "tgenconstraints.nim" - line: 25 - disabled: true -""" - -type - T1[T: int|string] = object - x: T - - T2[T: Ordinal] = object - x: T - -var x1: T1[int] -var x2: T1[string] -var x3: T2[int] - -proc foo[T](x: T): T2[T] {.discardable.} = - var o: T1[T] - -foo(10) - -# XXX: allow type intersections in situation like this -proc bar(x: int|TNumber): T1[type(x)] {.discardable.} = - when type(x) is TNumber: - var o: T2[type(x)] - -bar "test" -bar 100 -bar 1.1 diff --git a/tests/misc/theaproots.nim b/tests/misc/theaproots.nim index 1ea3c86b9..2dd345254 100644 --- a/tests/misc/theaproots.nim +++ b/tests/misc/theaproots.nim @@ -28,7 +28,7 @@ proc acc(x: var Foo): var ref Bar = proc test(maybeFoo: var Foo, maybeSeq: var seq[ref Bar], - bars: var openarray[ref Bar], + bars: var openArray[ref Bar], maybeTup: var Tup) = var bb: ref Bar maybeFoo.rmaybe = bb diff --git a/tests/misc/tidentconcatenations.nim b/tests/misc/tidentconcatenations.nim deleted file mode 100644 index ddd2e49cc..000000000 --- a/tests/misc/tidentconcatenations.nim +++ /dev/null @@ -1,31 +0,0 @@ -type - Hash*[bits: static[int]] = object - data*: array[bits div 8, uint8] - -{.emit: """ - -void sha_256(void* input, int input_len, void* output, int output_len) {} -void sha_512(void* input, int input_len, void* output, int output_len) {} - -void keccak_256(void* input, int input_len, void* output, int output_len) {} -void keccak_512(void* input, int input_len, void* output, int output_len) {} - -""".} - -template defineKeccak(bits: untyped) = - proc `extKeccak bits`(output: pointer, outSize: csize_t, input: pointer, inputSize: csize_t) {.nodecl, importc: "keccak_" & astToStr(bits).} - -template defineSha(bits: static[int]) = - proc `extSha bits`(output: pointer, outSize: csize_t, input: pointer, inputSize: csize_t) {.nodecl, importc: "sha_" & astToStr(bits).} - -template defineHashProcs(bits) = - defineSha(bits) - defineKeccak(bits) - -defineHashProcs(256) -defineHashProcs(512) - -extSha256(nil, 0, nil, 0) -extSha512(nil, 0, nil, 0) -extKeccak256(nil, 0, nil, 0) -extKeccak512(nil, 0, nil, 0) diff --git a/tests/misc/tinc.nim b/tests/misc/tinc.nim deleted file mode 100644 index 91f6223e2..000000000 --- a/tests/misc/tinc.nim +++ /dev/null @@ -1,8 +0,0 @@ -discard """ - errormsg: "type mismatch: got <int>" - file: "tinc.nim" - line: 8 -""" -var x = 0 - -inc(x+1) diff --git a/tests/misc/tints.nim b/tests/misc/tints.nim deleted file mode 100644 index d24cbd4ac..000000000 --- a/tests/misc/tints.nim +++ /dev/null @@ -1,85 +0,0 @@ -discard """ - output: ''' -0 0 -0 0 -Success''' -""" -# Test the different integer operations - -var testNumber = 0 - -template test(opr, a, b, c: untyped): untyped = - # test the expression at compile and runtime - block: - const constExpr = opr(a, b) - when constExpr != c: - {.error: "Test failed " & $constExpr & " " & $c.} - inc(testNumber) - #Echo("Test: " & $testNumber) - var aa = a - var bb = b - var varExpr = opr(aa, bb) - assert(varExpr == c) - -test(`+`, 12'i8, -13'i16, -1'i16) -test(`shl`, 0b11, 0b100, 0b110000) -when not defined(js): - test(`shl`, 0b11'i32, 0b100'i64, 0b110000'i64) -test(`shl`, 0b11'i32, 0b100'i32, 0b110000'i32) - -test(`or`, 0xf0f0'i16, 0x0d0d'i16, 0xfdfd'i16) -test(`and`, 0xf0f0'i16, 0xfdfd'i16, 0xf0f0'i16) - -when not defined(js): - test(`shr`, 0xffffffffffffffff'i64, 0x4'i64, 0xffffffffffffffff'i64) -test(`shr`, 0xffff'i16, 0x4'i16, 0xffff'i16) -test(`shr`, 0xff'i8, 0x4'i8, 0xff'i8) - -when not defined(js): - test(`shr`, 0xffffffff'i64, 0x4'i64, 0x0fffffff'i64) -test(`shr`, 0xffffffff'i32, 0x4'i32, 0xffffffff'i32) - -when not defined(js): - test(`shl`, 0xffffffffffffffff'i64, 0x4'i64, 0xfffffffffffffff0'i64) -test(`shl`, 0xffff'i16, 0x4'i16, 0xfff0'i16) -test(`shl`, 0xff'i8, 0x4'i8, 0xf0'i8) - -when not defined(js): - test(`shl`, 0xffffffff'i64, 0x4'i64, 0xffffffff0'i64) -test(`shl`, 0xffffffff'i32, 0x4'i32, 0xfffffff0'i32) - -# bug #916 -proc unc(a: float): float = - return a - -echo int(unc(0.5)), " ", int(unc(-0.5)) -echo int(0.5), " ", int(-0.5) - -block: # Casts to uint - template testCast(fromValue: typed, toType: typed, expectedResult: typed) = - let src = fromValue - let dst = cast[toType](src) - if dst != expectedResult: - echo "Casting ", astToStr(fromValue), " to ", astToStr(toType), " = ", dst.int, " instead of ", astToStr(expectedResult) - doAssert(dst == expectedResult) - - testCast(-1'i16, uint16, 0xffff'u16) - testCast(0xffff'u16, int16, -1'i16) - - testCast(0xff'u16, uint8, 0xff'u8) - testCast(0xffff'u16, uint8, 0xff'u8) - - testCast(-1'i16, uint32, 0xffffffff'u32) - testCast(0xffffffff'u32, int32, -1) - - testCast(0xfffffffe'u32, int32, -2'i32) - testCast(0xffffff'u32, int16, -1'i32) - - testCast(-5'i32, uint8, 251'u8) - -# issue #7174 -let c = 1'u -let val = c > 0 -doAssert val - -echo("Success") #OUT Success diff --git a/tests/misc/tinvalidarrayaccess.nim b/tests/misc/tinvalidarrayaccess.nim deleted file mode 100644 index f8bce45ef..000000000 --- a/tests/misc/tinvalidarrayaccess.nim +++ /dev/null @@ -1,21 +0,0 @@ -discard """ - errormsg: "index 2 not in 0 .. 1" - line: 18 -""" -block: - try: - let a = @[1,2] - echo a[3] - except Exception as e: - doAssert e.msg == "index 3 not in 0 .. 1" - # note: this is not being tested, because the CT error happens before - -block: - type TTestArr = array[0..1, int16] - var f: TTestArr - f[0] = 30 - f[1] = 40 - f[2] = 50 - f[3] = 60 - - echo(repr(f)) diff --git a/tests/misc/tinvalidarrayaccess2.nim b/tests/misc/tinvalidarrayaccess2.nim deleted file mode 100644 index 0a0703834..000000000 --- a/tests/misc/tinvalidarrayaccess2.nim +++ /dev/null @@ -1,10 +0,0 @@ -discard """ - errormsg: "index 3 not in 0 .. 1" - line: 9 -""" - -# Note: merge in tinvalidarrayaccess.nim pending https://github.com/nim-lang/Nim/issues/9906 - -let a = [1,2] -echo a[3] - diff --git a/tests/misc/tinvalidnewseq.nim b/tests/misc/tinvalidnewseq.nim index dec00fd4a..7a95db020 100644 --- a/tests/misc/tinvalidnewseq.nim +++ b/tests/misc/tinvalidnewseq.nim @@ -13,7 +13,7 @@ proc parseURL(url: string): TURL = var pattern: string = r"([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?" var m: array[0..6, string] #Array with the matches newSeq(m, 7) #ERROR - discard regexprs.match(url, re(pattern), m) + discard re.match(url, re(pattern), m) result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4], port: m[5], path: m[6].split('/')) diff --git a/tests/misc/tjoinable.nim b/tests/misc/tjoinable.nim new file mode 100644 index 000000000..f23fca0d4 --- /dev/null +++ b/tests/misc/tjoinable.nim @@ -0,0 +1,3 @@ +# checks that megatest allows duplicate names, see also `tests/testament/tjoinable.nim` +doAssert defined(testing) +doAssert defined(nimMegatest) diff --git a/tests/misc/tlambdadonotation.nim b/tests/misc/tlambdadonotation.nim deleted file mode 100644 index af51efdbf..000000000 --- a/tests/misc/tlambdadonotation.nim +++ /dev/null @@ -1,78 +0,0 @@ -discard """ -output: ''' -issue #11812 -issue #10899 -123 -issue #11367 -event consumed! -''' -""" - -echo "issue #11812" - -proc run(a: proc()) = a() - -proc main() = - var test: int - run(proc() = test = 0) - run do: - test = 0 - -main() - - -echo "issue #10899" - -proc foo(x: proc {.closure.}) = - x() - -proc bar = - var x = 123 - # foo proc = echo x #[ ok ]# - foo: echo x #[ SIGSEGV: Illegal storage access. (Attempt to read from nil?) ]# - -bar() - -echo "issue #11367" - -type - - EventCB = proc() - - Emitter = object - cb: EventCB - - Subscriber = object - discard - -proc newEmitter(): Emitter = - result - -proc on_event(self: var Emitter, cb: EventCB) = - self.cb = cb - -proc emit(self: Emitter) = - self.cb() - -proc newSubscriber(): Subscriber = - result - -proc consume(self: Subscriber) = - echo "event consumed!" - -proc main2() = - var emitter = newEmitter() - var subscriber = newSubscriber() - - proc foo() = - subscriber.consume() - - emitter.on_event() do: - subscriber.consume() - - # this works - # emitter.on_event(foo) - - emitter.emit() - -main2() diff --git a/tests/misc/tlocals.nim b/tests/misc/tlocals.nim deleted file mode 100644 index a6df68224..000000000 --- a/tests/misc/tlocals.nim +++ /dev/null @@ -1,75 +0,0 @@ -discard """ - 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/misc/tlowhigh.nim b/tests/misc/tlowhigh.nim deleted file mode 100644 index 6ae871255..000000000 --- a/tests/misc/tlowhigh.nim +++ /dev/null @@ -1,32 +0,0 @@ -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/misc/tnew.nim b/tests/misc/tnew.nim deleted file mode 100644 index 2d9a64461..000000000 --- a/tests/misc/tnew.nim +++ /dev/null @@ -1,57 +0,0 @@ -discard """ -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 = - 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/misc/tnewderef.nim b/tests/misc/tnewderef.nim deleted file mode 100644 index 3394dbddf..000000000 --- a/tests/misc/tnewderef.nim +++ /dev/null @@ -1,11 +0,0 @@ -discard """ - output: 3 - -""" - -var x: ref int -new(x) -x[] = 3 - -echo x[] - diff --git a/tests/misc/tnewsets.nim b/tests/misc/tnewsets.nim deleted file mode 100644 index f239d4aa2..000000000 --- a/tests/misc/tnewsets.nim +++ /dev/null @@ -1,6 +0,0 @@ -# new test for sets: - -const elem = ' ' - -var s: set[char] = {elem} -assert(elem in s and 'a' not_in s and 'c' not_in s ) diff --git a/tests/misc/tnoinst.nim b/tests/misc/tnoinst.nim deleted file mode 100644 index 85db1e8e7..000000000 --- a/tests/misc/tnoinst.nim +++ /dev/null @@ -1,16 +0,0 @@ -discard """ - errormsg: "instantiate 'notConcrete' explicitly" - line: 12 - disabled: "true" -""" - -proc wrap[T]() = - proc notConcrete[T](x, y: int): int = - var dummy: T - result = x - y - - var x: proc (x, y: T): int - x = notConcrete - - -wrap[int]() diff --git a/tests/misc/tnoop.nim b/tests/misc/tnoop.nim deleted file mode 100644 index 7f5bb1045..000000000 --- a/tests/misc/tnoop.nim +++ /dev/null @@ -1,13 +0,0 @@ -discard """ - nimout: ''' - found 'a' [var declared in tnoop.nim(11, 3)] - ''' - file: "tnoop.nim" - line: 13 - errormsg: "attempting to call routine: 'a'" -""" - -var - a: int - -a() diff --git a/tests/misc/tnot.nim b/tests/misc/tnot.nim deleted file mode 100644 index a3669705b..000000000 --- a/tests/misc/tnot.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ - errormsg: "type mismatch" - file: "tnot.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/misc/tparamsindefault.nim b/tests/misc/tparamsindefault.nim deleted file mode 100644 index 3fe917f2b..000000000 --- a/tests/misc/tparamsindefault.nim +++ /dev/null @@ -1,120 +0,0 @@ -discard """ -output: ''' -@[1, 2, 3]@[1, 2, 3] -a -a -1 -3 is an int -2 is an int -miau is a string -f1 1 1 1 -f1 2 3 3 -f1 10 20 30 -f2 100 100 100 -f2 200 300 300 -f2 300 400 400 -f3 10 10 20 -f3 10 15 25 -true true -false true -world -typedescDefault -''' -""" - -template reject(x) = - assert(not compiles(x)) - -block: - # https://github.com/nim-lang/Nim/issues/7756 - proc foo[T](x: seq[T], y: seq[T] = x) = - echo x, y - - let a = @[1, 2, 3] - foo(a) - -block: - # https://github.com/nim-lang/Nim/issues/1201 - proc issue1201(x: char|int = 'a') = echo x - - issue1201() - issue1201('a') - issue1201(1) - - # https://github.com/nim-lang/Nim/issues/7000 - proc test(a: int|string = 2) = - when a is int: - echo a, " is an int" - elif a is string: - echo a, " is a string" - - test(3) # works - test() # works - test("miau") - -block: - # https://github.com/nim-lang/Nim/issues/3002 and similar - proc f1(a: int, b = a, c = b) = - echo "f1 ", a, " ", b, " ", c - - proc f2(a: int, b = a, c: int = b) = - echo "f2 ", a, " ", b, " ", c - - proc f3(a: int, b = a, c = a + b) = - echo "f3 ", a, " ", b, " ", c - - f1 1 - f1(2, 3) - f1 10, 20, 30 - 100.f2 - 200.f2 300 - 300.f2(400) - - 10.f3() - 10.f3(15) - - reject: - # This is a type mismatch error: - proc f4(a: int, b = a, c: float = b) = discard - - reject: - # undeclared identifier - proc f5(a: int, b = c, c = 10) = discard - - reject: - # undeclared identifier - proc f6(a: int, b = b) = discard - - reject: - # undeclared identifier - proc f7(a = a) = discard - -block: - proc f(a: var int, b: ptr int, c = addr(a)) = - echo addr(a) == b, " ", b == c - - var x = 10 - f(x, addr(x)) - f(x, nil, nil) - -block: - # https://github.com/nim-lang/Nim/issues/1046 - proc pySubstr(s: string, start: int, endd = s.len()): string = - var - revStart = start - revEnd = endd - - if start < 0: - revStart = s.len() + start - if endd < 0: - revEnd = s.len() + endd - - return s[revStart .. revEnd-1] - - echo pySubstr("Hello world", -5) - - -# bug #11660 - -func typedescDefault(T: typedesc; arg: T = 0) = debugEcho "typedescDefault" -typedescDefault(int) diff --git a/tests/misc/tproveinit.nim b/tests/misc/tproveinit.nim deleted file mode 100644 index c9f688309..000000000 --- a/tests/misc/tproveinit.nim +++ /dev/null @@ -1,18 +0,0 @@ -discard """ - joinable: false -""" - -{.warningAsError[ProveInit]:on.} -template main() = - proc fn(): var int = - discard - discard fn() -doAssert not compiles(main()) - -# bug #9901 -import std/[sequtils, times] -proc parseMyDates(line: string): DateTime = - result = parse(line, "yyyy-MM-dd") -var dateStrings = @["2018-12-01", "2018-12-02", "2018-12-03"] -var parsed = dateStrings.map(parseMyDates) -discard parsed diff --git a/tests/misc/tradix.nim b/tests/misc/tradix.nim index 1773a9609..f4fb56849 100644 --- a/tests/misc/tradix.nim +++ b/tests/misc/tradix.nim @@ -40,8 +40,8 @@ type TRadixNode {.pure, inheritable.} = object kind: TRadixNodeKind TRadixNodeLinear = object of TRadixNode - len: int8 - keys: array[0..31, int8] + len: uint8 + keys: array[0..31, uint8] vals: array[0..31, PRadixNode] TRadixNodeFull = object of TRadixNode @@ -49,8 +49,8 @@ type TRadixNodeLeafBits = object of TRadixNode b: array[0..7, int] TRadixNodeLeafLinear = object of TRadixNode - len: int8 - keys: array[0..31, int8] + len: uint8 + keys: array[0..31, uint8] var root: PRadixNode @@ -59,8 +59,8 @@ proc searchInner(r: PRadixNode, a: int): PRadixNode = case r.kind of rnLinear: var x = cast[ptr TRadixNodeLinear](r) - for i in 0..ze(x.len)-1: - if ze(x.keys[i]) == a: return x.vals[i] + for i in 0..int(x.len)-1: + if int(x.keys[i]) == a: return x.vals[i] of rnFull: var x = cast[ptr TRadixNodeFull](r) return x.b[a] @@ -87,8 +87,8 @@ proc searchLeaf(r: PRadixNode, a: int): bool = return testBit(x.b[a /% BitsPerUnit], a) of rnLeafLinear: var x = cast[ptr TRadixNodeLeafLinear](r) - for i in 0..ze(x.len)-1: - if ze(x.keys[i]) == a: return true + for i in 0..int(x.len)-1: + if int(x.keys[i]) == a: return true else: assert(false) proc exclLeaf(r: PRadixNode, a: int) = @@ -98,9 +98,9 @@ proc exclLeaf(r: PRadixNode, a: int) = resetBit(x.b[a /% BitsPerUnit], a) of rnLeafLinear: var x = cast[ptr TRadixNodeLeafLinear](r) - var L = ze(x.len) + var L = int(x.len) for i in 0..L-1: - if ze(x.keys[i]) == a: + if int(x.keys[i]) == a: x.keys[i] = x.keys[L-1] dec(x.len) return @@ -131,8 +131,8 @@ proc addLeaf(r: var PRadixNode, a: int): bool = # a linear node: var x = cast[ptr TRadixNodeLinear](alloc0(sizeof(TRadixNodeLinear))) x.kind = rnLeafLinear - x.len = 1'i8 - x.keys[0] = toU8(a) + x.len = 1'u8 + x.keys[0] = uint8(a) r = x return false # not already in set case r.kind @@ -141,18 +141,18 @@ proc addLeaf(r: var PRadixNode, a: int): bool = return testOrSetBit(x.b[a /% BitsPerUnit], a) of rnLeafLinear: var x = cast[ptr TRadixNodeLeafLinear](r) - var L = ze(x.len) + var L = int(x.len) for i in 0..L-1: - if ze(x.keys[i]) == a: return true + if int(x.keys[i]) == a: return true if L <= high(x.keys): - x.keys[L] = toU8(a) + x.keys[L] = uint8(a) inc(x.len) else: # transform into a full node: var y = cast[ptr TRadixNodeLeafBits](alloc0(sizeof(TRadixNodeLeafBits))) y.kind = rnLeafBits - for i in 0..ze(x.len)-1: - var u = ze(x.keys[i]) + for i in 0..int(x.len)-1: + var u = int(x.keys[i]) setBit(y.b[u /% BitsPerUnit], u) setBit(y.b[a /% BitsPerUnit], a) dealloc(r) @@ -167,26 +167,26 @@ proc addInner(r: var PRadixNode, a: int, d: int): bool = # a linear node: var x = cast[ptr TRadixNodeLinear](alloc0(sizeof(TRadixNodeLinear))) x.kind = rnLinear - x.len = 1'i8 - x.keys[0] = toU8(k) + x.len = 1'u8 + x.keys[0] = uint8(k) r = x return addInner(x.vals[0], a, d-8) case r.kind of rnLinear: var x = cast[ptr TRadixNodeLinear](r) - var L = ze(x.len) + var L = int(x.len) for i in 0..L-1: - if ze(x.keys[i]) == k: # already exists + if int(x.keys[i]) == k: # already exists return addInner(x.vals[i], a, d-8) if L <= high(x.keys): - x.keys[L] = toU8(k) + x.keys[L] = uint8(k) inc(x.len) return addInner(x.vals[L], a, d-8) else: # transform into a full node: var y = cast[ptr TRadixNodeFull](alloc0(sizeof(TRadixNodeFull))) y.kind = rnFull - for i in 0..L-1: y.b[ze(x.keys[i])] = x.vals[i] + for i in 0..L-1: y.b[int(x.keys[i])] = x.vals[i] dealloc(r) r = y return addInner(y.b[k], a, d-8) @@ -211,8 +211,8 @@ iterator innerElements(r: PRadixNode): tuple[prefix: int, n: PRadixNode] = yield (i, r.b[i]) of rnLinear: var r = cast[ptr TRadixNodeLinear](r) - for i in 0..ze(r.len)-1: - yield (ze(r.keys[i]), r.vals[i]) + for i in 0..int(r.len)-1: + yield (int(r.keys[i]), r.vals[i]) else: assert(false) iterator leafElements(r: PRadixNode): int = @@ -228,8 +228,8 @@ iterator leafElements(r: PRadixNode): int = yield i*BitsPerUnit+j of rnLeafLinear: var r = cast[ptr TRadixNodeLeafLinear](r) - for i in 0..ze(r.len)-1: - yield ze(r.keys[i]) + for i in 0..int(r.len)-1: + yield int(r.keys[i]) else: assert(false) iterator elements*(r: PRadixNode): ByteAddress {.inline.} = diff --git a/tests/misc/trangechecks.nim b/tests/misc/trangechecks.nim deleted file mode 100644 index e48b1272b..000000000 --- a/tests/misc/trangechecks.nim +++ /dev/null @@ -1,48 +0,0 @@ -discard """ - output: '''10 -10 -1 -1 -true''' -""" - -# bug #1344 - -var expected: int -var x: range[1..10] = 10 - -try: - x += 1 - echo x -except OverflowDefect, RangeDefect: - expected += 1 - echo x - -try: - inc x - echo x -except OverflowDefect, RangeDefect: - expected += 1 - echo x - -x = 1 -try: - x -= 1 - echo x -except OverflowDefect, RangeDefect: - expected += 1 - echo x - -try: - dec x - echo x -except OverflowDefect, RangeDefect: - expected += 1 - echo x - -echo expected == 4 - -# bug #13698 -var - x45 = "hello".cstring - p = x45.len.int32 diff --git a/tests/misc/trawstr.nim b/tests/misc/trawstr.nim deleted file mode 100644 index aa41071d5..000000000 --- a/tests/misc/trawstr.nim +++ /dev/null @@ -1,10 +0,0 @@ -discard """ - errormsg: "closing \" expected" - file: "trawstr.nim" - line: 10 -""" -# Test the new raw strings: - -const - xxx = r"This is a raw string!" - yyy = "This not\" #ERROR diff --git a/tests/misc/treadln.nim b/tests/misc/treadln.nim deleted file mode 100644 index b716c4711..000000000 --- a/tests/misc/treadln.nim +++ /dev/null @@ -1,21 +0,0 @@ - -discard """ -output: ''' -test the improved readline handling that does not care whether its -Macintosh, Unix or Windows text format. -''' -""" - -# test the improved readline handling that does not care whether its -# Macintosh, Unix or Windows text format. - -var - inp: File - line: string - -if open(inp, "tests/misc/treadln.nim"): - while not endOfFile(inp): - line = readLine(inp) - if line.len >= 2 and line[0] == '#' and line[1] == ' ': - echo line[2..^1] - close(inp) diff --git a/tests/misc/treservedcidentsasfields.nim b/tests/misc/treservedcidentsasfields.nim deleted file mode 100644 index a9a954651..000000000 --- a/tests/misc/treservedcidentsasfields.nim +++ /dev/null @@ -1,39 +0,0 @@ -discard """ - targets: "c cpp" -""" - -import macros - -macro make_test_type(idents: varargs[untyped]): untyped = - result = nnkStmtList.newTree() - - var ident_defs: seq[NimNode] = @[] - for i in idents: - ident_defs.add newIdentDefs(i, ident("int")) - - result.add newTree(nnkTypeSection, - newTree(nnkTypeDef, - ident("TestType"), - newEmptyNode(), - newTree(nnkObjectTy, - newEmptyNode(), - newEmptyNode(), - newTree(nnkRecList, - ident_defs - ) - ) - ) - ) - -make_test_type( - auto, bool, catch, char, class, compl, const_cast, default, delete, double, - dynamic_cast, explicit, extern, false, float, friend, goto, int, long, - mutable, namespace, new, operator, private, protected, public, register, - reinterpret_cast, restrict, short, signed, sizeof, static_cast, struct, switch, - this, throw, true, typedef, typeid, typeof, typename, union, packed, unsigned, - virtual, void, volatile, wchar_t, alignas, alignof, constexpr, decltype, nullptr, - noexcept, thread_local, static_assert, char16_t, char32_t -) - -# Make sure the type makes it to codegen. -var test_instance: TestType diff --git a/tests/misc/trfc405.nim b/tests/misc/trfc405.nim new file mode 100644 index 000000000..0828879ee --- /dev/null +++ b/tests/misc/trfc405.nim @@ -0,0 +1,112 @@ + +{.experimental: "flexibleOptionalParams".} + +# https://github.com/nim-lang/RFCs/issues/405 + +template main = + template fn1(a = 1, b = 2, body): auto = (a, b, astToStr(body)) + let a1 = fn1(10, 20): + foo + doAssert a1 == (10, 20, "\nfoo") + + template fn2(a = 1, b = 2, body): auto = (a, b, astToStr(body)) + let a2 = fn2(a = 10): foo + doAssert a2 == (10, 2, "\nfoo") + let a2b = fn2(b = 20): foo + doAssert a2b == (1, 20, "\nfoo") + + template fn3(x: int, a = 1, b = 2, body): auto = (a, b, astToStr(body)) + let a3 = fn3(3, 10, 20): foo + doAssert a3 == (10, 20, "\nfoo") + let a3b = fn3(3, a = 10): foo + doAssert a3b == (10, 2, "\nfoo") + + template fn4(x: int, y: int, body): auto = (x, y, astToStr(body)) + let a4 = fn4(1, 2): foo + doAssert a4 == (1, 2, "\nfoo") + + template fn5(x = 1, y = 2, body: untyped = 3): auto = (x, y, astToStr(body)) + doAssert compiles(fn5(1, 2, foo)) + doAssert not compiles(fn5(1, foo)) + + block: + # with an overload + var witness = 0 + template fn6() = discard + template fn6(procname: string, body: untyped): untyped = witness.inc + fn6("abc"): discard + assert witness == 1 + + block: + # with overloads + var witness = 0 + template fn6() = discard + template fn6(a: int) = discard + template fn6(procname: string, body: untyped): untyped = witness.inc + fn6("abc"): discard + assert witness == 1 + + template fn6(b = 1.5, body: untyped): untyped = witness.inc + fn6(1.3): discard + assert witness == 2 + + block: + var witness = 0 + template fn6(a: int) = discard + template fn6(a: string) = discard + template fn6(ignore: string, b = 1.5, body: untyped): untyped = witness.inc + fn6(""): + foobar1 + foobar2 + doAssert witness == 1 + fn6(""): discard + doAssert witness == 2 + + block: # multi block args + template fn8(a = 1, b = 2, body1: untyped, body2: untyped): auto = (a, b, astToStr(body1), astToStr(body2)) + let a1 = fn8(): + foobar1 + foobar2 + do: + foobar3 + foobar4 + doAssert a1 == (1, 2, "\nfoobar1\nfoobar2", "\nfoobar3\nfoobar4") + + let a2 = fn8(b = 20): + foobar1 + foobar2 + do: + foobar3 + foobar4 + doAssert a2 == (1, 20, "\nfoobar1\nfoobar2", "\nfoobar3\nfoobar4") + + block: # issue #19015 + template hi(a: untyped, b: varargs[untyped]): untyped = + a + + var worked = false + hi: + worked = true + doAssert worked + worked = false + hi(doAssert(not worked)): + doesntCompile + hi(doAssert(not worked), doesntCompile, againDoesntCompile): + definitelyDoesntCompile + + template hi2(a: bool, b: untyped, c: varargs[untyped]): untyped = + b + doAssert a + + hi2 worked: + worked = true + doAssert worked + hi2 worked, doAssert(worked): + doesntCompile + hi2 worked, doAssert(worked), doesntCompile, againDoesntCompile: + definitelyDoesntCompile + hi2 worked, doAssert(worked), againDoesntCompile: + definitelyDoesntCompile + +static: main() +main() diff --git a/tests/misc/trunner.nim b/tests/misc/trunner.nim index a66177f28..6e5487d1b 100644 --- a/tests/misc/trunner.nim +++ b/tests/misc/trunner.nim @@ -6,6 +6,8 @@ discard """ ## tests that don't quite fit the mold and are easier to handle via `execCmdEx` ## A few others could be added to here to simplify code. ## Note: this test is a bit slow but tests a lot of things; please don't disable. +## Note: if needed, we could use `matrix: "-d:case1; -d:case2"` to split this +## into several independent tests while retaining the common test helpers. import std/[strformat,os,osproc,unittest,compilesettings] from std/sequtils import toSeq,mapIt @@ -21,20 +23,29 @@ proc isDots(a: string): bool = a.startsWith(".") and a.strip(chars = {'.'}) == "" const - defaultHintsOff = "--hint:successx:off --hint:exec:off --hint:link:off --hint:cc:off --hint:conf:off --hint:processing:off --hint:QuitCalled:off" - # useful when you want to turn only some hints on, and some common ones off. - # pending https://github.com/timotheecour/Nim/issues/453, simplify to: `--hints:off` nim = getCurrentCompilerExe() mode = querySetting(backend) nimcache = buildDir / "nimcacheTrunner" # instead of `querySetting(nimcacheDir)`, avoids stomping on other parallel tests -proc runCmd(file, options = ""): auto = +proc runNimCmd(file, options = "", rtarg = ""): auto = let fileabs = testsDir / file.unixToNativePath - doAssert fileabs.fileExists, fileabs - let cmd = fmt"{nim} {mode} {options} --hints:off {fileabs}" + # doAssert fileabs.fileExists, fileabs # disabled because this allows passing `nim r --eval:code fakefile` + let cmd = fmt"{nim} {mode} --hint:all:off {options} {fileabs} {rtarg}" result = execCmdEx(cmd) - when false: echo result[0] & "\n" & result[1] # for debugging + when false: # for debugging + echo cmd + echo result[0] & "\n" & $result[1] + +proc runNimCmdChk(file, options = "", rtarg = "", status = 0): string = + let (ret, status2) = runNimCmd(file, options, rtarg = rtarg) + doAssert status2 == status, $(file, options, status, status2) & "\n" & ret + ret + +proc genShellCmd(filename: string): string = + let filename = filename.quoteShell + when defined(windows): "cmd /c " & filename # or "cmd /c " ? + else: "sh " & filename when defined(nimTrunnerFfi): block: # mevalffi @@ -53,8 +64,8 @@ when defined(nimTrunnerFfi): hello world stderr hi stderr """ - let (output, exitCode) = runCmd("vm/mevalffi.nim", fmt"{opt} --experimental:compiletimeFFI") - let expected = fmt""" + let output = runNimCmdChk("vm/mevalffi.nim", fmt"{opt} --warnings:off --experimental:compiletimeFFI") + doAssert output == fmt""" {prefix}foo foo:100 foo:101 @@ -62,12 +73,13 @@ foo:102:103 foo:102:103:104 foo:0.03:asdf:103:105 ret=[s1:foobar s2:foobar age:25 pi:3.14] -""" - doAssert output == expected, output - doAssert exitCode == 0 +""", output -else: # don't run twice the same test - import std/[strutils] +elif not defined(nimTestsTrunnerDebugging): + # don't run twice the same test with `nimTrunnerFfi` + # use `-d:nimTestsTrunnerDebugging` for debugging convenience when you want to just run 1 test + import std/strutils + import std/json template check2(msg) = doAssert msg in output, output block: # tests with various options `nim doc --project --index --docroot` @@ -92,7 +104,7 @@ else: # don't run twice the same test of 5: nimcache / htmldocsDirname else: file.parentDir / htmldocsDirname - var cmd = fmt"{nim} doc --index:on --listFullPaths --hint:successX:on --nimcache:{nimcache} {options[i]} {file}" + var cmd = fmt"{nim} doc --index:on --filenames:abs --hint:successX:on --nimcache:{nimcache} {options[i]} {file}" removeDir(htmldocsDir) let (outp, exitCode) = execCmdEx(cmd) check exitCode == 0 @@ -142,17 +154,16 @@ sub/mmain.idx""", context else: doAssert false block: # mstatic_assert - let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad") + let (output, exitCode) = runNimCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad") check2 "sizeof(bool) == 2" check exitCode != 0 block: # ABI checks let file = "misc/msizeof5.nim" block: - let (output, exitCode) = runCmd(file, "-d:checkAbi") - doAssert exitCode == 0, output + discard runNimCmdChk(file, "-d:checkAbi") block: - let (output, exitCode) = runCmd(file, "-d:checkAbi -d:caseBad") + let (output, exitCode) = runNimCmd(file, "-d:checkAbi -d:caseBad") # on platforms that support _StaticAssert natively, errors will show full context, e.g.: # error: static_assert failed due to requirement 'sizeof(unsigned char) == 8' # "backend & Nim disagree on size for: BadImportcType{int64} [declared in mabi_check.nim(1, 6)]" @@ -205,6 +216,41 @@ sub/mmain.idx""", context let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}" check execCmdEx(cmd) == ("ok3\n", 0) + block: # nim jsondoc # bug #20132 + let file = testsDir / "misc/mjsondoc.nim" + let output = "nimcache_tjsondoc.json" + defer: removeFile(output) + let (msg, exitCode) = execCmdEx(fmt"{nim} jsondoc -o:{output} {file}") + doAssert exitCode == 0, msg + + let data = parseJson(readFile(output))["entries"] + doAssert data.len == 5 + let doSomething = data[0] + doAssert doSomething["name"].getStr == "doSomething" + doAssert doSomething["type"].getStr == "skProc" + doAssert doSomething["line"].getInt == 1 + doAssert doSomething["col"].getInt == 0 + doAssert doSomething["code"].getStr == "proc doSomething(x, y: int): int {.raises: [], tags: [], forbids: [].}" + let foo2 = data[4] + doAssert $foo2["signature"] == """{"arguments":[{"name":"x","type":"T"},{"name":"y","type":"U"},{"name":"z","type":"M"}],"genericParams":[{"name":"T","types":"int"},{"name":"M","types":"string"},{"name":"U"}]}""" + + block: # nim jsondoc # bug #11953 + let file = testsDir / "misc/mjsondoc.nim" + let destDir = testsDir / "misc/htmldocs" + removeDir(destDir) + defer: removeDir(destDir) + let (msg, exitCode) = execCmdEx(fmt"{nim} jsondoc {file}") + doAssert exitCode == 0, msg + + let data = parseJson(readFile(destDir / "mjsondoc.json"))["entries"] + doAssert data.len == 5 + let doSomething = data[0] + doAssert doSomething["name"].getStr == "doSomething" + doAssert doSomething["type"].getStr == "skProc" + doAssert doSomething["line"].getInt == 1 + doAssert doSomething["col"].getInt == 0 + doAssert doSomething["code"].getStr == "proc doSomething(x, y: int): int {.raises: [], tags: [], forbids: [].}" + block: # further issues with `--backend` let file = testsDir / "misc/mbackend.nim" var cmd = fmt"{nim} doc -b:cpp --hints:off --nimcache:{nimcache} {file}" @@ -221,8 +267,23 @@ sub/mmain.idx""", context let cmd = fmt"{nim} r -b:cpp --hints:off --nimcache:{nimcache} --warningAsError:ProveInit {file}" check execCmdEx(cmd) == ("witness\n", 0) + block: # bug #20149 + let file = testsDir / "misc/m20149.nim" + let cmd = fmt"{nim} r --hints:off --nimcache:{nimcache} --hintAsError:XDeclaredButNotUsed {file}" + check execCmdEx(cmd) == ("12\n", 0) + + block: # bug #15316 + when not defined(windows): + # This never worked reliably on Windows. Needs further investigation but it is hard to reproduce. + # Looks like a mild stack corruption when bailing out of nested exception handling. + let file = testsDir / "misc/m15316.nim" + let cmd = fmt"{nim} check --hints:off --nimcache:{nimcache} {file}" + check execCmdEx(cmd) == ("m15316.nim(1, 15) Error: expression expected, but found \')\'\nm15316.nim(2, 1) Error: expected: \':\', but got: \'[EOF]\'\nm15316.nim(2, 1) Error: expression expected, but found \'[EOF]\'\nm15316.nim(2, 1) " & + "Error: expected: \')\', but got: \'[EOF]\'\nError: illformed AST: \n", 1) + + block: # config.nims, nim.cfg, hintConf, bug #16557 - let cmd = fmt"{nim} r {defaultHintsOff} --hint:conf tests/newconfig/bar/mfoo.nim" + let cmd = fmt"{nim} r --hint:all:off --hint:conf tests/newconfig/bar/mfoo.nim" let (outp, exitCode) = execCmdEx(cmd, options = {poStdErrToStdOut}) doAssert exitCode == 0 let dir = getCurrentDir() @@ -238,6 +299,20 @@ tests/newconfig/bar/mfoo.nims""".splitLines expected.add &"Hint: used config file '{b}' [Conf]\n" doAssert outp.endsWith expected, outp & "\n" & expected + block: # bug #8219 + let file = "tests/newconfig/mconfigcheck.nims" + let cmd = fmt"{nim} check --hints:off {file}" + check execCmdEx(cmd) == ("", 0) + + block: # mfoo2.customext + let filename = testsDir / "newconfig/foo2/mfoo2.customext" + let cmd = fmt"{nim} e --hint:conf {filename}" + let (outp, exitCode) = execCmdEx(cmd, options = {poStdErrToStdOut}) + doAssert exitCode == 0 + var expected = &"Hint: used config file '{filename}' [Conf]\n" + doAssert outp.endsWith "123" & "\n" & expected + + block: # nim --eval let opt = "--hints:off" check fmt"""{nim} {opt} --eval:"echo defined(nimscript)"""".execCmdEx == ("true\n", 0) @@ -245,7 +320,7 @@ tests/newconfig/bar/mfoo.nims""".splitLines check fmt"""{nim} r -b:js {opt} --eval:"echo defined(js)"""".execCmdEx == ("true\n", 0) block: # `hintProcessing` dots should not interfere with `static: echo` + friends - let cmd = fmt"""{nim} r {defaultHintsOff} --hint:processing -f --eval:"static: echo 1+1"""" + let cmd = fmt"""{nim} r --hint:all:off --hint:processing -f --eval:"static: echo 1+1"""" let (outp, exitCode) = execCmdEx(cmd, options = {poStdErrToStdOut}) template check3(cond) = doAssert cond, $(outp,) doAssert exitCode == 0 @@ -259,7 +334,7 @@ tests/newconfig/bar/mfoo.nims""".splitLines check3 "2" in outp block: # nim secret - let opt = fmt"{defaultHintsOff} --hint:processing" + let opt = "--hint:all:off --hint:processing" template check3(cond) = doAssert cond, $(outp,) for extra in ["", "--stdout"]: let cmd = fmt"""{nim} secret {opt} {extra}""" @@ -272,8 +347,8 @@ tests/newconfig/bar/mfoo.nims""".splitLines when not defined(windows): check3 lines.len == 5 check3 lines[0].isDots - check3 lines[1].dup(removePrefix(">>> ")) == "3" # prompt depends on `nimUseLinenoise` - check3 lines[2].isDots + # check3 lines[1].isDots # todo nim secret might use parsing pipeline + check3 lines[2].dup(removePrefix(">>> ")) == "3" # prompt depends on `nimUseLinenoise` check3 lines[3] == "ab" check3 lines[4] == "" else: @@ -284,3 +359,86 @@ tests/newconfig/bar/mfoo.nims""".splitLines let (outp, exitCode) = run "echo 1+2; quit(2)" check3 "3" in outp doAssert exitCode == 2 + + block: # nimBetterRun + let file = "misc/mbetterrun.nim" + const nimcache2 = buildDir / "D20210423T185116" + removeDir nimcache2 + # related to `-d:nimBetterRun` + let opt = fmt"-r --usenimcache --nimcache:{nimcache2}" + var ret = "" + for a in @["v1", "v2", "v1", "v3"]: + ret.add runNimCmdChk(file, fmt"{opt} -d:mbetterrunVal:{a}") + ret.add runNimCmdChk(file, fmt"{opt} -d:mbetterrunVal:v2", rtarg = "arg1 arg2") + # rt arguments should not cause a recompilation + doAssert ret == """ +compiling: v1 +running: v1 +compiling: v2 +running: v2 +running: v1 +compiling: v3 +running: v3 +running: v2 +""", ret + + block: # nim dump + let cmd = fmt"{nim} dump --dump.format:json -d:D20210428T161003 --hints:off ." + let (ret, status) = execCmdEx(cmd) + doAssert status == 0 + let j = ret.parseJson + # sanity checks + doAssert "D20210428T161003" in j["defined_symbols"].to(seq[string]) + doAssert j["version"].to(string) == NimVersion + doAssert j["nimExe"].to(string) == getCurrentCompilerExe() + + block: # genscript + const nimcache2 = buildDir / "D20210524T212851" + removeDir(nimcache2) + let input = "tgenscript_fakefile" # no need for a real file, --eval is good enough + let output = runNimCmdChk(input, fmt"""--genscript --nimcache:{nimcache2.quoteShell} --eval:"echo(12345)" """) + doAssert output.len == 0, output + let ext = when defined(windows): ".bat" else: ".sh" + let filename = fmt"compile_{input}{ext}" # synchronize with `generateScript` + doAssert fileExists(nimcache2/filename), nimcache2/filename + let (outp, status) = execCmdEx(genShellCmd(filename), options = {poStdErrToStdOut}, workingDir = nimcache2) + doAssert status == 0, outp + let (outp2, status2) = execCmdEx(nimcache2 / input, options = {poStdErrToStdOut}) + doAssert outp2 == "12345\n", outp2 + doAssert status2 == 0 + + block: # UnusedImport + proc fn(opt: string, expected: string) = + let output = runNimCmdChk("msgs/mused3.nim", fmt"--warning:all:off --warning:UnusedImport --hint:DuplicateModuleImport {opt}") + doAssert output == expected, opt & "\noutput:\n" & output & "expected:\n" & expected + fn("-d:case1"): """ +mused3.nim(13, 8) Warning: imported and not used: 'mused3b' [UnusedImport] +""" + fn("-d:case2"): "" + fn("-d:case3"): "" + fn("-d:case4"): "" + fn("-d:case5"): "" + fn("-d:case6"): "" + fn("-d:case7"): "" + fn("-d:case8"): "" + fn("-d:case9"): "" + fn("-d:case10"): "" + when false: + fn("-d:case11"): """ + Warning: imported and not used: 'm2' [UnusedImport] + """ + fn("-d:case12"): """ +mused3.nim(75, 10) Hint: duplicate import of 'mused3a'; previous import here: mused3.nim(74, 10) [DuplicateModuleImport] +""" + + block: # FieldDefect + proc fn(opt: string, expected: string) = + let output = runNimCmdChk("misc/mfield_defect.nim", fmt"-r --warning:all:off --declaredlocs {opt}", status = 1) + doAssert expected in output, opt & "\noutput:\n" & output & "expected:\n" & expected + fn("-d:case1"): """mfield_defect.nim(25, 15) Error: field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'""" + fn("-d:case2 --gc:refc"): """mfield_defect.nim(25, 15) field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'""" + fn("-d:case1 -b:js"): """mfield_defect.nim(25, 15) Error: field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'""" + fn("-d:case2 -b:js"): """field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'""" + fn("-d:case2 --gc:arc"): """mfield_defect.nim(25, 15) field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'""" +else: + discard # only during debugging, tests added here will run with `-d:nimTestsTrunnerDebugging` enabled diff --git a/tests/misc/trunner_special.nim b/tests/misc/trunner_special.nim index 47ba44a29..e08b419b0 100644 --- a/tests/misc/trunner_special.nim +++ b/tests/misc/trunner_special.nim @@ -1,6 +1,7 @@ discard """ targets: "c cpp" joinable: false + disabled: osx """ #[ @@ -13,6 +14,10 @@ xxx test all tests/untestable/* here, possibly with adjustments to make running import std/[strformat,os,unittest,compilesettings] import stdtest/specialpaths + +from stdtest/testutils import disableSSLTesting + + const nim = getCurrentCompilerExe() mode = querySetting(backend) @@ -26,6 +31,7 @@ proc main = block: # SSL nimDisableCertificateValidation integration tests runCmd fmt"{nim} r {options} -d:nimDisableCertificateValidation -d:ssl {testsDir}/untestable/thttpclient_ssl_disabled.nim" block: # SSL certificate check integration tests - runCmd fmt"{nim} r {options} -d:ssl --threads:on {testsDir}/untestable/thttpclient_ssl_remotenetwork.nim" + runCmd fmt"{nim} r {options} -d:ssl --threads:on --mm:refc {testsDir}/untestable/thttpclient_ssl_remotenetwork.nim" -main() +when not disableSSLTesting(): + main() diff --git a/tests/misc/tsimplesort.nim b/tests/misc/tsimplesort.nim index e4a8e0b37..395db55e6 100644 --- a/tests/misc/tsimplesort.nim +++ b/tests/misc/tsimplesort.nim @@ -10,7 +10,7 @@ type TSlotEnum = enum seEmpty, seFilled, seDeleted TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B] TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]] - TTable* {.final, myShallow.}[A, B] = object + TTable*[A, B] {.final, myShallow.} = object data: TKeyValuePairSeq[A, B] counter: int @@ -112,7 +112,7 @@ proc initTable*[A, B](initialSize=64): TTable[A, B] = result.counter = 0 newSeq(result.data, initialSize) -proc toTable*[A, B](pairs: openarray[tuple[key: A, +proc toTable*[A, B](pairs: openArray[tuple[key: A, val: B]]): TTable[A, B] = ## creates a new hash table that contains the given `pairs`. result = initTable[A, B](nextPowerOfTwo(pairs.len+10)) @@ -137,8 +137,7 @@ proc `$`*[A, B](t: TTable[A, B]): string = # ------------------------------ count tables ------------------------------- type - TCountTable* {.final, myShallow.}[ - A] = object ## table that counts the number of each key + TCountTable*[A] {.final, myShallow.} = object ## table that counts the number of each key data: seq[tuple[key: A, val: int]] counter: int diff --git a/tests/misc/tsimtych.nim b/tests/misc/tsimtych.nim deleted file mode 100644 index 74a6ad4c0..000000000 --- a/tests/misc/tsimtych.nim +++ /dev/null @@ -1,10 +0,0 @@ -discard """ - errormsg: "type mismatch: got <bool> but expected \'string\'" - file: "tsimtych.nim" - line: 10 -""" -# Test 2 -# Simple type checking - -var a: string -a = false #ERROR diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index 0d96a5e04..ce5334664 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -732,3 +732,11 @@ type doAssert sizeof(PackedUnion) == 11 doAssert alignof(PackedUnion) == 1 + +# bug #22553 +type + ChunkObj = object + data: UncheckedArray[byte] + +doAssert sizeof(ChunkObj) == 1 +doAssert offsetOf(ChunkObj, data) == 1 diff --git a/tests/misc/tsizeof3.nim b/tests/misc/tsizeof3.nim index 1215b4bcd..f0ba8c4d0 100644 --- a/tests/misc/tsizeof3.nim +++ b/tests/misc/tsizeof3.nim @@ -27,3 +27,32 @@ type static: doAssert(compiles(offsetOf(Payload, vals))) + + +type + GoodboySave* {.bycopy.} = object + saveCount: uint8 + savePoint: uint16 + shards: uint32 + friendCount: uint8 + friendCards: set[0..255] + locationsKnown: set[0..127] + locationsUnlocked: set[0..127] + pickupsObtained: set[0..127] + pickupsUsed: set[0..127] + pickupCount: uint8 + +block: # bug #20914 + block: + proc csizeof[T](a: T): int {.importc:"sizeof", nodecl.} + + var s: GoodboySave + doAssert sizeof(s) == 108 + doAssert csizeof(s) == static(sizeof(s)) + + block: + proc calignof[T](a: T): int {.importc:"alignof", header: "<stdalign.h>".} + + var s: set[0..256] + doAssert alignof(s) == 1 + doAssert calignof(s) == static(alignof(s)) diff --git a/tests/misc/tslices.nim b/tests/misc/tslices.nim deleted file mode 100644 index d063c5ebf..000000000 --- a/tests/misc/tslices.nim +++ /dev/null @@ -1,58 +0,0 @@ -discard """ -output: ''' -456456 -456456 -456456 -Zugr5nd -egerichtetd -verichtetd -''' -""" - -# Test the new slices. - -import strutils - -var mystr = "Abgrund" -mystr[..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] - -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" - -echo mystr - -mystr[0..2] = "ve" -echo mystr - -var s = "abcdef" -s[1 .. ^2] = "xyz" -assert s == "axyzf" diff --git a/tests/misc/tspellsuggest.nim b/tests/misc/tspellsuggest.nim deleted file mode 100644 index 033ed0afc..000000000 --- a/tests/misc/tspellsuggest.nim +++ /dev/null @@ -1,45 +0,0 @@ -discard """ - # pending bug #16521 (bug 12) use `matrix` - cmd: "nim c --spellsuggest:15 --hints:off $file" - action: "reject" - nimout: ''' -tspellsuggest.nim(45, 13) Error: undeclared identifier: 'fooBar' -candidates (edit distance, scope distance); see '--spellSuggest': - (1, 0): 'fooBar8' [var declared in tspellsuggest.nim(43, 9)] - (1, 1): 'fooBar7' [var declared in tspellsuggest.nim(41, 7)] - (1, 3): 'fooBar1' [var declared in tspellsuggest.nim(33, 5)] - (1, 3): 'fooBar2' [let declared in tspellsuggest.nim(34, 5)] - (1, 3): 'fooBar3' [const declared in tspellsuggest.nim(35, 7)] - (1, 3): 'fooBar4' [proc declared in tspellsuggest.nim(36, 6)] - (1, 3): 'fooBar5' [template declared in tspellsuggest.nim(37, 10)] - (1, 3): 'fooBar6' [macro declared in tspellsuggest.nim(38, 7)] - (1, 5): 'FooBar' [type declared in mspellsuggest.nim(5, 6)] - (1, 5): 'fooBar4' [proc declared in mspellsuggest.nim(1, 6)] - (1, 5): 'fooBar9' [var declared in mspellsuggest.nim(2, 5)] - (1, 5): 'fooCar' [var declared in mspellsuggest.nim(4, 5)] - (2, 5): 'FooCar' [type declared in mspellsuggest.nim(6, 6)] - (2, 5): 'GooBa' [type declared in mspellsuggest.nim(7, 6)] - (3, 0): 'fooBarBaz' [const declared in tspellsuggest.nim(44, 11)] -''' -""" - -# tests `--spellsuggest:num` - - - -# line 30 -import ./mspellsuggest - -var fooBar1 = 0 -let fooBar2 = 0 -const fooBar3 = 0 -proc fooBar4() = discard -template fooBar5() = discard -macro fooBar6() = discard - -proc main = - var fooBar7 = 0 - block: - var fooBar8 = 0 - const fooBarBaz = 0 - let x = fooBar diff --git a/tests/misc/tspellsuggest2.nim b/tests/misc/tspellsuggest2.nim deleted file mode 100644 index 78504c513..000000000 --- a/tests/misc/tspellsuggest2.nim +++ /dev/null @@ -1,45 +0,0 @@ -discard """ - # pending bug #16521 (bug 12) use `matrix` - cmd: "nim c --spellsuggest --hints:off $file" - action: "reject" - nimout: ''' -tspellsuggest2.nim(45, 13) Error: undeclared identifier: 'fooBar' -candidates (edit distance, scope distance); see '--spellSuggest': - (1, 0): 'fooBar8' [var declared in tspellsuggest2.nim(43, 9)] - (1, 1): 'fooBar7' [var declared in tspellsuggest2.nim(41, 7)] - (1, 3): 'fooBar1' [var declared in tspellsuggest2.nim(33, 5)] - (1, 3): 'fooBar2' [let declared in tspellsuggest2.nim(34, 5)] - (1, 3): 'fooBar3' [const declared in tspellsuggest2.nim(35, 7)] - (1, 3): 'fooBar4' [proc declared in tspellsuggest2.nim(36, 6)] - (1, 3): 'fooBar5' [template declared in tspellsuggest2.nim(37, 10)] - (1, 3): 'fooBar6' [macro declared in tspellsuggest2.nim(38, 7)] - (1, 5): 'FooBar' [type declared in mspellsuggest.nim(5, 6)] - (1, 5): 'fooBar4' [proc declared in mspellsuggest.nim(1, 6)] - (1, 5): 'fooBar9' [var declared in mspellsuggest.nim(2, 5)] - (1, 5): 'fooCar' [var declared in mspellsuggest.nim(4, 5)] -''' -""" - -# tests `--spellsuggest` - - - - - - -# line 30 -import ./mspellsuggest - -var fooBar1 = 0 -let fooBar2 = 0 -const fooBar3 = 0 -proc fooBar4() = discard -template fooBar5() = discard -macro fooBar6() = discard - -proc main = - var fooBar7 = 0 - block: - var fooBar8 = 0 - const fooBarBaz = 0 - let x = fooBar diff --git a/tests/misc/tstrtabs.nim b/tests/misc/tstrtabs.nim deleted file mode 100644 index 2f7eda9f7..000000000 --- a/tests/misc/tstrtabs.nim +++ /dev/null @@ -1,20 +0,0 @@ -discard """ - targets: "c cpp js" -""" - -import std/strtabs - -proc fun()= - let ret = newStringTable(modeCaseSensitive) - ret["foo"] = "bar" - - doAssert $ret == "{foo: bar}" - - let b = ret["foo"] - doAssert b == "bar" - -proc main()= - static: fun() - fun() - -main() diff --git a/tests/misc/ttlsemulation.nim b/tests/misc/ttlsemulation.nim index 47c5934e6..767a9bd4e 100644 --- a/tests/misc/ttlsemulation.nim +++ b/tests/misc/ttlsemulation.nim @@ -1,4 +1,5 @@ discard """ + disabled: i386 matrix: "-d:nimTtlsemulationCase1 --threads --tlsEmulation:on; -d:nimTtlsemulationCase2 --threads --tlsEmulation:off; -d:nimTtlsemulationCase3 --threads" targets: "c cpp" """ diff --git a/tests/misc/tunsigned64mod.nim b/tests/misc/tunsigned64mod.nim deleted file mode 100644 index ca3286df3..000000000 --- a/tests/misc/tunsigned64mod.nim +++ /dev/null @@ -1,24 +0,0 @@ - -# bug #1638 - -let v1 = 7 -let v2 = 7'u64 - -let t1 = v1 mod 2 # works -let t2 = 7'u64 mod 2'u64 # works -let t3 = v2 mod 2'u64 # Error: invalid type: 'range 0..1(uint64) -let t4 = (v2 mod 2'u64).uint64 # works - -# bug #2550 - -var x: uint # doesn't work -doAssert x mod 2 == 0 - -var y: uint64 # doesn't work -doAssert y mod 2 == 0 - -var z: uint32 # works -doAssert z mod 2 == 0 - -var a: int # works -doAssert a mod 2 == 0 diff --git a/tests/misc/tunsignedcmp.nim b/tests/misc/tunsignedcmp.nim deleted file mode 100644 index 11b67ac5f..000000000 --- a/tests/misc/tunsignedcmp.nim +++ /dev/null @@ -1,43 +0,0 @@ -discard """ - output: '''true -true -true -5 -4 -3 -2 -1 -0 -it should stop now -18446744073709551615 -4294967295 -''' -""" - -# bug 1420 -var x = 40'u32 -var y = 30'u32 -echo x > y # works - -echo((40'i32) > (30'i32)) -echo((40'u32) > (30'u32)) # Error: ordinal type expected - -# bug #4220 - -const count: uint = 5 -var stop_me = false - -for i in countdown(count, 0): - echo i - if stop_me: break - if i == 0: - echo "it should stop now" - stop_me = true - -# bug #3985 -const - HIGHEST_64BIT_UINT = 0xFFFFFFFFFFFFFFFF'u - HIGHEST_32BIT_UINT = 0xFFFFFFFF'u - -echo($HIGHEST_64BIT_UINT) -echo($HIGHEST_32BIT_UINT) diff --git a/tests/misc/tunsignedcomp.nim b/tests/misc/tunsignedcomp.nim deleted file mode 100644 index 970c4ae9d..000000000 --- a/tests/misc/tunsignedcomp.nim +++ /dev/null @@ -1,136 +0,0 @@ -discard """ - output: '''''' - disabled: "true" -""" - -# All operations involving uint64 are commented out -# as they're not yet supported. -# All other operations are handled by implicit conversions from uints to ints -# uint64 could be supported but would need special implementation of the operators - -# unsigned < signed - -doAssert 10'u8 < 20'i8 -doAssert 10'u8 < 20'i16 -doAssert 10'u8 < 20'i32 -doAssert 10'u8 < 20'i64 - -doAssert 10'u16 < 20'i8 -doAssert 10'u16 < 20'i16 -doAssert 10'u16 < 20'i32 -doAssert 10'u16 < 20'i64 - -doAssert 10'u32 < 20'i8 -doAssert 10'u32 < 20'i16 -doAssert 10'u32 < 20'i32 -doAssert 10'u32 < 20'i64 - -# doAssert 10'u64 < 20'i8 -# doAssert 10'u64 < 20'i16 -# doAssert 10'u64 < 20'i32 -# doAssert 10'u64 < 20'i64 - -# signed < unsigned -doAssert 10'i8 < 20'u8 -doAssert 10'i8 < 20'u16 -doAssert 10'i8 < 20'u32 -# doAssert 10'i8 < 20'u64 - -doAssert 10'i16 < 20'u8 -doAssert 10'i16 < 20'u16 -doAssert 10'i16 < 20'u32 -# doAssert 10'i16 < 20'u64 - -doAssert 10'i32 < 20'u8 -doAssert 10'i32 < 20'u16 -doAssert 10'i32 < 20'u32 -# doAssert 10'i32 < 20'u64 - -doAssert 10'i64 < 20'u8 -doAssert 10'i64 < 20'u16 -doAssert 10'i64 < 20'u32 -# doAssert 10'i64 < 20'u64 - -# unsigned <= signed -doAssert 10'u8 <= 20'i8 -doAssert 10'u8 <= 20'i16 -doAssert 10'u8 <= 20'i32 -doAssert 10'u8 <= 20'i64 - -doAssert 10'u16 <= 20'i8 -doAssert 10'u16 <= 20'i16 -doAssert 10'u16 <= 20'i32 -doAssert 10'u16 <= 20'i64 - -doAssert 10'u32 <= 20'i8 -doAssert 10'u32 <= 20'i16 -doAssert 10'u32 <= 20'i32 -doAssert 10'u32 <= 20'i64 - -# doAssert 10'u64 <= 20'i8 -# doAssert 10'u64 <= 20'i16 -# doAssert 10'u64 <= 20'i32 -# doAssert 10'u64 <= 20'i64 - -# signed <= unsigned -doAssert 10'i8 <= 20'u8 -doAssert 10'i8 <= 20'u16 -doAssert 10'i8 <= 20'u32 -# doAssert 10'i8 <= 20'u64 - -doAssert 10'i16 <= 20'u8 -doAssert 10'i16 <= 20'u16 -doAssert 10'i16 <= 20'u32 -# doAssert 10'i16 <= 20'u64 - -doAssert 10'i32 <= 20'u8 -doAssert 10'i32 <= 20'u16 -doAssert 10'i32 <= 20'u32 -# doAssert 10'i32 <= 20'u64 - -doAssert 10'i64 <= 20'u8 -doAssert 10'i64 <= 20'u16 -doAssert 10'i64 <= 20'u32 -# doAssert 10'i64 <= 20'u64 - -# signed == unsigned -doAssert 10'i8 == 10'u8 -doAssert 10'i8 == 10'u16 -doAssert 10'i8 == 10'u32 -# doAssert 10'i8 == 10'u64 - -doAssert 10'i16 == 10'u8 -doAssert 10'i16 == 10'u16 -doAssert 10'i16 == 10'u32 -# doAssert 10'i16 == 10'u64 - -doAssert 10'i32 == 10'u8 -doAssert 10'i32 == 10'u16 -doAssert 10'i32 == 10'u32 -# doAssert 10'i32 == 10'u64 - -doAssert 10'i64 == 10'u8 -doAssert 10'i64 == 10'u16 -doAssert 10'i64 == 10'u32 -# doAssert 10'i64 == 10'u64 - -# unsigned == signed -doAssert 10'u8 == 10'i8 -doAssert 10'u8 == 10'i16 -doAssert 10'u8 == 10'i32 -# doAssert 10'u8 == 10'i64 - -doAssert 10'u16 == 10'i8 -doAssert 10'u16 == 10'i16 -doAssert 10'u16 == 10'i32 -# doAssert 10'u16 == 10'i64 - -doAssert 10'u32 == 10'i8 -doAssert 10'u32 == 10'i16 -doAssert 10'u32 == 10'i32 -# doAssert 10'u32 == 10'i64 - -# doAssert 10'u64 == 10'i8 -# doAssert 10'u64 == 10'i16 -# doAssert 10'u64 == 10'i32 -# doAssert 10'u64 == 10'i64 diff --git a/tests/misc/tunsignedconv.nim b/tests/misc/tunsignedconv.nim deleted file mode 100644 index b9463b5f0..000000000 --- a/tests/misc/tunsignedconv.nim +++ /dev/null @@ -1,81 +0,0 @@ -# Tests unsigned literals and implicit conversion between uints and ints - -var h8:uint8 = 128 -var h16:uint16 = 32768 -var h32:uint32 = 2147483648'u32 -var h64:uint64 = 9223372036854775808'u64 -var foobar:uint64 = 9223372036854775813'u64 # Issue 728 - -var v8:uint8 = 10 -var v16:uint16 = 10 -var v32:uint32 = 10 -var v64:uint64 = 10 - -# u8 + literal produces u8: -var a8: uint8 = v8 + 10 -var a16: uint16 = v16 + 10 - -when false: - var d8 = v8 + 10'i8 - var d16 = v8 + 10'i16 - var d32 = v8 + 10'i32 - -when false: - # these don't work yet because unsigned.nim is stupid. XXX We need to fix this. - var f8 = v16 + 10'u8 - var f16 = v16 + 10'u16 - var f32 = v16 + 10'u32 - - var g8 = v32 + 10'u8 - var g16 = v32 + 10'u16 - var g32 = v32 + 10'u32 - -var ar: array[0..20, int] -var n8 = ar[v8] -var n16 = ar[v16] -var n32 = ar[v32] -var n64 = ar[v64] - - -block t4176: - var yyy: uint8 = 0 - yyy = yyy - 127 - doAssert type(yyy) is uint8 - -# bug #13661 - -proc fun(): uint = cast[uint](-1) -const x0 = fun() - -doAssert typeof(x0) is uint - -discard $x0 - -# bug #13671 - -const x1 = cast[uint](-1) -discard $(x1,) - -# bug #13698 -let n: csize = 1 # xxx should that be csize_t or is that essential here? -doAssert $n.int32 == "1" - -# bug #14616 - -let limit = 1'u64 - -let rangeVar = 0'u64 ..< limit - -doAssert repr(rangeVar) == """[a = 0, -b = 0]""" - -# bug #15210 - -let a3 = not 0'u64 -var success = false -try: - discard a3.int64 -except RangeDefect: - success = true - -doAssert success, "conversion should fail at runtime" diff --git a/tests/misc/tunsignedinc.nim b/tests/misc/tunsignedinc.nim deleted file mode 100644 index 9d1a4bbb4..000000000 --- a/tests/misc/tunsignedinc.nim +++ /dev/null @@ -1,34 +0,0 @@ - -block: # bug #2427 - var x = 0'u8 - dec x # OverflowDefect - x -= 1 # OverflowDefect - x = x - 1 # No error - - doAssert(x == 253'u8) - -block: - var x = 130'u8 - x += 130'u8 - doAssert(x == 4'u8) - -block: - var x = 40000'u16 - x = x + 40000'u16 - doAssert(x == 14464'u16) - -block: - var x = 4000000000'u32 - x = x + 4000000000'u32 - doAssert(x == 3705032704'u32) - -block: - var x = 123'u16 - x -= 125 - doAssert(x == 65534'u16) - -block t4175: - let i = 0u - 1u - const j = 0u - 1u - doAssert i == j - doAssert j + 1u == 0u diff --git a/tests/misc/tunsignedmisc.nim b/tests/misc/tunsignedmisc.nim deleted file mode 100644 index b2a3849cf..000000000 --- a/tests/misc/tunsignedmisc.nim +++ /dev/null @@ -1,66 +0,0 @@ -discard """ - errormsg: "number out of range: '0x123'u8'" -""" - -# Bug #1179 - -# Unsigneds - -# 8 bit -let ref1 = 128'u8 shr 7 -let hex1 = 0x80'u8 shr 7 -let oct1 = 0o200'u8 shr 7 -let dig1 = 0b10000000'u8 shr 7 - -doAssert(ref1 == 1) -doAssert(ref1 == hex1) -doAssert(ref1 == oct1) -doAssert(ref1 == dig1) - -# 16 bit -let ref2 = 32768'u16 shr 15 -let hex2 = 0x8000'u16 shr 15 -let oct2 = 0o100000'u16 shr 15 -let dig2 = 0b1000000000000000'u16 shr 15 - -doAssert(ref2 == 1) -doAssert(ref2 == hex2) -doAssert(ref2 == oct2) -doAssert(ref2 == dig2) - -# 32 bit -let ref3 = 2147483648'u32 shr 31 -let hex3 = 0x80000000'u32 shr 31 -let oct3 = 0o20000000000'u32 shr 31 -let dig3 = 0b10000000000000000000000000000000'u32 shr 31 - -doAssert(ref3 == 1) -doAssert(ref3 == hex3) -doAssert(ref3 == oct3) -doAssert(ref3 == dig3) - -# Below doesn't work for lexer stage errors... -# doAssert(compiles(0xFF'u8) == true) -# doAssert(compiles(0xFFF'u16) == true) -# doAssert(compiles(0x7FFF'i16) == true) - -# doAssert(compiles(0x123'u8) == false) -# doAssert(compiles(0x123'i8) == false) -# doAssert(compiles(0x123123'u16) == false) -# doAssert(compiles(0x123123'i16) == false) - -# Should compile # -let boundOkHex1 = 0xFF'u8 -let boundOkHex2 = 0xFFFF'u16 -let boundOkHex3 = 0x7FFF'i16 - -let boundOkHex4 = 0x80'i8 -let boundOkHex5 = 0xFF'i8 -let boundOkHex6 = 0xFFFF'i16 -let boundOkHex7 = 0x7FFF'i16 - -# Should _not_ compile # -let boundBreakingHex1 = 0x123'u8 -let boundBreakingHex2 = 0x123'i8 -let boundBreakingHex3 = 0x123123'u16 -let boundBreakingHex4 = 0x123123'i16 diff --git a/tests/misc/tupcomingfeatures.nim b/tests/misc/tupcomingfeatures.nim deleted file mode 100644 index d37ce85cf..000000000 --- a/tests/misc/tupcomingfeatures.nim +++ /dev/null @@ -1,35 +0,0 @@ -discard """ - output: '''0 -2 0 -0 -2''' -""" - -{.this: self.} - -type - Foo = object - a, b, x: int - -proc yay(self: Foo) = - echo a, " ", b, " ", x - -proc footest[T](self: var Foo, a: T) = - b = 1+a - yay() - -proc nongeneric(self: Foo) = - echo a, " ", b - -var ff: Foo -footest(ff, -3) -ff.nongeneric - -{.experimental.} -using - c: Foo - x, y: int - -proc usesSig(c) = - echo "yummy" - -proc foobar(c, y) = - echo "yay" diff --git a/tests/misc/tvarious1.nim b/tests/misc/tvarious1.nim index 9c0b541db..9c912ee8e 100644 --- a/tests/misc/tvarious1.nim +++ b/tests/misc/tvarious1.nim @@ -46,3 +46,13 @@ echo value var ys = @[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] #var x = int(ys.high / 2) #echo ys[x] # Works echo ys[int(ys.high / 2)] # Doesn't work + + +# bug #19680 +var here = "" +when stderr is static: + doAssert false +else: + here = "works" + +doAssert here == "works" diff --git a/tests/misc/tvarnums.nim b/tests/misc/tvarnums.nim index 2aef242e1..498099c49 100644 --- a/tests/misc/tvarnums.nim +++ b/tests/misc/tvarnums.nim @@ -7,7 +7,7 @@ import strutils type - TBuffer = array[0..10, int8] + TBuffer = array[0..10, uint8] proc toVarNum(x: int32, b: var TBuffer) = # encoding: first bit indicates end of number (0 if at end) @@ -21,11 +21,11 @@ proc toVarNum(x: int32, b: var TBuffer) = # anyway a = abs(x) # first 6 bits: - b[0] = toU8(ord(a >% 63'i32) shl 7 or (ord(x < 0'i32) shl 6) or (int(a) and 63)) + b[0] = uint8(ord(a >% 63'i32) shl 7 or (ord(x < 0'i32) shl 6) or (int(a) and 63)) a = (a shr 6'i32) and 0x03ffffff # skip first 6 bits var i = 1 while a != 0'i32: - b[i] = toU8(ord(a >% 127'i32) shl 7 or (int(a) and 127)) + b[i] = uint8(ord(a >% 127'i32) shl 7 or (int(a) and 127)) inc(i) a = a shr 7'i32 @@ -41,40 +41,40 @@ proc toVarNum64(x: int64, b: var TBuffer) = # anyway a = abs(x) # first 6 bits: - b[0] = toU8(ord(a >% 63'i64) shl 7 or (ord(x < 0'i64) shl 6) or int(a and 63)) + b[0] = uint8(ord(a >% 63'i64) shl 7 or (ord(x < 0'i64) shl 6) or int(a and 63)) a = (a shr 6) and 0x03ffffffffffffff # skip first 6 bits var i = 1 while a != 0'i64: - b[i] = toU8(ord(a >% 127'i64) shl 7 or int(a and 127)) + b[i] = uint8(ord(a >% 127'i64) shl 7 or int(a and 127)) inc(i) a = a shr 7 proc toNum64(b: TBuffer): int64 = # treat first byte different: - result = ze64(b[0]) and 63 + result = int64(b[0]) and 63 var i = 0 Shift = 6'i64 - while (ze(b[i]) and 128) != 0: + while (int(b[i]) and 128) != 0: inc(i) - result = result or ((ze64(b[i]) and 127) shl Shift) + result = result or ((int64(b[i]) and 127) shl Shift) inc(Shift, 7) - if (ze(b[0]) and 64) != 0: # sign bit set? + if (int(b[0]) and 64) != 0: # sign bit set? result = not result +% 1 # this is the same as ``- result`` # but gives no overflow error for low(int) proc toNum(b: TBuffer): int32 = # treat first byte different: - result = int32 ze(b[0]) and 63 + result = int32(b[0]) and 63 var i = 0 Shift = 6'i32 - while (ze(b[i]) and 128) != 0: + while (int(b[i]) and 128) != 0: inc(i) - result = result or ((int32(ze(b[i])) and 127'i32) shl Shift) + result = result or ((int32(b[i]) and 127'i32) shl Shift) Shift = Shift + 7'i32 - if (ze(b[0]) and (1 shl 6)) != 0: # sign bit set? + if (int(b[0]) and (1 shl 6)) != 0: # sign bit set? result = (not result) +% 1'i32 # this is the same as ``- result`` # but gives no overflow error for low(int) diff --git a/tests/misc/tvcc.nim b/tests/misc/tvcc.nim new file mode 100644 index 000000000..10533729c --- /dev/null +++ b/tests/misc/tvcc.nim @@ -0,0 +1,9 @@ +discard """ + matrix: "--cc:vcc" + disabled: "linux" + disabled: "bsd" + disabled: "osx" + disabled: "unix" + disabled: "posix" +""" +doAssert true diff --git a/tests/misc/twarningaserror.nim b/tests/misc/twarningaserror.nim deleted file mode 100644 index 6f7b76095..000000000 --- a/tests/misc/twarningaserror.nim +++ /dev/null @@ -1,35 +0,0 @@ -discard """ - joinable: false -""" - -#[ -tests: hintAsError, warningAsError -]# - -template fn1 = - {.hintAsError[ConvFromXtoItselfNotNeeded]:on.} - proc fn(a: string) = discard a.string - {.hintAsError[ConvFromXtoItselfNotNeeded]:off.} - -template fn2 = - {.hintAsError[ConvFromXtoItselfNotNeeded]:on.} - proc fn(a: string) = discard a - {.hintAsError[ConvFromXtoItselfNotNeeded]:off.} - -template gn1 = - {.warningAsError[ProveInit]:on.} - proc fn(): var int = discard - discard fn() - {.warningAsError[ProveInit]:off.} - -template gn2 = - {.warningAsError[ProveInit]:on.} - proc fn(): int = discard - discard fn() - {.warningAsError[ProveInit]:off.} - -doAssert not compiles(fn1()) -doAssert compiles(fn2()) - -doAssert not compiles(gn1()) -doAssert compiles(gn2()) |