categories.nim 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. #
  2. #
  3. # Nim Tester
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## Include for the tester that contains test suites that test special features
  10. ## of the compiler.
  11. const
  12. specialCategories = [
  13. "assert",
  14. "async",
  15. "debugger",
  16. "dll",
  17. "examples",
  18. "flags",
  19. "gc",
  20. "io",
  21. "js",
  22. "lib",
  23. "longgc",
  24. "manyloc",
  25. "nimble-all",
  26. "nimble-core",
  27. "nimble-extra",
  28. "niminaction",
  29. "rodfiles",
  30. "threads",
  31. "untestable",
  32. "stdlib",
  33. "testdata",
  34. "nimcache",
  35. "coroutines",
  36. "osproc",
  37. "shouldfail",
  38. "dir with space"
  39. ]
  40. # included from tester.nim
  41. # ---------------- ROD file tests ---------------------------------------------
  42. const
  43. rodfilesDir = "tests/rodfiles"
  44. proc delNimCache(filename, options: string) =
  45. for target in low(TTarget)..high(TTarget):
  46. let dir = nimcacheDir(filename, options, target)
  47. try:
  48. removeDir(dir)
  49. except OSError:
  50. echo "[Warning] could not delete: ", dir
  51. proc runRodFiles(r: var TResults, cat: Category, options: string) =
  52. template test(filename: string, clearCacheFirst=false) =
  53. if clearCacheFirst: delNimCache(filename, options)
  54. testSpec r, makeTest(rodfilesDir / filename, options, cat)
  55. # test basic recompilation scheme:
  56. test "hallo", true
  57. test "hallo"
  58. when false:
  59. # test incremental type information:
  60. test "hallo2"
  61. # test type converters:
  62. test "aconv", true
  63. test "bconv"
  64. # test G, A, B example from the documentation; test init sections:
  65. test "deada", true
  66. test "deada2"
  67. when false:
  68. # test method generation:
  69. test "bmethods", true
  70. test "bmethods2"
  71. # test generics:
  72. test "tgeneric1", true
  73. test "tgeneric2"
  74. proc compileRodFiles(r: var TResults, cat: Category, options: string) =
  75. template test(filename: untyped, clearCacheFirst=true) =
  76. if clearCacheFirst: delNimCache(filename, options)
  77. testSpec r, makeTest(rodfilesDir / filename, options, cat)
  78. # test DLL interfacing:
  79. test "gtkex1", true
  80. test "gtkex2"
  81. # --------------------- flags tests -------------------------------------------
  82. proc flagTests(r: var TResults, cat: Category, options: string) =
  83. # --genscript
  84. const filename = "tests"/"flags"/"tgenscript"
  85. const genopts = " --genscript"
  86. let nimcache = nimcacheDir(filename, genopts, targetC)
  87. testSpec r, makeTest(filename, genopts, cat)
  88. when defined(windows):
  89. testExec r, makeTest(filename, " cmd /c cd " & nimcache &
  90. " && compile_tgenscript.bat", cat)
  91. elif defined(posix):
  92. testExec r, makeTest(filename, " sh -c \"cd " & nimcache &
  93. " && sh compile_tgenscript.sh\"", cat)
  94. # Run
  95. testExec r, makeTest(filename, " " & nimcache / "tgenscript", cat)
  96. # --------------------- DLL generation tests ----------------------------------
  97. proc safeCopyFile(src, dest: string) =
  98. try:
  99. copyFile(src, dest)
  100. except OSError:
  101. echo "[Warning] could not copy: ", src, " to ", dest
  102. proc runBasicDLLTest(c, r: var TResults, cat: Category, options: string) =
  103. const rpath = when defined(macosx):
  104. " --passL:-rpath --passL:@loader_path"
  105. else:
  106. ""
  107. var test1 = makeTest("lib/nimrtl.nim", options & " --app:lib -d:createNimRtl --threads:on", cat)
  108. test1.spec.action = actionCompile
  109. testSpec c, test1
  110. var test2 = makeTest("tests/dll/server.nim", options & " --app:lib -d:useNimRtl --threads:on" & rpath, cat)
  111. test2.spec.action = actionCompile
  112. testSpec c, test2
  113. when defined(Windows):
  114. # windows looks in the dir of the exe (yay!):
  115. var nimrtlDll = DynlibFormat % "nimrtl"
  116. safeCopyFile("lib" / nimrtlDll, "tests/dll" / nimrtlDll)
  117. else:
  118. # posix relies on crappy LD_LIBRARY_PATH (ugh!):
  119. const libpathenv = when defined(haiku):
  120. "LIBRARY_PATH"
  121. else:
  122. "LD_LIBRARY_PATH"
  123. var libpath = getEnv(libpathenv).string
  124. # Temporarily add the lib directory to LD_LIBRARY_PATH:
  125. putEnv(libpathenv, "tests/dll" & (if libpath.len > 0: ":" & libpath else: ""))
  126. defer: putEnv(libpathenv, libpath)
  127. var nimrtlDll = DynlibFormat % "nimrtl"
  128. safeCopyFile("lib" / nimrtlDll, "tests/dll" / nimrtlDll)
  129. testSpec r, makeTest("tests/dll/client.nim", options & " -d:useNimRtl --threads:on" & rpath,
  130. cat)
  131. proc dllTests(r: var TResults, cat: Category, options: string) =
  132. # dummy compile result:
  133. var c = initResults()
  134. runBasicDLLTest c, r, cat, options
  135. runBasicDLLTest c, r, cat, options & " -d:release"
  136. when not defined(windows):
  137. # still cannot find a recent Windows version of boehm.dll:
  138. runBasicDLLTest c, r, cat, options & " --gc:boehm"
  139. runBasicDLLTest c, r, cat, options & " -d:release --gc:boehm"
  140. # ------------------------------ GC tests -------------------------------------
  141. proc gcTests(r: var TResults, cat: Category, options: string) =
  142. template testWithNone(filename: untyped) =
  143. testSpec r, makeTest("tests/gc" / filename, options &
  144. " --gc:none", cat)
  145. testSpec r, makeTest("tests/gc" / filename, options &
  146. " -d:release --gc:none", cat)
  147. template testWithoutMs(filename: untyped) =
  148. testSpec r, makeTest("tests/gc" / filename, options, cat)
  149. testSpec r, makeTest("tests/gc" / filename, options &
  150. " -d:release", cat)
  151. testSpec r, makeTest("tests/gc" / filename, options &
  152. " -d:release -d:useRealtimeGC", cat)
  153. template testWithoutBoehm(filename: untyped) =
  154. testWithoutMs filename
  155. testSpec r, makeTest("tests/gc" / filename, options &
  156. " --gc:markAndSweep", cat)
  157. testSpec r, makeTest("tests/gc" / filename, options &
  158. " -d:release --gc:markAndSweep", cat)
  159. template test(filename: untyped) =
  160. testWithoutBoehm filename
  161. when not defined(windows) and not defined(android):
  162. # AR: cannot find any boehm.dll on the net, right now, so disabled
  163. # for windows:
  164. testSpec r, makeTest("tests/gc" / filename, options &
  165. " --gc:boehm", cat)
  166. testSpec r, makeTest("tests/gc" / filename, options &
  167. " -d:release --gc:boehm", cat)
  168. testWithoutBoehm "foreign_thr"
  169. test "gcemscripten"
  170. test "growobjcrash"
  171. test "gcbench"
  172. test "gcleak"
  173. test "gcleak2"
  174. testWithoutBoehm "gctest"
  175. testWithNone "gctest"
  176. test "gcleak3"
  177. test "gcleak4"
  178. # Disabled because it works and takes too long to run:
  179. #test "gcleak5"
  180. testWithoutBoehm "weakrefs"
  181. test "cycleleak"
  182. testWithoutBoehm "closureleak"
  183. testWithoutMs "refarrayleak"
  184. testWithoutBoehm "tlists"
  185. testWithoutBoehm "thavlak"
  186. test "stackrefleak"
  187. test "cyclecollector"
  188. proc longGCTests(r: var TResults, cat: Category, options: string) =
  189. when defined(windows):
  190. let cOptions = "-ldl -DWIN"
  191. else:
  192. let cOptions = "-ldl"
  193. var c = initResults()
  194. # According to ioTests, this should compile the file
  195. testSpec c, makeTest("tests/realtimeGC/shared", options, cat)
  196. # ^- why is this not appended to r? Should this be discarded?
  197. testC r, makeTest("tests/realtimeGC/cmain", cOptions, cat), actionRun
  198. testSpec r, makeTest("tests/realtimeGC/nmain", options & "--threads: on", cat)
  199. # ------------------------- threading tests -----------------------------------
  200. proc threadTests(r: var TResults, cat: Category, options: string) =
  201. template test(filename: untyped) =
  202. testSpec r, makeTest(filename, options, cat)
  203. testSpec r, makeTest(filename, options & " -d:release", cat)
  204. testSpec r, makeTest(filename, options & " --tlsEmulation:on", cat)
  205. for t in os.walkFiles("tests/threads/t*.nim"):
  206. test(t)
  207. # ------------------------- IO tests ------------------------------------------
  208. proc ioTests(r: var TResults, cat: Category, options: string) =
  209. # We need readall_echo to be compiled for this test to run.
  210. # dummy compile result:
  211. var c = initResults()
  212. testSpec c, makeTest("tests/system/helpers/readall_echo", options, cat)
  213. testSpec r, makeTest("tests/system/tio", options, cat)
  214. # ------------------------- async tests ---------------------------------------
  215. proc asyncTests(r: var TResults, cat: Category, options: string) =
  216. template test(filename: untyped) =
  217. testSpec r, makeTest(filename, options, cat)
  218. for t in os.walkFiles("tests/async/t*.nim"):
  219. test(t)
  220. # ------------------------- debugger tests ------------------------------------
  221. proc debuggerTests(r: var TResults, cat: Category, options: string) =
  222. var t = makeTest("tools/nimgrep", options & " --debugger:on", cat)
  223. t.spec.action = actionCompile
  224. testSpec r, t
  225. # ------------------------- JS tests ------------------------------------------
  226. proc jsTests(r: var TResults, cat: Category, options: string) =
  227. template test(filename: untyped) =
  228. testSpec r, makeTest(filename, options & " -d:nodejs", cat), {targetJS}
  229. testSpec r, makeTest(filename, options & " -d:nodejs -d:release", cat), {targetJS}
  230. for t in os.walkFiles("tests/js/t*.nim"):
  231. test(t)
  232. for testfile in ["exception/texceptions", "exception/texcpt1",
  233. "exception/texcsub", "exception/tfinally",
  234. "exception/tfinally2", "exception/tfinally3",
  235. "actiontable/tactiontable", "method/tmultimjs",
  236. "varres/tvarres0", "varres/tvarres3", "varres/tvarres4",
  237. "varres/tvartup", "misc/tints", "misc/tunsignedinc",
  238. "async/tjsandnativeasync"]:
  239. test "tests/" & testfile & ".nim"
  240. for testfile in ["strutils", "json", "random", "times", "logging"]:
  241. test "lib/pure/" & testfile & ".nim"
  242. # ------------------------- nim in action -----------
  243. proc testNimInAction(r: var TResults, cat: Category, options: string) =
  244. let options = options & " --nilseqs:on"
  245. template test(filename: untyped) =
  246. testSpec r, makeTest(filename, options, cat)
  247. template testJS(filename: untyped) =
  248. testSpec r, makeTest(filename, options, cat), {targetJS}
  249. template testCPP(filename: untyped) =
  250. testSpec r, makeTest(filename, options, cat), {targetCPP}
  251. let tests = [
  252. "niminaction/Chapter1/various1",
  253. "niminaction/Chapter2/various2",
  254. "niminaction/Chapter2/resultaccept",
  255. "niminaction/Chapter2/resultreject",
  256. "niminaction/Chapter2/explicit_discard",
  257. "niminaction/Chapter2/no_def_eq",
  258. "niminaction/Chapter2/no_iterator",
  259. "niminaction/Chapter2/no_seq_type",
  260. "niminaction/Chapter3/ChatApp/src/server",
  261. "niminaction/Chapter3/ChatApp/src/client",
  262. "niminaction/Chapter3/various3",
  263. "niminaction/Chapter6/WikipediaStats/concurrency_regex",
  264. "niminaction/Chapter6/WikipediaStats/concurrency",
  265. "niminaction/Chapter6/WikipediaStats/naive",
  266. "niminaction/Chapter6/WikipediaStats/parallel_counts",
  267. "niminaction/Chapter6/WikipediaStats/race_condition",
  268. "niminaction/Chapter6/WikipediaStats/sequential_counts",
  269. "niminaction/Chapter6/WikipediaStats/unguarded_access",
  270. "niminaction/Chapter7/Tweeter/src/tweeter",
  271. "niminaction/Chapter7/Tweeter/src/createDatabase",
  272. "niminaction/Chapter7/Tweeter/tests/database_test",
  273. "niminaction/Chapter8/sdl/sdl_test"
  274. ]
  275. # Verify that the files have not been modified. Death shall fall upon
  276. # whoever edits these hashes without dom96's permission, j/k. But please only
  277. # edit when making a conscious breaking change, also please try to make your
  278. # commit message clear and notify me so I can easily compile an errata later.
  279. const refHashes = @[
  280. "51afdfa84b3ca3d810809d6c4e5037ba",
  281. "30f07e4cd5eaec981f67868d4e91cfcf",
  282. "d14e7c032de36d219c9548066a97e846",
  283. "b335635562ff26ec0301bdd86356ac0c",
  284. "6c4add749fbf50860e2f523f548e6b0e",
  285. "76de5833a7cc46f96b006ce51179aeb1",
  286. "705eff79844e219b47366bd431658961",
  287. "a1e87b881c5eb161553d119be8b52f64",
  288. "2d706a6ec68d2973ec7e733e6d5dce50",
  289. "c11a013db35e798f44077bc0763cc86d",
  290. "3e32e2c5e9a24bd13375e1cd0467079c",
  291. "a5452722b2841f0c1db030cf17708955",
  292. "dc6c45eb59f8814aaaf7aabdb8962294",
  293. "69d208d281a2e7bffd3eaf4bab2309b1",
  294. "ec05666cfb60211bedc5e81d4c1caf3d",
  295. "da520038c153f4054cb8cc5faa617714",
  296. "59906c8cd819cae67476baa90a36b8c1",
  297. "9a8fe78c588d08018843b64b57409a02",
  298. "8b5d28e985c0542163927d253a3e4fc9",
  299. "783299b98179cc725f9c46b5e3b5381f",
  300. "1a2b3fba1187c68d6a9bfa66854f3318",
  301. "80f9c3e594a798225046e8a42e990daf"
  302. ]
  303. for i, test in tests:
  304. let filename = "tests" / test.addFileExt("nim")
  305. let testHash = getMD5(readFile(filename).string)
  306. doAssert testHash == refHashes[i], "Nim in Action test " & filename & " was changed."
  307. # Run the tests.
  308. for testfile in tests:
  309. test "tests/" & testfile & ".nim"
  310. let jsFile = "tests/niminaction/Chapter8/canvas/canvas_test.nim"
  311. testJS jsFile
  312. let cppFile = "tests/niminaction/Chapter8/sfml/sfml_test.nim"
  313. testCPP cppFile
  314. # ------------------------- manyloc -------------------------------------------
  315. proc findMainFile(dir: string): string =
  316. # finds the file belonging to ".nim.cfg"; if there is no such file
  317. # it returns the some ".nim" file if there is only one:
  318. const cfgExt = ".nim.cfg"
  319. result = ""
  320. var nimFiles = 0
  321. for kind, file in os.walkDir(dir):
  322. if kind == pcFile:
  323. if file.endsWith(cfgExt): return file[.. ^(cfgExt.len+1)] & ".nim"
  324. elif file.endsWith(".nim"):
  325. if result.len == 0: result = file
  326. inc nimFiles
  327. if nimFiles != 1: result.setlen(0)
  328. proc manyLoc(r: var TResults, cat: Category, options: string) =
  329. for kind, dir in os.walkDir("tests/manyloc"):
  330. if kind == pcDir:
  331. when defined(windows):
  332. if dir.endsWith"nake": continue
  333. if dir.endsWith"named_argument_bug": continue
  334. let mainfile = findMainFile(dir)
  335. if mainfile != "":
  336. var test = makeTest(mainfile, options, cat)
  337. test.spec.action = actionCompile
  338. testSpec r, test
  339. proc compileExample(r: var TResults, pattern, options: string, cat: Category) =
  340. for test in os.walkFiles(pattern):
  341. var test = makeTest(test, options, cat)
  342. test.spec.action = actionCompile
  343. testSpec r, test
  344. proc testStdlib(r: var TResults, pattern, options: string, cat: Category) =
  345. for testFile in os.walkFiles(pattern):
  346. let name = extractFilename(testFile)
  347. if name notin disabledFiles:
  348. let contents = readFile(testFile).string
  349. var testObj = makeTest(testFile, options, cat)
  350. if "when isMainModule" notin contents:
  351. testObj.spec.action = actionCompile
  352. testSpec r, testObj
  353. # ----------------------------- nimble ----------------------------------------
  354. type
  355. PackageFilter = enum
  356. pfCoreOnly
  357. pfExtraOnly
  358. pfAll
  359. var nimbleDir = getEnv("NIMBLE_DIR").string
  360. if nimbleDir.len == 0: nimbleDir = getHomeDir() / ".nimble"
  361. let
  362. nimbleExe = findExe("nimble")
  363. #packageDir = nimbleDir / "pkgs" # not used
  364. packageIndex = nimbleDir / "packages.json"
  365. proc waitForExitEx(p: Process): int =
  366. var outp = outputStream(p)
  367. var line = newStringOfCap(120).TaintedString
  368. while true:
  369. if outp.readLine(line):
  370. discard
  371. else:
  372. result = peekExitCode(p)
  373. if result != -1: break
  374. close(p)
  375. proc getPackageDir(package: string): string =
  376. ## TODO - Replace this with dom's version comparison magic.
  377. var commandOutput = execCmdEx("nimble path $#" % package)
  378. if commandOutput.exitCode != QuitSuccess:
  379. return ""
  380. else:
  381. result = commandOutput[0].string
  382. iterator listPackages(filter: PackageFilter): tuple[name, url: string] =
  383. let packageList = parseFile(packageIndex)
  384. for package in packageList.items():
  385. let
  386. name = package["name"].str
  387. url = package["url"].str
  388. isCorePackage = "nim-lang" in normalize(url)
  389. case filter:
  390. of pfCoreOnly:
  391. if isCorePackage:
  392. yield (name, url)
  393. of pfExtraOnly:
  394. if not isCorePackage:
  395. yield (name, url)
  396. of pfAll:
  397. yield (name, url)
  398. proc testNimblePackages(r: var TResults, cat: Category, filter: PackageFilter) =
  399. if nimbleExe == "":
  400. echo("[Warning] - Cannot run nimble tests: Nimble binary not found.")
  401. return
  402. if execCmd("$# update" % nimbleExe) == QuitFailure:
  403. echo("[Warning] - Cannot run nimble tests: Nimble update failed.")
  404. return
  405. let packageFileTest = makeTest("PackageFileParsed", "", cat)
  406. try:
  407. for name, url in listPackages(filter):
  408. var test = makeTest(name, "", cat)
  409. echo(url)
  410. let
  411. installProcess = startProcess(nimbleExe, "", ["install", "-y", name])
  412. installStatus = waitForExitEx(installProcess)
  413. installProcess.close
  414. if installStatus != QuitSuccess:
  415. r.addResult(test, targetC, "", "", reInstallFailed)
  416. continue
  417. let
  418. buildPath = getPackageDir(name).strip
  419. buildProcess = startProcess(nimbleExe, buildPath, ["build"])
  420. buildStatus = waitForExitEx(buildProcess)
  421. buildProcess.close
  422. if buildStatus != QuitSuccess:
  423. r.addResult(test, targetC, "", "", reBuildFailed)
  424. r.addResult(test, targetC, "", "", reSuccess)
  425. r.addResult(packageFileTest, targetC, "", "", reSuccess)
  426. except JsonParsingError:
  427. echo("[Warning] - Cannot run nimble tests: Invalid package file.")
  428. r.addResult(packageFileTest, targetC, "", "", reBuildFailed)
  429. # ----------------------------------------------------------------------------
  430. const AdditionalCategories = ["debugger", "examples", "lib", "megatest"]
  431. proc `&.?`(a, b: string): string =
  432. # candidate for the stdlib?
  433. result = if b.startswith(a): b else: a & b
  434. proc processSingleTest(r: var TResults, cat: Category, options, test: string) =
  435. let test = "tests" & DirSep &.? cat.string / test
  436. let target = if cat.string.normalize == "js": targetJS else: targetC
  437. if existsFile(test):
  438. testSpec r, makeTest(test, options, cat), {target}
  439. else:
  440. echo "[Warning] - ", test, " test does not exist"
  441. proc isJoinableSpec(spec: TSpec): bool =
  442. result = not spec.sortoutput and
  443. spec.action == actionRun and
  444. not fileExists(spec.file.changeFileExt("cfg")) and
  445. not fileExists(parentDir(spec.file) / "nim.cfg") and
  446. spec.cmd.len == 0 and
  447. spec.err != reDisabled and
  448. not spec.unjoinable and
  449. spec.exitCode == 0 and
  450. spec.input.len == 0 and
  451. spec.nimout.len == 0 and
  452. spec.outputCheck != ocSubstr and
  453. spec.ccodeCheck.len == 0 and
  454. (spec.targets == {} or spec.targets == {targetC})
  455. proc norm(s: var string) =
  456. while true:
  457. let tmp = s.replace("\n\n", "\n")
  458. if tmp == s: break
  459. s = tmp
  460. s = s.strip
  461. proc runJoinedTest(r: var TResults, cat: Category, testsDir: string) =
  462. ## returs a list of tests that have problems
  463. var specs: seq[TSpec] = @[]
  464. for kind, dir in walkDir(testsDir):
  465. assert testsDir.startsWith(testsDir)
  466. let cat = dir[testsDir.len .. ^1]
  467. if kind == pcDir and cat notin specialCategories:
  468. for file in os.walkFiles(testsDir / cat / "t*.nim"):
  469. let spec = parseSpec(file)
  470. if isJoinableSpec(spec):
  471. specs.add spec
  472. echo "joinable specs: ", specs.len
  473. var megatest: string
  474. for runSpec in specs:
  475. megatest.add "import r\""
  476. megatest.add runSpec.file
  477. megatest.add "\"\n"
  478. writeFile("megatest.nim", megatest)
  479. const args = ["c", "-d:testing", "--listCmd", "megatest.nim"]
  480. var (buf, exitCode) = execCmdEx2(command = "nim", args = args, options = {poStdErrToStdOut, poUsePath}, input = "")
  481. if exitCode != 0:
  482. echo buf
  483. quit("megatest compilation failed")
  484. (buf, exitCode) = execCmdEx("./megatest")
  485. if exitCode != 0:
  486. echo buf
  487. quit("megatest execution failed")
  488. norm buf
  489. writeFile("outputGotten.txt", buf)
  490. var outputExpected = ""
  491. for i, runSpec in specs:
  492. outputExpected.add runSpec.output.strip
  493. outputExpected.add '\n'
  494. norm outputExpected
  495. if buf != outputExpected:
  496. writeFile("outputExpected.txt", outputExpected)
  497. discard execShellCmd("diff -uNdr outputExpected.txt outputGotten.txt")
  498. echo "output different!"
  499. quit 1
  500. else:
  501. echo "output OK"
  502. removeFile("outputGotten.txt")
  503. removeFile("megatest.nim")
  504. #testSpec r, makeTest("megatest", options, cat)
  505. # ---------------------------------------------------------------------------
  506. proc processCategory(r: var TResults, cat: Category, options, testsDir: string,
  507. runJoinableTests: bool) =
  508. case cat.string.normalize
  509. of "rodfiles":
  510. when false:
  511. compileRodFiles(r, cat, options)
  512. runRodFiles(r, cat, options)
  513. of "js":
  514. # only run the JS tests on Windows or Linux because Travis is bad
  515. # and other OSes like Haiku might lack nodejs:
  516. if not defined(linux) and isTravis:
  517. discard
  518. else:
  519. jsTests(r, cat, options)
  520. of "dll":
  521. dllTests(r, cat, options)
  522. of "flags":
  523. flagTests(r, cat, options)
  524. of "gc":
  525. gcTests(r, cat, options)
  526. of "longgc":
  527. longGCTests(r, cat, options)
  528. of "debugger":
  529. debuggerTests(r, cat, options)
  530. of "manyloc":
  531. manyLoc r, cat, options
  532. of "threads":
  533. threadTests r, cat, options & " --threads:on"
  534. of "io":
  535. ioTests r, cat, options
  536. of "async":
  537. asyncTests r, cat, options
  538. of "lib":
  539. testStdlib(r, "lib/pure/*.nim", options, cat)
  540. testStdlib(r, "lib/packages/docutils/highlite", options, cat)
  541. of "examples":
  542. compileExample(r, "examples/*.nim", options, cat)
  543. compileExample(r, "examples/gtk/*.nim", options, cat)
  544. compileExample(r, "examples/talk/*.nim", options, cat)
  545. of "nimble-core":
  546. testNimblePackages(r, cat, pfCoreOnly)
  547. of "nimble-extra":
  548. testNimblePackages(r, cat, pfExtraOnly)
  549. of "nimble-all":
  550. testNimblePackages(r, cat, pfAll)
  551. of "niminaction":
  552. testNimInAction(r, cat, options)
  553. of "untestable":
  554. # We can't test it because it depends on a third party.
  555. discard # TODO: Move untestable tests to someplace else, i.e. nimble repo.
  556. of "megatest":
  557. runJoinedTest(r, cat, testsDir)
  558. else:
  559. var testsRun = 0
  560. for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"):
  561. var test = makeTest(name, options, cat)
  562. if runJoinableTests or not isJoinableSpec(test.spec) or cat.string in specialCategories:
  563. discard "run the test"
  564. else:
  565. test.spec.err = reJoined
  566. testSpec r, test
  567. inc testsRun
  568. if testsRun == 0:
  569. echo "[Warning] - Invalid category specified \"", cat.string, "\", no tests were run"