AutoTest does not build on windows due to missing 'setenv', add SetEnv function (#140)

This commit is contained in:
Tomas Lindquist 2023-01-24 10:54:05 +01:00 committed by GitHub
parent 571ac7f000
commit 0d258e9104
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 2 deletions

View file

@ -0,0 +1,22 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
String cmd, out;
#ifdef PLATFORM_WIN32
cmd = "cmd /C \"echo 1 %FOOBAR% 2\"";
ASSERT(Sys(cmd) == "1 %FOOBAR% 2\r\n");
SetEnv("FOOBAR","BAZ");
ASSERT(Sys(cmd) == "1 BAZ 2\r\n");
#else
cmd = "echo \"1 $FOOBAR 2\"";
ASSERT(Sys(cmd) == "1 2\n");
SetEnv("FOOBAR","BAZ");
ASSERT(Sys(cmd) == "1 BAZ 2\n");
#endif
ASSERT(GetEnv("FOOBAR") == "BAZ");
}

View file

@ -0,0 +1,9 @@
uses
Core;
file
SetEnvVar.cpp;
mainconfig
"" = "";

View file

@ -63,8 +63,8 @@ void Do(const char *nest, const char *bm, bool release, bool test)
if(test) {
Tested++;
LocalProcess p;
setenv("UPP_MAIN__", ff.GetPath(), 1);
setenv("UPP_ASSEMBLY__", GetFileFolder(ff.GetPath()), 1);
SetEnv("UPP_MAIN__", ff.GetPath());
SetEnv("UPP_ASSEMBLY__", GetFileFolder(ff.GetPath()));
if(!p.Start(exe)) {
Cout() << "FAILED TO RUN\n";
infolog << ", FAILED TO RUN";

View file

@ -69,6 +69,15 @@ String GetEnv(const char *id)
return WString(_wgetenv(ToSystemCharsetW(id))).ToString();
}
bool SetEnv(const char *name, const char *value)
{
String env;
env << name << "=" << value;
auto wenv = ToUtf16(env);
wenv.Add(wchar_t(0));
return _wputenv(wenv.begin()) == 0;
}
String GetExeFilePath()
{
return GetModuleFileName();
@ -83,6 +92,11 @@ String GetEnv(const char *id)
return FromSystemCharset(getenv(id));
}
bool SetEnv(const char *name, const char *value)
{
return setenv(name, value, 1) == 0;
}
static void sSetArgv0__(const char *title)
{
strcpy(Argv0__, title);

View file

@ -1,4 +1,5 @@
String GetEnv(const char *id);
bool SetEnv(const char *name, const char *value);
String GetExeFilePath();
String GetExeTitle();