test_nimscript.nims 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # This nimscript is used to test if the following modules can be imported
  2. # http://nim-lang.org/docs/nims.html
  3. {.warning[UnusedImport]: off.}
  4. from stdtest/specialpaths import buildDir
  5. when defined(nimPreviewSlimSystem):
  6. import std/[
  7. syncio, assertions, formatfloat, objectdollar, widestrs
  8. ]
  9. import std/[
  10. # Core:
  11. bitops, typetraits, lenientops, macros, volatile,
  12. # fails due to FFI: typeinfo
  13. # fails due to cstring cast/copyMem: endians
  14. # works but uses FFI: cpuinfo, rlocks, locks
  15. # Algorithms:
  16. algorithm, enumutils, sequtils, setutils,
  17. # Collections:
  18. critbits, deques, heapqueue, intsets, lists, options, sets,
  19. tables, packedsets,
  20. # Strings:
  21. editdistance, wordwrap, parseutils, ropes,
  22. pegs, punycode, strformat, strmisc, strscans, strtabs,
  23. strutils, unicode, unidecode, cstrutils,
  24. # works but uses FFI: encodings
  25. # Time handling:
  26. # fails due to FFI: monotimes, times
  27. # but times.getTime() implemented for VM
  28. # Generic operator system services:
  29. os, streams, distros,
  30. # fails due to FFI: memfiles, osproc, terminal
  31. # works but uses FFI: dynlib
  32. # intentionally fails: marshal
  33. # Math libraries:
  34. complex, math, random, rationals, stats, sums,
  35. # works but uses FFI: fenv, sysrand
  36. # Internet protocols:
  37. httpcore, mimetypes, uri,
  38. # fails due to FFI: asyncdispatch, asyncfile, asyncftpclient, asynchttpserver,
  39. # asyncnet, cgi, cookies, httpclient, nativesockets, net, selectors, smtp
  40. # works but no need to test: asyncstreams, asyncfutures
  41. # Threading:
  42. # fails due to FFI: threadpool
  43. # Parsers:
  44. htmlparser, json, lexbase, parsecfg, parsecsv, parsesql, parsexml,
  45. parseopt, jsonutils,
  46. # XML processing:
  47. xmltree, xmlparser,
  48. # Generators:
  49. htmlgen,
  50. # Hashing:
  51. base64, hashes, md5,
  52. # fails due to cstring cast/times import/endians import: oids
  53. # fails due to copyMem/endians import: sha1
  54. # Miscellaneous:
  55. colors, sugar, varints, enumerate, with,
  56. # fails due to FFI: browsers, coro, segfaults
  57. # fails due to times import/methods: logging
  58. # fails due to methods: unittest
  59. # Modules for JS backend:
  60. # fails intentionally: asyncjs, dom, jsconsole, jscore, jsffi, jsbigints,
  61. # jsfetch, jsformdata, jsheaders
  62. # Unlisted in lib.html:
  63. decls, compilesettings, wrapnils, effecttraits, genasts,
  64. importutils, isolation
  65. ]
  66. # non-std imports
  67. import stdtest/testutils
  68. # tests (increase coverage via code reuse)
  69. import stdlib/trandom
  70. import stdlib/tosenv
  71. echo "Nimscript imports are successful."
  72. block:
  73. doAssert "./foo//./bar/".normalizedPath == "foo/bar".unixToNativePath
  74. block:
  75. doAssert $3'u == "3"
  76. doAssert $3'u64 == "3"
  77. block: # #14142
  78. discard dirExists("/usr")
  79. discard fileExists("/usr/foo")
  80. discard findExe("nim")
  81. block:
  82. doAssertRaises(AssertionDefect): doAssert false
  83. try: doAssert false
  84. except Exception as e:
  85. discard
  86. block: # cpDir, cpFile, dirExists, fileExists, mkDir, mvDir, mvFile, rmDir, rmFile
  87. const dname = buildDir/"D20210121T175016"
  88. const subDir = dname/"sub"
  89. const subDir2 = dname/"sub2"
  90. const fpath = subDir/"f"
  91. const fpath2 = subDir/"f2"
  92. const fpath3 = subDir2/"f"
  93. mkDir(subDir)
  94. writeFile(fpath, "some text")
  95. cpFile(fpath, fpath2)
  96. doAssert fileExists(fpath2)
  97. rmFile(fpath2)
  98. cpDir(subDir, subDir2)
  99. doAssert fileExists(fpath3)
  100. rmDir(subDir2)
  101. mvFile(fpath, fpath2)
  102. doAssert not fileExists(fpath)
  103. doAssert fileExists(fpath2)
  104. mvFile(fpath2, fpath)
  105. mvDir(subDir, subDir2)
  106. doAssert not dirExists(subDir)
  107. doAssert dirExists(subDir2)
  108. mvDir(subDir2, subDir)
  109. rmDir(dname)
  110. block:
  111. # check parseopt can get command line:
  112. discard initOptParser()