fix bugs in shell putenv and getenv style variables. add more unit tests.
This commit is contained in:
@ -1250,9 +1250,9 @@ void Input::shell()
|
|||||||
for (int i = 1; i < narg; i++) {
|
for (int i = 1; i < narg; i++) {
|
||||||
rv = 0;
|
rv = 0;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (arg[i]) rv = _putenv(arg[i]);
|
if (arg[i]) rv = _putenv(utils::strdup(arg[i]));
|
||||||
#else
|
#else
|
||||||
if (arg[i]) rv = putenv(arg[i]);
|
if (arg[i]) rv = putenv(utils::strdup(arg[i]));
|
||||||
#endif
|
#endif
|
||||||
rv = (rv < 0) ? errno : 0;
|
rv = (rv < 0) ? errno : 0;
|
||||||
MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world);
|
MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world);
|
||||||
|
|||||||
@ -341,8 +341,7 @@ void Variable::set(int narg, char **arg)
|
|||||||
which[nvar] = 0;
|
which[nvar] = 0;
|
||||||
pad[nvar] = 0;
|
pad[nvar] = 0;
|
||||||
data[nvar] = new char*[num[nvar]];
|
data[nvar] = new char*[num[nvar]];
|
||||||
copy(1,&arg[2],data[nvar]);
|
data[nvar][0] = utils::strdup(arg[2]);
|
||||||
data[nvar][1] = utils::strdup("(undefined)");
|
|
||||||
|
|
||||||
// SCALARFILE for strings or numbers
|
// SCALARFILE for strings or numbers
|
||||||
// which = 1st value
|
// which = 1st value
|
||||||
|
|||||||
@ -20,8 +20,8 @@
|
|||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "variable.h"
|
||||||
|
|
||||||
#include "fmt/format.h"
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "../testing/core.h"
|
#include "../testing/core.h"
|
||||||
@ -398,6 +398,7 @@ TEST_F(SimpleCommandsTest, Shell)
|
|||||||
{
|
{
|
||||||
BEGIN_HIDE_OUTPUT();
|
BEGIN_HIDE_OUTPUT();
|
||||||
command("shell putenv TEST_VARIABLE=simpletest");
|
command("shell putenv TEST_VARIABLE=simpletest");
|
||||||
|
command("variable simple1 getenv TEST_VARIABLE");
|
||||||
END_HIDE_OUTPUT();
|
END_HIDE_OUTPUT();
|
||||||
|
|
||||||
char *test_var = getenv("TEST_VARIABLE");
|
char *test_var = getenv("TEST_VARIABLE");
|
||||||
@ -405,18 +406,22 @@ TEST_F(SimpleCommandsTest, Shell)
|
|||||||
ASSERT_THAT(test_var, StrEq("simpletest"));
|
ASSERT_THAT(test_var, StrEq("simpletest"));
|
||||||
|
|
||||||
BEGIN_HIDE_OUTPUT();
|
BEGIN_HIDE_OUTPUT();
|
||||||
command("shell putenv TEST_VARIABLE=simpletest");
|
command("shell putenv TEST_VARIABLE=simpletest2");
|
||||||
command("shell putenv TEST_VARIABLE2=simpletest2 OTHER_VARIABLE=2");
|
command("shell putenv TEST_VARIABLE2=simpletest OTHER_VARIABLE=2");
|
||||||
END_HIDE_OUTPUT();
|
END_HIDE_OUTPUT();
|
||||||
|
|
||||||
char *test_var2 = getenv("TEST_VARIABLE2");
|
char *test_var2 = getenv("TEST_VARIABLE2");
|
||||||
char *other_var = getenv("OTHER_VARIABLE");
|
char *other_var = getenv("OTHER_VARIABLE");
|
||||||
|
|
||||||
ASSERT_NE(test_var2, nullptr);
|
ASSERT_NE(test_var2, nullptr);
|
||||||
ASSERT_THAT(test_var2, StrEq("simpletest2"));
|
ASSERT_THAT(test_var2, StrEq("simpletest"));
|
||||||
|
|
||||||
ASSERT_NE(other_var, nullptr);
|
ASSERT_NE(other_var, nullptr);
|
||||||
ASSERT_THAT(other_var, StrEq("2"));
|
ASSERT_THAT(other_var, StrEq("2"));
|
||||||
|
|
||||||
|
test_var = getenv("TEST_VARIABLE");
|
||||||
|
ASSERT_NE(test_var, nullptr);
|
||||||
|
ASSERT_THAT(test_var, StrEq("simpletest2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SimpleCommandsTest, CiteMe)
|
TEST_F(SimpleCommandsTest, CiteMe)
|
||||||
|
|||||||
@ -122,6 +122,8 @@ TEST_F(VariableTest, CreateDelete)
|
|||||||
file_vars();
|
file_vars();
|
||||||
ASSERT_EQ(variable->nvar, 1);
|
ASSERT_EQ(variable->nvar, 1);
|
||||||
BEGIN_HIDE_OUTPUT();
|
BEGIN_HIDE_OUTPUT();
|
||||||
|
command("shell putenv TEST_VARIABLE=simpletest2");
|
||||||
|
command("shell putenv TEST_VARIABLE2=simpletest OTHER_VARIABLE=2");
|
||||||
command("variable one index 1 2 3 4");
|
command("variable one index 1 2 3 4");
|
||||||
command("variable two equal 1");
|
command("variable two equal 1");
|
||||||
command("variable two equal 2");
|
command("variable two equal 2");
|
||||||
@ -133,8 +135,8 @@ TEST_F(VariableTest, CreateDelete)
|
|||||||
command("variable five2 loop 10 200 pad");
|
command("variable five2 loop 10 200 pad");
|
||||||
command("variable six world one");
|
command("variable six world one");
|
||||||
command("variable seven format two \"%5.2f\"");
|
command("variable seven format two \"%5.2f\"");
|
||||||
command("variable eight getenv PWD");
|
command("variable eight getenv TEST_VARIABLE2");
|
||||||
command("variable eight getenv XXXXX");
|
command("variable eight getenv XXX");
|
||||||
command("variable nine file test_variable.file");
|
command("variable nine file test_variable.file");
|
||||||
command("variable ten internal 1.0");
|
command("variable ten internal 1.0");
|
||||||
command("variable ten internal 10.0");
|
command("variable ten internal 10.0");
|
||||||
@ -167,6 +169,14 @@ TEST_F(VariableTest, CreateDelete)
|
|||||||
unlink("MYFILE");
|
unlink("MYFILE");
|
||||||
ASSERT_THAT(variable->retrieve("file"), StrEq("0"));
|
ASSERT_THAT(variable->retrieve("file"), StrEq("0"));
|
||||||
|
|
||||||
|
BEGIN_HIDE_OUTPUT();
|
||||||
|
command("variable seven delete");
|
||||||
|
command("variable seven getenv TEST_VARIABLE");
|
||||||
|
command("variable eight getenv OTHER_VARIABLE");
|
||||||
|
END_HIDE_OUTPUT();
|
||||||
|
ASSERT_THAT(variable->retrieve("seven"), StrEq("simpletest2"));
|
||||||
|
ASSERT_THAT(variable->retrieve("eight"), StrEq("2"));
|
||||||
|
|
||||||
ASSERT_EQ(variable->equalstyle(variable->find("one")), 0);
|
ASSERT_EQ(variable->equalstyle(variable->find("one")), 0);
|
||||||
ASSERT_EQ(variable->equalstyle(variable->find("two")), 1);
|
ASSERT_EQ(variable->equalstyle(variable->find("two")), 1);
|
||||||
ASSERT_EQ(variable->equalstyle(variable->find("ten")), 1);
|
ASSERT_EQ(variable->equalstyle(variable->find("ten")), 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user