From 34cf84fa681db7f8e0c0aba88557effa5099fb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 8 Apr 2019 13:31:31 +0300 Subject: [PATCH] crt-test: Test putenv and the environ variable --- test/crt-test.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/crt-test.c b/test/crt-test.c index 5244f8f..84a4908 100644 --- a/test/crt-test.c +++ b/test/crt-test.c @@ -31,6 +31,10 @@ #include #endif +#ifndef _WIN32 +extern char **environ; +#endif + #ifdef _WIN32 static void invalid_parameter(const wchar_t *expression, const wchar_t *function, const wchar_t *file, unsigned int line, uintptr_t pReserved) { } @@ -183,6 +187,27 @@ int main(int argc, char* argv[]) { TEST_INT(strtol("foo", NULL, 100), 0); TEST_INT(errno, EINVAL); + int env_ok = 0; + putenv("CRT_TEST_VAR=1"); + for (char **ptr = environ; *ptr; ptr++) + if (!strcmp(*ptr, "CRT_TEST_VAR=1")) + env_ok = 1; + if (!env_ok) { + fails++; + printf("Variable set by putenv not found found in environ\n"); + } + tests++; + env_ok = 0; + putenv("CRT_TEST_VAR=2"); + for (char **ptr = environ; *ptr; ptr++) + if (!strcmp(*ptr, "CRT_TEST_VAR=2")) + env_ok = 1; + if (!env_ok) { + fails++; + printf("Variable updated by putenv not found found in environ\n"); + } + tests++; + TEST_FLT(floor(F(3.9)), 3.0); TEST_FLT(floor(F(17179869184.0)), 17179869184.0); TEST_FLT(floor(F(-3.3)), -4.0);