make more standard libraries work with nimPreviewSlimSystem (#20343)

* make more standard libraries work with `nimPreviewSlimSystem`

* typo

* part two

* Delete specutils.nim

* fixes more tests

* more fixes

* fixes tests

* fixes three more tests

* add formatfloat import

* fix

* last
This commit is contained in:
ringabout
2022-09-28 02:06:23 +08:00
committed by GitHub
parent 98a717dda9
commit 3d2f0e2c7c
194 changed files with 299 additions and 54 deletions

View File

@@ -1,6 +1,8 @@
# test atomic operations
import std/[atomics, bitops]
import std/assertions
type
Object = object

View File

@@ -2,6 +2,7 @@ discard """
targets: "c cpp"
"""
import std/atomics
import std/assertions
block testSize: # issue 12726
type

View File

@@ -1,2 +1,3 @@
switch("styleCheck", "usages")
switch("styleCheck", "error")
switch("styleCheck", "error")
switch("define", "nimPreviewSlimSystem")

View File

@@ -1,4 +1,5 @@
import std/intsets
import std/assertions
proc test1*[]() =
let a = initIntSet()

View File

@@ -5,6 +5,7 @@ discard """
"""
import os
import std/assertions
# consider moving this inside tosproc (taking care that it's for cpp mode)

View File

@@ -1,4 +1,5 @@
import heapqueue
import std/heapqueue
import std/assertions
var test_queue : HeapQueue[int]

View File

@@ -1,4 +1,5 @@
import strutils
import std/strutils
import std/assertions
type
MyEnum = enum

View File

@@ -6,6 +6,7 @@ discard """
#12928,10456
import std/[sequtils, algorithm, json, sugar]
import std/assertions
proc test() =
try:

View File

@@ -1,7 +1,7 @@
discard """
targets: "c cpp js"
"""
import std/assertions
# TODO: in future work move existing arithmetic tests (tests/arithm/*) into this file
# FYI https://github.com/nim-lang/Nim/pull/17767

View File

@@ -7,6 +7,7 @@ discard """
import strutils
from net import TimeoutError
import std/assertions
import httpclient, asynchttpserver, asyncdispatch, asyncfutures

View File

@@ -8,6 +8,7 @@ import net
import std/asyncnet
import std/nativesockets
import std/assertions
const postBegin = """
POST / HTTP/1.1

View File

@@ -1,7 +1,7 @@
discard """
targets: "c js"
"""
import std/assertions
import std/base64
template main() =

View File

@@ -5,6 +5,7 @@ OK
'''
"""
import bitops
import std/assertions
proc main() =
const U8 = 0b0011_0010'u8

View File

@@ -1,4 +1,5 @@
import std/private/bitops_utils
import std/assertions
template chk(a, b) =
let a2 = castToUnsigned(a)

View File

@@ -1,5 +1,6 @@
import std/unittest
import std/[cgi, strtabs, sugar]
import std/assertions
block: # Test cgi module
const queryString = "foo=bar&фу=бар&checked=✓&list=1,2,3&with_space=text%20with%20space"

View File

@@ -4,6 +4,7 @@ discard """
"""
import std/os
import std/assertions
var params = paramCount()
doAssert params == 0

View File

@@ -1,5 +1,5 @@
import std/[complex, math]
import std/assertions
proc `=~`[T](x, y: Complex[T]): bool =
result = abs(x.re-y.re) < 1e-6 and abs(x.im-y.im) < 1e-6

View File

@@ -4,6 +4,7 @@ discard """
import std/[cookies, times, strtabs]
import std/assertions
let expire = fromUnix(0) + 1.seconds

View File

@@ -3,6 +3,7 @@ discard """
"""
import std/[sequtils,critbits]
import std/assertions
template main =
var r: CritBitTree[void]

View File

@@ -5,6 +5,7 @@ discard """
from std/sugar import collect
from stdtest/testutils import whenRuntimeJs, whenVMorJs
import std/assertions
template testMitems() =
block:

View File

@@ -3,7 +3,7 @@ discard """
"""
import std/cstrutils
import std/assertions
proc main() =
let s = cstring "abcdef"

View File

@@ -1,4 +1,5 @@
import std/db_mysql
import std/assertions
doAssert dbQuote("SELECT * FROM foo WHERE col1 = 'bar_baz'") == "'SELECT * FROM foo WHERE col1 = \\'bar_baz\\''"
doAssert dbQuote("SELECT * FROM foo WHERE col1 LIKE '%bar_baz%'") == "'SELECT * FROM foo WHERE col1 LIKE \\'%bar_baz%\\''"

View File

@@ -1,7 +1,7 @@
discard """
targets: "c cpp js"
"""
import std/assertions
import std/decls
template fun() =

View File

@@ -1,5 +1,5 @@
import std/private/decode_helpers
import std/assertions
block:
var i = 0

View File

@@ -5,7 +5,7 @@ discard """
import std/deques
from std/sequtils import toSeq
import std/assertions
block:
proc index(self: Deque[int], idx: Natural): int =

View File

@@ -4,6 +4,7 @@ discard """
import experimental/diff
import std/strutils
import std/assertions
proc testHelper(f: seq[Item]): string =
for it in f:

View File

@@ -9,6 +9,7 @@ discard """
import ../../lib/packages/docutils/[rstast, rst, dochelpers]
import unittest
import std/assertions
proc testMsgHandler(filename: string, line, col: int, msgkind: MsgKind,
arg: string) =

View File

@@ -1,4 +1,5 @@
import std/editdistance
import std/assertions
doAssert editDistance("", "") == 0
doAssert editDistance("kitten", "sitting") == 3 # from Wikipedia

View File

@@ -1,4 +1,5 @@
import std/encodings
import std/assertions
var fromGBK = open("utf-8", "gbk")
var toGBK = open("gbk", "utf-8")

View File

@@ -1,4 +1,5 @@
import std/enumerate
import std/assertions
let a = @[1, 3, 5, 7]

View File

@@ -4,6 +4,7 @@ discard """
import std/enumutils
from std/sequtils import toSeq
import std/assertions
template main =
block: # items

View File

@@ -7,6 +7,7 @@ discard """
import std/envvars
from std/sequtils import toSeq
import stdtest/testutils
import std/assertions
# "LATIN CAPITAL LETTER AE" in UTF-8 (0xc386)
const unicodeUtf8 = "\xc3\x86"

View File

@@ -7,6 +7,9 @@ discard """
import os, osproc, strutils, nativesockets, net, selectors, memfiles,
asyncdispatch, asyncnet
import std/[assertions, syncio]
when defined(windows):
import winlean
@@ -56,7 +59,7 @@ proc isValidHandle(f: int): bool =
proc main() =
if paramCount() == 0:
# Parent process
let f = system.open("__test_fdleak", fmReadWrite)
let f = syncio.open("__test_fdleak", fmReadWrite)
defer: close f
leakCheck(f.getOsFileHandle, "system.open()")

View File

@@ -3,6 +3,7 @@ joinable: false
"""
import os, osproc, strutils
import std/assertions
const Iterations = 200

View File

@@ -1,4 +1,5 @@
import std/fenv
import std/assertions
func is_significant(x: float): bool =

View File

@@ -3,6 +3,7 @@ discard """
"""
import std/math
import std/assertions
const manualTest = false

View File

@@ -7,6 +7,7 @@ discard """
import std/genasts
import std/macros
from std/strformat import `&`
import std/assertions
import ./mgenast
proc main =

View File

@@ -6,6 +6,7 @@ discard """
# bug: https://github.com/nim-lang/Nim/issues/10198
import nativesockets
import std/assertions
block DGRAM_UDP:
let aiList = getAddrInfo("127.0.0.1", 999.Port, AF_INET, SOCK_DGRAM, IPPROTO_UDP)

View File

@@ -4,6 +4,7 @@ discard """
"""
import os, strutils
import std/syncio
# Cases
# 1 - String : Existing File : Symlink true
# 2 - String : Existing File : Symlink false

View File

@@ -1,4 +1,5 @@
import nativesockets
import std/assertions
doAssert getProtoByName("ipv6") == 41
doAssert getProtoByName("tcp") == 6

View File

@@ -1,4 +1,5 @@
import std/private/globs
import std/assertions
template main =
when defined(windows):

View File

@@ -4,6 +4,7 @@ discard """
import std/hashes
from stdtest/testutils import disableVm, whenVMorJs
import std/assertions
when not defined(js) and not defined(cpp):
block:

View File

@@ -1,5 +1,5 @@
import std/heapqueue
import std/assertions
proc toSortedSeq[T](h: HeapQueue[T]): seq[T] =
var tmp = h

View File

@@ -11,7 +11,7 @@ import htmlparser
import xmltree
import strutils
from streams import newStringStream
import std/assertions
block t2813:
const

View File

@@ -14,6 +14,8 @@ from net import TimeoutError
import nativesockets, os, httpclient, asyncdispatch
import std/[assertions, syncio]
const manualTests = false
proc makeIPv6HttpServer(hostname: string, port: Port,

View File

@@ -15,7 +15,7 @@ discard """
when not defined(windows):
# Disabled on Windows due to old OpenSSL version
import std/[formatfloat, syncio]
import
httpclient,
net,

View File

@@ -4,6 +4,8 @@ discard """
import asynchttpserver, httpclient, asyncdispatch, strutils, net
import std/assertions
block: # bug #16436
proc startServer(): AsyncHttpServer =
result = newAsyncHttpServer()

View File

@@ -1,4 +1,5 @@
import httpcore, strutils
import std/assertions
block:
block HttpCode:

View File

@@ -2,6 +2,7 @@
import std/os
from stdtest/specialpaths import buildDir
import std/[assertions, syncio]
block: # readChars
let file = buildDir / "D20201118T205105.txt"

View File

@@ -4,7 +4,7 @@ discard """
"""
import std/[isolation, json]
import std/[assertions, objectdollar]
proc main(moveZeroesOut: static bool) =

View File

@@ -2,7 +2,7 @@ discard """
targets: "js"
"""
import std/jsbigints
import std/[jsbigints, assertions]
let big1: JsBigInt = big"2147483647"

View File

@@ -14,6 +14,7 @@ when not defined(js):
import std/streams
import stdtest/testutils
from std/fenv import epsilon
import std/[assertions, objectdollar]
proc testRoundtrip[T](t: T, expected: string) =
# checks that `T => json => T2 => json2` is such that json2 = json

View File

@@ -4,6 +4,7 @@ discard """
"""
import json, strutils, options, tables
import std/assertions
# The definition of the `%` proc needs to be here, since the `% c` calls below
# can only find our custom `%` proc for `Pix` if defined in global scope.

View File

@@ -7,6 +7,7 @@ import std/json
from std/math import isNaN, signbit
from std/fenv import epsilon
from stdtest/testutils import whenRuntimeJs
import std/[assertions, objectdollar]
proc testRoundtrip[T](t: T, expected: string) =
# checks that `T => json => T2 => json2` is such that json2 = json

View File

@@ -3,6 +3,7 @@ discard """
"""
import std/[lists, sequtils]
import std/assertions
const
data = [1, 2, 3, 4, 5, 6]

View File

@@ -5,6 +5,7 @@ discard """
#bug #6049
import uselocks
import std/assertions
var m = createMyType[int]()
doAssert m.use() == 3

View File

@@ -5,6 +5,7 @@ See also:
]#
import std/macros
import std/assertions
block: # hasArgOfName
macro m(u: untyped): untyped =

View File

@@ -3,6 +3,7 @@ discard """
"""
import std/marshal
import std/[assertions, objectdollar]
# TODO: add static tests

View File

@@ -7,6 +7,8 @@ discard """
# but it requires disabling certain lines with `when not defined(nimTmathCase2)`
import std/math
import std/assertions
# Function for approximate comparison of floats
proc `==~`(x, y: float): bool = abs(x - y) < 1e-9

View File

@@ -3,6 +3,7 @@ discard """
"""
import md5
import std/assertions
proc main() {.raises: [].} =
doAssert(getMD5("Franz jagt im komplett verwahrlosten Taxi quer durch Bayern") ==

View File

@@ -1,4 +1,6 @@
import memfiles, os
import std/syncio
var
mm: MemFile
fn = "test.mmap"

View File

@@ -4,6 +4,9 @@ discard """
Half read size: 10 Data: Hello'''
"""
import memfiles, os
import std/syncio
const
fn = "test.mmap"
var

View File

@@ -1,4 +1,4 @@
import memfiles
import std/[memfiles, assertions]
var inp = memfiles.open("tests/stdlib/tmemlinesBuf.nim")
var buffer: string = ""
var lineCount = 0

View File

@@ -12,6 +12,8 @@ Readed line: Hello!
Position after reading line: 7'''
"""
import os, streams, memfiles
import std/syncio
const
fn = "test.mmapstream"
var

View File

@@ -1,3 +1,4 @@
import std/assertions
block: # cmpMem
type

View File

@@ -1,4 +1,5 @@
import std/mersenne
import std/assertions
template main() =
var mt = newMersenneTwister(2525)

View File

@@ -3,6 +3,9 @@ discard """
"""
import std/mimetypes
import std/assertions
template main() =
var m = newMimetypes()
doAssert m.getMimetype("mp4") == "video/mp4"

View File

@@ -2,6 +2,8 @@ discard """
targets: "c cpp js"
"""
import std/assertions
# bug #20227
type
Data = object

View File

@@ -3,6 +3,7 @@ discard """
"""
import std/[monotimes, times]
import std/assertions
let d = initDuration(nanoseconds = 10)
let t1 = getMonoTime()

View File

@@ -1,5 +1,6 @@
import std/nativesockets
import stdtest/testutils
import std/assertions
block:
let hostname = getHostname()

View File

@@ -4,6 +4,7 @@ outputsub: ""
import net, nativesockets
import unittest
import std/assertions
block: # isIpAddress tests
block: # 127.0.0.1 is valid

View File

@@ -5,6 +5,7 @@ discard """
"""
import os, net, nativesockets, asyncdispatch
import std/[assertions]
## Test for net.dial

View File

@@ -1,7 +1,5 @@
discard """
"""
import std/private/ntpath
import std/assertions
block: # From Python's `Lib/test/test_ntpath.py`
doAssert splitDrive(r"c:\foo\bar") == (r"c:", r"\foo\bar")

View File

@@ -3,7 +3,7 @@ discard """
"""
import std/oids
import std/assertions
block: # genOid
let x = genOid()

View File

@@ -1,5 +1,6 @@
import std/wordwrap
import openssl
import std/assertions
const PubKey = r"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAknKWvrdnncCIzBnIGrZ5qtZrPH+Yo3t7ag9WZIu6Gmc/JgIDDaZhJeyGW0YSnifeAEhooWvM4jDWhTEARzktalSHqYtmwI/1Oxwp6NTYH8akMe2LCpZ5pX9FVA6m9o2tkbdXatbDKRqeD4UA8Ow7Iyrdo6eb1SU8vk+26i+uXHTtsb25p8uf2ppO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b4hryvR9VDEolP+LMoiPe8AzBMeB5fP493TPdjtnWmrPCXNLc7UAFSj2CZsRhau4PuiqnNrsb5iz/7iXVl3E8wZvS4w7WYpO4m33L0cijA6MdcdqilQu4Z5tw4nG45lAW9UYyOc9D4hJTzgtGHhECgYA6QyDoj931brSoK0ocT+DB11Sj4utbOuberMaV8zgTSRhwodSl+WgdAUMMMDRacPcrBrgQiAMSZ15msqYZHEFhEa7Id8arFKvSXquTzf9iDKyJ0unzO/ThLjS3W+GxVNyrdufzA0tQ3IaKfOcDUrOpC7fdbtyrVqqSl4dF5MI9GwKBgQCl3OF6qyOEDDZgsUk1L59h7k3QR6VmBf4e9IeGUxZamvQlHjU/yY1nm1mjgGnbUB/SPKtqZKoMV6eBTVoNiuhQcItpGda9D3mnx+7p3T0/TBd+fJeuwcplfPDjrEktogcq5w/leQc3Ve7gr1EMcwb3r28f8/9L42QHQR/OKODs8QKBgQCFAvxDRPyYg7V/AgD9rt1KzXi4+b3Pls5NXZa2g/w+hmdhHUNxV5IGmHlqFnptGyshgYgQGxMMkW0iJ1j8nLamFnkbFQOp5/UKbdPLRKiB86oPpxsqYtPXucDUqEfcMsp57mD1CpGVODbspogFpSUvQpMECkhvI0XLMbolMdo53g=="

View File

@@ -4,8 +4,8 @@ discard """
import std/[json, options]
when defined(nimPreviewSlimSystem):
import std/objectdollar
import std/assertions
import std/objectdollar
# RefPerson is used to test that overloaded `==` operator is not called by

View File

@@ -28,6 +28,7 @@ Raises
import os, strutils, pathnorm
from stdtest/specialpaths import buildDir
import std/[syncio, assertions]
block fileOperations:
let files = @["these.txt", "are.x", "testing.r", "files.q"]

View File

@@ -4,6 +4,7 @@ discard """
# bug 10952, UNC paths
import os
import std/assertions
doAssert r"\\hostname\foo\bar" / "baz" == r"\\hostname\foo\bar\baz"
doAssert r"\\?\C:\foo" / "bar" == r"\\?\C:\foo\bar"

View File

@@ -7,6 +7,7 @@ discard """
import std/os
from std/sequtils import toSeq
import stdtest/testutils
import std/assertions
# "LATIN CAPITAL LETTER AE" in UTF-8 (0xc386)
const unicodeUtf8 = "\xc3\x86"

View File

@@ -9,6 +9,7 @@ because it'd need cleanup up stdout
see also: tests/osproc/*.nim; consider merging those into a single test here
(easier to factor and test more things as a single self contained test)
]#
import std/[assertions, syncio]
when defined(case_testfile): # compiled test file for child process
from posix import exitnow

View File

@@ -5,6 +5,7 @@ discard """
"""
import os, osproc, times, std / monotimes
import std/assertions
when defined(windows):
const ProgramWhichDoesNotEnd = "notepad"

View File

@@ -4,6 +4,8 @@ import std/sets
import sequtils
import algorithm
import std/assertions
block basicIntSetTests:
var y = initPackedSet[int]()
y.incl(1)

View File

@@ -3,6 +3,7 @@ discard """
"""
import parsecfg, streams, sequtils
import std/assertions
when not defined(js):
from stdtest/specialpaths import buildDir

View File

@@ -1,5 +1,6 @@
include parsecsv
import strutils, os
import std/assertions
block: # Tests for reading the header row
let content = "\nOne,Two,Three,Four\n1,2,3,4\n10,20,30,40,\n100,200,300,400\n"

View File

@@ -2,6 +2,7 @@ discard """
targets: "c js"
"""
import parsesql
import std/assertions
doAssert treeRepr(parseSql("INSERT INTO STATS VALUES (10, 5.5); ")
) == """

View File

@@ -1,4 +1,5 @@
import std/[parseutils, sequtils, sugar]
import std/[parseutils, sequtils, sugar, formatfloat]
import std/assertions
let input = "$test{} $this is ${an{ example}} "

View File

@@ -9,6 +9,8 @@ disabled: true
import
parseopt
import std/[assertions, syncio]
proc writeHelp() =
writeLine(stdout, "Usage: tparsopt [options] filename [options]")

View File

@@ -2,6 +2,7 @@ discard """
"""
import std/os
import std/assertions
when doslikeFileSystem:
import std/pathnorm

View File

@@ -54,7 +54,7 @@ Event parser output
when defined(nimHasEffectsOf):
{.experimental: "strictEffects".}
import std/[strutils, streams, pegs]
import std/[strutils, streams, pegs, assertions]
const
indent = " "

View File

@@ -7,6 +7,7 @@ outputsub: ""
when not defined(windows):
import posix
import std/syncio
var
u: Utsname

View File

@@ -8,6 +8,8 @@ when defined nimTestTpreludeCase1:
else:
include prelude
import std/assertions
template main() =
doAssert toSeq(1..3) == @[1,2,3]
static: main()

View File

@@ -1,4 +1,5 @@
import punycode, std/unicode
import std/assertions
doAssert(decode(encode("", "bücher")) == "bücher")
doAssert(decode(encode("münchen")) == "münchen")

View File

@@ -7,6 +7,8 @@ joinable: false
# Test `addQuitProc` (now deprecated by `addExitProc`)
import std/syncio
proc myExit() {.noconv.} =
write(stdout, "just exiting...\n")

View File

@@ -2,7 +2,7 @@ discard """
joinable: false # to avoid messing with global rand state
targets: "c js"
"""
import std/[assertions, formatfloat]
import std/[random, math, stats, sets, tables]
when not defined(js):
import std/os

View File

@@ -1,4 +1,5 @@
import std/[rationals, math]
import std/assertions
template main() =
var

View File

@@ -1,4 +1,5 @@
import std/re
import std/assertions
proc testAll() =
doAssert match("(a b c)", rex"\( .* \)")

View File

@@ -11,7 +11,7 @@ when defined(powerpc64):
else:
import
re
import std/syncio
if "keyA = valueA" =~ re"\s*(\w+)\s*\=\s*(\w+)":
write(stdout, "key: ", matches[0])
elif "# comment!" =~ re.re"\s*(\#.*)":

View File

@@ -5,6 +5,7 @@ discard """
when defined(windows):
import std/registry
import std/assertions
block: # bug #14010
let path = "Environment"

View File

@@ -7,6 +7,7 @@ discard """
from strutils import endsWith, contains, strip
from std/macros import newLit
import std/assertions
macro deb(a): string = newLit a.repr.strip
macro debTyped(a: typed): string = newLit a.repr.strip

View File

@@ -3,6 +3,7 @@ discard """
"""
import std/ropes
import std/assertions
template main() =
block:

Some files were not shown because too many files have changed in this diff Show More