Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions test/helpers/test_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ bool TestConfiguration::TryParseOption(const string &name, const Value &value) {
test_config.on_set_option(parameter);
}
options.insert(make_pair(test_config.name, parameter));
if (StringUtil::CIEquals(test_config.name, "test_env")) {
test_env_from_config_loaded = false;
test_env_from_config_keys.clear();
}
return true;
}

Expand Down Expand Up @@ -423,6 +427,26 @@ void TestConfiguration::LoadConfig(const string &config_path) {
}
}

void TestConfiguration::LoadTestEnvFromConfig() {
if (test_env_from_config_loaded) {
return;
}
test_env_from_config_loaded = true;
test_env_from_config_keys.clear();
auto entry = options.find("test_env");
if (entry == options.end()) {
return;
}
auto list_children = ListValue::GetChildren(entry->second);
for (const auto &value : list_children) {
auto &struct_children = StructValue::GetChildren(value);
auto &env = StringValue::Get(struct_children[0]);
auto &env_value = StringValue::Get(struct_children[1]);
test_env_from_config_keys.insert(env);
test_env[env] = env_value;
}
}

void TestConfiguration::ProcessPath(string &path, const string &test_name) {
path = StringUtil::Replace(path, "{TEST_DIR}", TestDirectoryPath());
path = StringUtil::Replace(path, "{UUID}", UUID::ToString(UUID::GenerateRandomUUID()));
Expand Down Expand Up @@ -512,24 +536,20 @@ vector<ConfigSetting> TestConfiguration::GetConfigSettings() {
}

string TestConfiguration::GetTestEnv(const string &key, const string &default_value) {
if (!test_env_from_config_loaded && options.find("test_env") != options.end()) {
test_env_from_config_loaded = true;
auto entry = options["test_env"];
auto list_children = ListValue::GetChildren(entry);
for (const auto &value : list_children) {
auto &struct_children = StructValue::GetChildren(value);
auto &env = StringValue::Get(struct_children[0]);
auto &env_value = StringValue::Get(struct_children[1]);
test_env[env] = env_value;
}
}
LoadTestEnvFromConfig();
if (test_env.find(key) == test_env.end()) {
return default_value;
}
return test_env[key];
}

bool TestConfiguration::HasTestEnv(const string &key) {
LoadTestEnvFromConfig();
return test_env_from_config_keys.find(key) != test_env_from_config_keys.end();
}

const unordered_map<string, string> &TestConfiguration::GetTestEnvMap() {
LoadTestEnvFromConfig();
return test_env;
}

Expand Down
4 changes: 4 additions & 0 deletions test/include/test_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class TestConfiguration {
vector<string> ErrorMessagesToBeSkipped();
string GetStorageVersion();
string GetTestEnv(const string &key, const string &default_value);
bool HasTestEnv(const string &key);
const unordered_map<string, string> &GetTestEnvMap();
vector<unordered_set<string>> GetSelectTagSets();
vector<unordered_set<string>> GetSkipTagSets();
Expand All @@ -97,8 +98,11 @@ class TestConfiguration {
static void AppendSkipTagSet(const Value &tag_set);

private:
void LoadTestEnvFromConfig();

//! Give preference to settings from loaded configs
bool test_env_from_config_loaded = false;
unordered_set<string> test_env_from_config_keys;
case_insensitive_map_t<Value> options;
unordered_set<string> tests_to_be_skipped;

Expand Down
10 changes: 6 additions & 4 deletions test/sqlite/sqllogic_test_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,10 +1114,12 @@ void SQLLogicTestRunner::ExecuteFile(string script) {

auto &test_config = TestConfiguration::Get();
auto env_var = token.parameters[0];
auto test_env_result = test_config.GetTestEnv(env_var, "");
auto test_env_defined = test_config.HasTestEnv(env_var);
string env_actual_value;
const char *env_actual = nullptr;
if (!test_env_result.empty()) {
env_actual = test_env_result.c_str();
if (test_env_defined) {
env_actual_value = test_config.GetTestEnv(env_var, "");
env_actual = env_actual_value.c_str();
} else {
env_actual = std::getenv(env_var.c_str());
}
Expand Down Expand Up @@ -1147,7 +1149,7 @@ void SQLLogicTestRunner::ExecuteFile(string script) {
file_tags.emplace_back(StringUtil::Format("env[%s]=%s", token.parameters[0], token.parameters[1]));
}

if (environment_variables.count(env_var)) {
if (!test_env_defined && environment_variables.count(env_var)) {
parser.Fail(StringUtil::Format("Environment variable '%s' has already been defined", env_var));
}
environment_variables[env_var] = env_actual;
Expand Down
Loading