mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
AutoTest does not build on windows due to missing 'setenv', add SetEnv function (#140)
This commit is contained in:
parent
571ac7f000
commit
0d258e9104
5 changed files with 48 additions and 2 deletions
22
autotest/SetEnvVar/SetEnvVar.cpp
Normal file
22
autotest/SetEnvVar/SetEnvVar.cpp
Normal 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");
|
||||
}
|
||||
9
autotest/SetEnvVar/SetEnvVar.upp
Normal file
9
autotest/SetEnvVar/SetEnvVar.upp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
SetEnvVar.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
String GetEnv(const char *id);
|
||||
bool SetEnv(const char *name, const char *value);
|
||||
|
||||
String GetExeFilePath();
|
||||
String GetExeTitle();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue