diff options
Diffstat (limited to 'tests/compiler')
-rw-r--r-- | tests/compiler/samplelib.nim | 2 | ||||
-rw-r--r-- | tests/compiler/t12684.nim | 7 | ||||
-rw-r--r-- | tests/compiler/tasm.nim | 15 | ||||
-rw-r--r-- | tests/compiler/tbtrees.nim (renamed from tests/compiler/tbrees.nim) | 2 | ||||
-rw-r--r-- | tests/compiler/tcmdlineclib.nim | 3 | ||||
-rw-r--r-- | tests/compiler/tcmdlineclib.nims | 10 | ||||
-rw-r--r-- | tests/compiler/tdebugutils.nim | 38 | ||||
-rw-r--r-- | tests/compiler/tgrammar.nim | 7 | ||||
-rw-r--r-- | tests/compiler/tnimblecmd.nim | 97 | ||||
-rw-r--r-- | tests/compiler/tprefixmatches.nim | 2 |
10 files changed, 157 insertions, 26 deletions
diff --git a/tests/compiler/samplelib.nim b/tests/compiler/samplelib.nim new file mode 100644 index 000000000..c70971722 --- /dev/null +++ b/tests/compiler/samplelib.nim @@ -0,0 +1,2 @@ +# Sample library used by tcmdlineclib.nim +proc test(): int {.cdecl, exportc, dynlib.} = 123 diff --git a/tests/compiler/t12684.nim b/tests/compiler/t12684.nim new file mode 100644 index 000000000..a5f33d2c9 --- /dev/null +++ b/tests/compiler/t12684.nim @@ -0,0 +1,7 @@ +discard """ + cmd: "nim check --hints:off --warnings:off $file" + errormsg: "undeclared identifier: 'Undeclared'" +""" + +var x: Undeclared +import compiler/nimeval diff --git a/tests/compiler/tasm.nim b/tests/compiler/tasm.nim new file mode 100644 index 000000000..9f60231e0 --- /dev/null +++ b/tests/compiler/tasm.nim @@ -0,0 +1,15 @@ +proc testAsm() = + let src = 41 + var dst = 0 + + asm """ + mov %1, %0\n\t + add $1, %0 + : "=r" (`dst`) + : "r" (`src`)""" + + doAssert dst == 42 + +when defined(gcc) or defined(clang) and not defined(cpp): + {.passc: "-std=c99".} + testAsm() \ No newline at end of file diff --git a/tests/compiler/tbrees.nim b/tests/compiler/tbtrees.nim index 5f6482ed9..973c26420 100644 --- a/tests/compiler/tbrees.nim +++ b/tests/compiler/tbtrees.nim @@ -68,7 +68,7 @@ proc main = when true: var b2 = initBTree[int, string]() var t2 = initTable[int, string]() - const iters = 100_000 + const iters = 100 for i in 1..iters: let x = rand(high(int)) if not t2.hasKey(x): diff --git a/tests/compiler/tcmdlineclib.nim b/tests/compiler/tcmdlineclib.nim new file mode 100644 index 000000000..c06d6f103 --- /dev/null +++ b/tests/compiler/tcmdlineclib.nim @@ -0,0 +1,3 @@ +proc test(): int {.importc, cdecl.} + +doAssert test() == 123 diff --git a/tests/compiler/tcmdlineclib.nims b/tests/compiler/tcmdlineclib.nims new file mode 100644 index 000000000..f7899d92e --- /dev/null +++ b/tests/compiler/tcmdlineclib.nims @@ -0,0 +1,10 @@ +import os + +selfExec "c --app:lib " & (projectDir() / "samplelib.nim") +switch("clibdir", projectDir()) +--clib:samplelib + +# Make test executable can load sample shared library. +# `-rpath` option doesn't work and ignored on Windows. +# But the dll file in same directory as executable file is loaded. +switch("passL", "-Wl,-rpath," & projectDir()) diff --git a/tests/compiler/tdebugutils.nim b/tests/compiler/tdebugutils.nim new file mode 100644 index 000000000..50b15cb78 --- /dev/null +++ b/tests/compiler/tdebugutils.nim @@ -0,0 +1,38 @@ +discard """ + joinable: false + disabled: true +""" + +#[ +This test illustrates some features of `debugutils` to debug the compiler. + +## example +this shows how to enable compiler logging just for a section of user code, +without generating tons of unrelated log messages for code you're not interested +in debugging. + +```sh +# enable some debugging code, e.g. the `when false:` block in `semExpr` +nim c -o:bin/nim_temp --stacktrace -d:debug -d:nimDebugUtils compiler/nim +bin/nim_temp c tests/compiler/tdebugutils.nim +``` + +(use --filenames:abs for abs files) + +## result +("<", "tdebugutils.nim(16, 3)", {.define(nimCompilerDebug).}, nil) +(">", "tdebugutils.nim(17, 3)", let a = 2.5 * 3, {}, nkLetSection) +(">", "tdebugutils.nim(17, 15)", 2.5 * 3, {efAllowDestructor, efWantValue}, nkInfix) +(">", "tdebugutils.nim(17, 11)", 2.5, {efAllowStmt, efDetermineType, efOperand}, nkFloatLit) +("<", "tdebugutils.nim(17, 11)", 2.5, float64) +(">", "tdebugutils.nim(17, 17)", 3, {efAllowStmt, efDetermineType, efOperand}, nkIntLit) +("<", "tdebugutils.nim(17, 17)", 3, int literal(3)) +("<", "tdebugutils.nim(17, 15)", 2.5 * 3, float) +("<", "tdebugutils.nim(17, 3)", let a = 2.5 * 3, nil) +(">", "tdebugutils.nim(18, 3)", {.undef(nimCompilerDebug).}, {}, nkPragma) +]# + +proc main = + {.define(nimCompilerDebug).} + let a = 2.5 * 3 + {.undef(nimCompilerDebug).} diff --git a/tests/compiler/tgrammar.nim b/tests/compiler/tgrammar.nim new file mode 100644 index 000000000..772d0f0cc --- /dev/null +++ b/tests/compiler/tgrammar.nim @@ -0,0 +1,7 @@ +discard """ + matrix: "-d:nimTestGrammar" +""" + +import compiler/parser + +checkSameGrammar() diff --git a/tests/compiler/tnimblecmd.nim b/tests/compiler/tnimblecmd.nim index d39179be1..53bce4625 100644 --- a/tests/compiler/tnimblecmd.nim +++ b/tests/compiler/tnimblecmd.nim @@ -1,26 +1,75 @@ -include compiler/[nimblecmd] +include compiler/[nimblecmd], sets proc v(s: string): Version = s.newVersion -# #head is special in the sense that it's assumed to always be newest. -doAssert v"1.0" < v"#head" -doAssert v"1.0" < v"1.1" -doAssert v"1.0.1" < v"1.1" -doAssert v"1" < v"1.1" -doAssert v"#aaaqwe" < v"1.1" # We cannot assume that a branch is newer. -doAssert v"#a111" < v"#head" - -let conf = newConfigRef() -var rr = newStringTable() -addPackage conf, rr, "irc-#a111", unknownLineInfo -addPackage conf, rr, "irc-#head", unknownLineInfo -addPackage conf, rr, "irc-0.1.0", unknownLineInfo -#addPackage conf, rr, "irc", unknownLineInfo -#addPackage conf, rr, "another", unknownLineInfo -addPackage conf, rr, "another-0.1", unknownLineInfo - -addPackage conf, rr, "ab-0.1.3", unknownLineInfo -addPackage conf, rr, "ab-0.1", unknownLineInfo -addPackage conf, rr, "justone-1.0", unknownLineInfo - -doAssert toSeq(rr.chosen) == - @["irc-#head", "ab-0.1.3", "justone-1.0", "another-0.1"] + +proc testVersionsComparison = + # #head is special in the sense that it's assumed to always be newest. + doAssert v"1.0" < v"#head" + doAssert v"1.0" < v"1.1" + doAssert v"1.0.1" < v"1.1" + doAssert v"1" < v"1.1" + doAssert v"#aaaqwe" < v"1.1" # We cannot assume that a branch is newer. + doAssert v"#a111" < v"#head" + +proc testAddPackageWithoutChecksum = + ## For backward compatibility it is not required all packages to have a + ## sha1 checksum at the end of the name of the Nimble cache directory. + ## This way a new compiler will be able to work with an older Nimble. + + let conf = newConfigRef() + var rr: PackageInfo + + addPackage conf, rr, "irc-#a111", unknownLineInfo + addPackage conf, rr, "irc-#head", unknownLineInfo + addPackage conf, rr, "irc-0.1.0", unknownLineInfo + + addPackage conf, rr, "another-0.1", unknownLineInfo + + addPackage conf, rr, "ab-0.1.3", unknownLineInfo + addPackage conf, rr, "ab-0.1", unknownLineInfo + addPackage conf, rr, "justone-1.0", unknownLineInfo + + doAssert toSeq(rr.chosen).toHashSet == + ["irc-#head", "another-0.1", "ab-0.1.3", "justone-1.0"].toHashSet + +proc testAddPackageWithChecksum = + let conf = newConfigRef() + var rr: PackageInfo + + # in the case of packages with the same version, but different checksums for + # now the first one will be chosen + + addPackage conf, rr, "irc-#a111-DBC1F902CB79946E990E38AF51F0BAD36ACFABD9", + unknownLineInfo + addPackage conf, rr, "irc-#head-042D4BE2B90ED0672E717D71850ABDB0A2D19CD1", + unknownLineInfo + addPackage conf, rr, "irc-#head-042D4BE2B90ED0672E717D71850ABDB0A2D19CD2", + unknownLineInfo + addPackage conf, rr, "irc-0.1.0-6EE6DE936B32E82C7DBE526DA3463574F6568FAF", + unknownLineInfo + + addPackage conf, rr, "another-0.1", unknownLineInfo + addPackage conf, rr, "another-0.1-F07EE6040579F0590608A8FD34F5F2D91D859340", + unknownLineInfo + + addPackage conf, rr, "ab-0.1.3-34BC3B72CE46CF5A496D1121CFEA7369385E9EA2", + unknownLineInfo + addPackage conf, rr, "ab-0.1.3-24BC3B72CE46CF5A496D1121CFEA7369385E9EA2", + unknownLineInfo + addPackage conf, rr, "ab-0.1-A3CFFABDC4759F7779D541F5E031AED17169390A", + unknownLineInfo + + # lower case hex digits is also a valid sha1 checksum + addPackage conf, rr, "justone-1.0-f07ee6040579f0590608a8fd34f5f2d91d859340", + unknownLineInfo + + doAssert toSeq(rr.chosen).toHashSet == [ + "irc-#head-042D4BE2B90ED0672E717D71850ABDB0A2D19CD1", + "another-0.1", + "ab-0.1.3-34BC3B72CE46CF5A496D1121CFEA7369385E9EA2", + "justone-1.0-f07ee6040579f0590608a8fd34f5f2d91d859340" + ].toHashSet + +testVersionsComparison() +testAddPackageWithoutChecksum() +testAddPackageWithChecksum() diff --git a/tests/compiler/tprefixmatches.nim b/tests/compiler/tprefixmatches.nim index a89a6f613..6a3186729 100644 --- a/tests/compiler/tprefixmatches.nim +++ b/tests/compiler/tprefixmatches.nim @@ -5,7 +5,7 @@ macro check(val, body: untyped): untyped = result = newStmtList() expectKind body, nnkStmtList for b in body: - expectKind b, nnkPar + expectKind b, nnkTupleConstr expectLen b, 2 let p = b[0] let s = b[1] |