summary refs log tree commit diff stats
path: root/tests/misc/trunner.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-06-27 11:39:16 -0700
committerGitHub <noreply@github.com>2021-06-27 20:39:16 +0200
commit0b7361e938134305d6893ee2876b5fc8f9ba419b (patch)
tree0de77b56c54acfac597823b40706384e235595f7 /tests/misc/trunner.nim
parent1b9b8060075efab82912dc33ba64e671d102b999 (diff)
downloadNim-0b7361e938134305d6893ee2876b5fc8f9ba419b.tar.gz
followup #18362: make `UnusedImport` work robustly (#18366)
* warnDuplicateModuleImport => hintDuplicateModuleImport
* improve DuplicateModuleImport msg, add test
Diffstat (limited to 'tests/misc/trunner.nim')
-rw-r--r--tests/misc/trunner.nim26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/misc/trunner.nim b/tests/misc/trunner.nim
index 77ae10f3d..8426e9aee 100644
--- a/tests/misc/trunner.nim
+++ b/tests/misc/trunner.nim
@@ -31,7 +31,7 @@ const
 proc runNimCmd(file, options = "", rtarg = ""): auto =
   let fileabs = testsDir / file.unixToNativePath
   # doAssert fileabs.fileExists, fileabs # disabled because this allows passing `nim r --eval:code fakefile`
-  let cmd = fmt"{nim} {mode} {options} --hints:off {fileabs} {rtarg}"
+  let cmd = fmt"{nim} {mode} --hint:all:off {options} {fileabs} {rtarg}"
   result = execCmdEx(cmd)
   when false: # for debugging
     echo cmd
@@ -352,5 +352,29 @@ running: v2
     doAssert outp2 == "12345\n", outp2
     doAssert status2 == 0
 
+  block: # UnusedImport
+    proc fn(opt: string, expected: string) =
+      let output = runNimCmdChk("pragmas/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]
+"""
+
 else:
   discard # only during debugging, tests added here will run with `-d:nimTestsTrunnerDebugging` enabled