fix bugs in shell putenv and getenv style variables. add more unit tests.

This commit is contained in:
Axel Kohlmeyer
2021-04-09 20:19:04 -04:00
parent 08471cb88e
commit a69c5a5cae
4 changed files with 24 additions and 10 deletions

View File

@ -20,8 +20,8 @@
#include "output.h"
#include "update.h"
#include "utils.h"
#include "variable.h"
#include "fmt/format.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
@ -398,6 +398,7 @@ TEST_F(SimpleCommandsTest, Shell)
{
BEGIN_HIDE_OUTPUT();
command("shell putenv TEST_VARIABLE=simpletest");
command("variable simple1 getenv TEST_VARIABLE");
END_HIDE_OUTPUT();
char *test_var = getenv("TEST_VARIABLE");
@ -405,18 +406,22 @@ TEST_F(SimpleCommandsTest, Shell)
ASSERT_THAT(test_var, StrEq("simpletest"));
BEGIN_HIDE_OUTPUT();
command("shell putenv TEST_VARIABLE=simpletest");
command("shell putenv TEST_VARIABLE2=simpletest2 OTHER_VARIABLE=2");
command("shell putenv TEST_VARIABLE=simpletest2");
command("shell putenv TEST_VARIABLE2=simpletest OTHER_VARIABLE=2");
END_HIDE_OUTPUT();
char *test_var2 = getenv("TEST_VARIABLE2");
char *other_var = getenv("OTHER_VARIABLE");
ASSERT_NE(test_var2, nullptr);
ASSERT_THAT(test_var2, StrEq("simpletest2"));
ASSERT_THAT(test_var2, StrEq("simpletest"));
ASSERT_NE(other_var, nullptr);
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)

View File

@ -122,6 +122,8 @@ TEST_F(VariableTest, CreateDelete)
file_vars();
ASSERT_EQ(variable->nvar, 1);
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 two equal 1");
command("variable two equal 2");
@ -133,8 +135,8 @@ TEST_F(VariableTest, CreateDelete)
command("variable five2 loop 10 200 pad");
command("variable six world one");
command("variable seven format two \"%5.2f\"");
command("variable eight getenv PWD");
command("variable eight getenv XXXXX");
command("variable eight getenv TEST_VARIABLE2");
command("variable eight getenv XXX");
command("variable nine file test_variable.file");
command("variable ten internal 1.0");
command("variable ten internal 10.0");
@ -167,6 +169,14 @@ TEST_F(VariableTest, CreateDelete)
unlink("MYFILE");
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("two")), 1);
ASSERT_EQ(variable->equalstyle(variable->find("ten")), 1);