From 14f580680438fb6f1b099ce6b9bd3d3426e4d9f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Mjaavatten?= Date: Mon, 25 Jul 2022 12:45:49 +0200 Subject: [PATCH] Fix test issues Fixes * `nim cpp` didn't compile the tests * Nimscript import of `tosenv.nim` from `test_nimscript.nims` failed with "cannot importc" --- tests/stdlib/tenvvars.nim | 12 ++++++++---- tests/stdlib/tosenv.nim | 14 +++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/stdlib/tenvvars.nim b/tests/stdlib/tenvvars.nim index ce8a7a1eb2..41db22bd03 100644 --- a/tests/stdlib/tenvvars.nim +++ b/tests/stdlib/tenvvars.nim @@ -47,9 +47,9 @@ template main = main() +when defined(windows): + proc c_wgetenv(env: WideCString): WideCString {.importc: "_wgetenv", header: "".} proc c_getenv(env: cstring): cstring {.importc: "getenv", header: "".} -proc c_wgetenv(env: WideCString): WideCString {.importc: "_wgetenv", header: "".} -proc c_wputenv(env: WideCString): int32 {.importc: "_wputenv", header: "".} when not defined(js) and not defined(nimscript): block: # bug #18533 @@ -60,7 +60,10 @@ when not defined(js) and not defined(nimscript): doAssert getEnv("foo") == "fooVal1" createThread(thr, threadFunc) joinThreads(thr) - doAssert getEnv("foo") == $c_wgetenv("foo".newWideCString) + when defined(windows): + doAssert getEnv("foo") == $c_wgetenv("foo".newWideCString) + else: + doAssert getEnv("foo") == $c_getenv("foo".cstring) doAssertRaises(OSError): delEnv("foo=bar") @@ -69,12 +72,13 @@ when defined(windows): LC_ALL = 0 unicodeAnsi = "\xc6" # `unicodeUtf8` in `windows-1252` encoding + proc c_wputenv(env: WideCString): int32 {.importc: "_wputenv", header: "".} proc setlocale(category: cint, locale: cstring): cstring {.importc, header: "".} # Set locale required to represent `unicodeAnsi` discard setlocale(LC_ALL, cstring"English_United States.1252") - block: # Feature #xxx + block: # Bug #20083 # These test that `getEnv`, `putEnv` and `existsEnv` handle Unicode # characters correctly. This means that module X in the process calling the # CRT environment variable API will get the correct string. Raw CRT API diff --git a/tests/stdlib/tosenv.nim b/tests/stdlib/tosenv.nim index 4d0acff391..2eb0e44eca 100644 --- a/tests/stdlib/tosenv.nim +++ b/tests/stdlib/tosenv.nim @@ -48,9 +48,9 @@ template main = static: main() main() +when defined(windows): + proc c_wgetenv(env: WideCString): WideCString {.importc: "_wgetenv", header: "".} proc c_getenv(env: cstring): cstring {.importc: "getenv", header: "".} -proc c_wgetenv(env: WideCString): WideCString {.importc: "_wgetenv", header: "".} -proc c_wputenv(env: WideCString): int32 {.importc: "_wputenv", header: "".} when not defined(js) and not defined(nimscript): block: # bug #18533 @@ -61,21 +61,25 @@ when not defined(js) and not defined(nimscript): doAssert getEnv("foo") == "fooVal1" createThread(thr, threadFunc) joinThreads(thr) - doAssert getEnv("foo") == $c_wgetenv("foo".newWideCString) + when defined(windows): + doAssert getEnv("foo") == $c_wgetenv("foo".newWideCString) + else: + doAssert getEnv("foo") == $c_getenv("foo".cstring) doAssertRaises(OSError): delEnv("foo=bar") -when defined(windows): +when defined(windows) and not defined(nimscript): const LC_ALL = 0 unicodeAnsi = "\xc6" # `unicodeUtf8` in `windows-1252` encoding + proc c_wputenv(env: WideCString): int32 {.importc: "_wputenv", header: "".} proc setlocale(category: cint, locale: cstring): cstring {.importc, header: "".} # Set locale required to represent `unicodeAnsi` discard setlocale(LC_ALL, cstring"English_United States.1252") - block: # Feature #xxx + block: # Bug #20083 # These test that `getEnv`, `putEnv` and `existsEnv` handle Unicode # characters correctly. This means that module X in the process calling the # CRT environment variable API will get the correct string. Raw CRT API