@@ -12,10 +12,18 @@ from std/sequtils import toSeq,mapIt
1212from std/ algorithm import sorted
1313import stdtest/ [specialpaths, unittest_light]
1414from std/ private/ globs import nativeToUnixPath
15-
15+ from strutils import startsWith, strip, removePrefix
16+ from std/ sugar import dup
1617import " $lib/../compiler/nimpaths"
1718
19+ proc isDots (a: string ): bool =
20+ # # test for `hintProcessing` dots
21+ a.startsWith (" ." ) and a.strip (chars = {'.' }) == " "
22+
1823const
24+ defaultHintsOff = " --hint:successx:off --hint:exec:off --hint:link:off --hint:cc:off --hint:conf:off --hint:processing:off --hint:QuitCalled:off"
25+ # useful when you want to turn only some hints on, and some common ones off.
26+ # pending https://github.com/timotheecour/Nim/issues/453, simplify to: `--hints:off`
1927 nim = getCurrentCompilerExe ()
2028 mode =
2129 when defined (c): " c"
@@ -93,10 +101,9 @@ else: # don't run twice the same test
93101 check exitCode == 0
94102 let ret = toSeq (walkDirRec (htmldocsDir, relative= true )).mapIt (it.nativeToUnixPath).sorted.join (" \n " )
95103 let context = $ (i, ret, cmd)
96- var expected = " "
97104 case i
98105 of 0 ,5 :
99- let htmlFile = htmldocsDir/ " mmain.html "
106+ let htmlFile = htmldocsDir/ mainFname
100107 check htmlFile in outp # sanity check for `hintSuccessX`
101108 assertEquals ret, fmt"""
102109{ dotdotMangle} /imp.html
@@ -106,7 +113,7 @@ imp.html
106113imp.idx
107114imp2.html
108115imp2.idx
109- mmain.html
116+ { mainFname }
110117mmain.idx
111118{ nimdocOutCss}
112119{ theindexFname} """ , context
@@ -119,21 +126,21 @@ tests/nimdoc/sub/imp.html
119126tests/nimdoc/sub/imp.idx
120127tests/nimdoc/sub/imp2.html
121128tests/nimdoc/sub/imp2.idx
122- tests/nimdoc/sub/mmain.html
129+ tests/nimdoc/sub/{ mainFname }
123130tests/nimdoc/sub/mmain.idx
124131{ theindexFname} """
125132 of 2 , 3 : assertEquals ret, fmt"""
126133{ docHackJsFname}
127- mmain.html
134+ { mainFname }
128135mmain.idx
129136{ nimdocOutCss} """ , context
130137 of 4 : assertEquals ret, fmt"""
131138{ docHackJsFname}
132139{ nimdocOutCss}
133- sub/mmain.html
140+ sub/{ mainFname }
134141sub/mmain.idx """ , context
135142 of 6 : assertEquals ret, fmt"""
136- mmain.html
143+ { mainFname }
137144{ nimdocOutCss} """ , context
138145 else : doAssert false
139146
@@ -222,3 +229,44 @@ mmain.html
222229 check fmt""" { nim} { opt} --eval:"echo defined(nimscript)"""" .execCmdEx == (" true\n " , 0 )
223230 check fmt""" { nim} r { opt} --eval:"echo defined(c)"""" .execCmdEx == (" true\n " , 0 )
224231 check fmt""" { nim} r -b:js { opt} --eval:"echo defined(js)"""" .execCmdEx == (" true\n " , 0 )
232+
233+ block : # `hintProcessing` dots should not interfere with `static: echo` + friends
234+ let cmd = fmt""" { nim} r { defaultHintsOff} --hint:processing -f --eval:"static: echo 1+1""""
235+ let (outp, exitCode) = execCmdEx (cmd, options = {poStdErrToStdOut})
236+ template check3 (cond) = doAssert cond, $ (outp,)
237+ doAssert exitCode == 0
238+ let lines = outp.splitLines
239+ check3 lines.len == 3
240+ when not defined (windows): # xxx: on windows, dots not properly handled, gives: `....2\n\n`
241+ check3 lines[0 ].isDots
242+ check3 lines[1 ] == " 2"
243+ check3 lines[2 ] == " "
244+ else :
245+ check3 " 2" in outp
246+
247+ block : # nim secret
248+ let opt = fmt" { defaultHintsOff} --hint:processing"
249+ template check3 (cond) = doAssert cond, $ (outp,)
250+ for extra in [" " , " --stdout" ]:
251+ let cmd = fmt""" { nim} secret { opt} { extra} """
252+ # xxx minor bug: `nim --hint:QuitCalled:off secret` ignores the hint cmdline flag
253+ template run (input2): untyped =
254+ execCmdEx (cmd, options = {poStdErrToStdOut}, input = input2)
255+ block :
256+ let (outp, exitCode) = run """ echo 1+2; import strutils; echo strip(" ab "); quit() """
257+ let lines = outp.splitLines
258+ when not defined (windows):
259+ check3 lines.len == 5
260+ check3 lines[0 ].isDots
261+ check3 lines[1 ].dup (removePrefix (" >>> " )) == " 3" # prompt depends on `nimUseLinenoise`
262+ check3 lines[2 ].isDots
263+ check3 lines[3 ] == " ab"
264+ check3 lines[4 ] == " "
265+ else :
266+ check3 " 3" in outp
267+ check3 " ab" in outp
268+ doAssert exitCode == 0
269+ block :
270+ let (outp, exitCode) = run " echo 1+2; quit(2)"
271+ check3 " 3" in outp
272+ doAssert exitCode == 2
0 commit comments