envPairs works in vm, nims (#18615)

* envPairs works in vm, nims

* fixup
This commit is contained in:
Timothee Cour 2021-09-29 00:32:39 -07:00 • committed by GitHub
commit f061971a9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 213 additions and 210 deletions

View file

@ -1,3 +1,5 @@
# xxx consider merging this in tests/stdlib/tos.nim for increased coverage (with selecting disabling)
static: doAssert defined(nodejs)
import os
@ -19,29 +21,3 @@ block:
if not isWindows:
doAssert cwd.isAbsolute
doAssert relativePath(getCurrentDir() / "foo", "bar") == "../foo"
import std/sequtils
template main =
putEnv("foo", "bar")
doAssert getEnv("foo") == "bar"
doAssert existsEnv("foo")
putEnv("foo", "")
doAssert existsEnv("foo")
putEnv("foo", "bar2")
doAssert getEnv("foo") == "bar2"
when nimvm:
discard
else:
# need support in vmops: envPairs, delEnv
let s = toSeq(envPairs())
doAssert ("foo", "bar2") in s
doAssert ("foo", "bar") notin s
delEnv("foo")
doAssert not existsEnv("foo")
static: main()
main()

View file

@ -13,16 +13,18 @@ template main =
for val in ["val", ""]: # ensures empty val works too
const key = "NIM_TESTS_TOSENV_KEY"
doAssert not existsEnv(key)
putEnv(key, val)
putEnv(key, "tempval")
doAssert existsEnv(key)
doAssert getEnv(key) == "tempval"
putEnv(key, val) # change a key that already exists
doAssert existsEnv(key)
doAssert getEnv(key) == val
when nimvm: discard
else:
doAssert (key, val) in toSeq(envPairs())
doAssert (key, val) in toSeq(envPairs())
delEnv(key)
when nimvm: discard
else:
doAssert (key, val) notin toSeq(envPairs())
doAssert (key, val) notin toSeq(envPairs())
doAssert not existsEnv(key)
delEnv(key) # deleting an already deleted env var
doAssert not existsEnv(key)
@ -43,7 +45,7 @@ template main =
static: main()
main()
when not defined(js):
when not defined(js) and not defined(nimscript):
block: # bug #18533
proc c_getenv(env: cstring): cstring {.importc: "getenv", header: "<stdlib.h>".}
var thr: Thread[void]

View file

@ -71,7 +71,11 @@ import std/[
decls, compilesettings, with, wrapnils
]
# non-std imports
import stdtest/testutils
# tests (increase coverage via code reuse)
import stdlib/trandom
import stdlib/tosenv
echo "Nimscript imports are successful."