summary refs log tree commit diff stats
path: root/tests/misc/trunner.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-12-30 05:58:41 -0800
committerGitHub <noreply@github.com>2020-12-30 14:58:41 +0100
commit8508c4e1c262567ecc093de8b645cec677ce5afd (patch)
tree35329fb3dcdf9ce94ff56638d5ac3d9eb55d7d07 /tests/misc/trunner.nim
parent2f4d00fb98beaf6bb2e155e9da7dc7194038b5f3 (diff)
downloadNim-8508c4e1c262567ecc093de8b645cec677ce5afd.tar.gz
fix `hintProcessing` dots interference with `static:echo` and `hintCC`; add tests for `nim secret`, add tests for hintProcessing, misc other bug fixes (#16495)
* fix dots interfering with static:echo
* add tests
* fix hintProcessing dots for hintCC
* improve trunner tests
* fix bug: readLineFromStdin now writes prompt to stdout, consistent with linenoise and rdstdin
* disable a failing test for windows
Diffstat (limited to 'tests/misc/trunner.nim')
-rw-r--r--tests/misc/trunner.nim64
1 files changed, 56 insertions, 8 deletions
diff --git a/tests/misc/trunner.nim b/tests/misc/trunner.nim
index e288a56c7..530561cd9 100644
--- a/tests/misc/trunner.nim
+++ b/tests/misc/trunner.nim
@@ -12,10 +12,18 @@ from std/sequtils import toSeq,mapIt
 from std/algorithm import sorted
 import stdtest/[specialpaths, unittest_light]
 from std/private/globs import nativeToUnixPath
-
+from strutils import startsWith, strip, removePrefix
+from std/sugar import dup
 import "$lib/../compiler/nimpaths"
 
+proc isDots(a: string): bool =
+  ## test for `hintProcessing` dots
+  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 =
     when defined(c): "c"
@@ -93,10 +101,9 @@ else: # don't run twice the same test
       check exitCode == 0
       let ret = toSeq(walkDirRec(htmldocsDir, relative=true)).mapIt(it.nativeToUnixPath).sorted.join("\n")
       let context = $(i, ret, cmd)
-      var expected = ""
       case i
       of 0,5:
-        let htmlFile = htmldocsDir/"mmain.html"
+        let htmlFile = htmldocsDir/mainFname
         check htmlFile in outp # sanity check for `hintSuccessX`
         assertEquals ret, fmt"""
 {dotdotMangle}/imp.html
@@ -106,7 +113,7 @@ imp.html
 imp.idx
 imp2.html
 imp2.idx
-mmain.html
+{mainFname}
 mmain.idx
 {nimdocOutCss}
 {theindexFname}""", context
@@ -119,21 +126,21 @@ tests/nimdoc/sub/imp.html
 tests/nimdoc/sub/imp.idx
 tests/nimdoc/sub/imp2.html
 tests/nimdoc/sub/imp2.idx
-tests/nimdoc/sub/mmain.html
+tests/nimdoc/sub/{mainFname}
 tests/nimdoc/sub/mmain.idx
 {theindexFname}"""
       of 2, 3: assertEquals ret, fmt"""
 {docHackJsFname}
-mmain.html
+{mainFname}
 mmain.idx
 {nimdocOutCss}""", context
       of 4: assertEquals ret, fmt"""
 {docHackJsFname}
 {nimdocOutCss}
-sub/mmain.html
+sub/{mainFname}
 sub/mmain.idx""", context
       of 6: assertEquals ret, fmt"""
-mmain.html
+{mainFname}
 {nimdocOutCss}""", context
       else: doAssert false
 
@@ -222,3 +229,44 @@ mmain.html
     check fmt"""{nim} {opt} --eval:"echo defined(nimscript)"""".execCmdEx == ("true\n", 0)
     check fmt"""{nim} r {opt} --eval:"echo defined(c)"""".execCmdEx == ("true\n", 0)
     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 (outp, exitCode) = execCmdEx(cmd, options = {poStdErrToStdOut})
+    template check3(cond) = doAssert cond, $(outp,)
+    doAssert exitCode == 0
+    let lines = outp.splitLines
+    check3 lines.len == 3
+    when not defined(windows): # xxx: on windows, dots not properly handled, gives: `....2\n\n`
+      check3 lines[0].isDots
+      check3 lines[1] == "2"
+      check3 lines[2] == ""
+    else:
+      check3 "2" in outp
+
+  block: # nim secret
+    let opt = fmt"{defaultHintsOff} --hint:processing"
+    template check3(cond) = doAssert cond, $(outp,)
+    for extra in ["", "--stdout"]:
+      let cmd = fmt"""{nim} secret {opt} {extra}"""
+      # xxx minor bug: `nim --hint:QuitCalled:off secret` ignores the hint cmdline flag
+      template run(input2): untyped =
+        execCmdEx(cmd, options = {poStdErrToStdOut}, input = input2)
+      block:
+        let (outp, exitCode) = run """echo 1+2; import strutils; echo strip(" ab "); quit()"""
+        let lines = outp.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[3] == "ab"
+          check3 lines[4] == ""
+        else:
+          check3 "3" in outp
+          check3 "ab" in outp
+        doAssert exitCode == 0
+      block:
+        let (outp, exitCode) = run "echo 1+2; quit(2)"
+        check3 "3" in outp
+        doAssert exitCode == 2