Instance env_remove

This commit is contained in:
ridiculousfish 2018-09-10 20:57:10 -07:00
parent ede66ccaac
commit a00de96a57
4 changed files with 8 additions and 19 deletions

View File

@ -652,7 +652,7 @@ static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
} }
if (idx_count == 0) { // unset the var if (idx_count == 0) { // unset the var
retval = env_remove(dest, scope); retval = parser.vars().remove(dest, scope);
// Temporarily swallowing ENV_NOT_FOUND errors to prevent // Temporarily swallowing ENV_NOT_FOUND errors to prevent
// breaking all tests that unset variables that aren't set. // breaking all tests that unset variables that aren't set.
if (retval != ENV_NOT_FOUND) { if (retval != ENV_NOT_FOUND) {

View File

@ -1435,8 +1435,6 @@ int env_set_empty(const wcstring &key, env_mode_flags_t mode) {
return env_stack_t::principal().set_empty(key, mode); return env_stack_t::principal().set_empty(key, mode);
} }
int env_remove(const wcstring &key, int mode) { return env_stack_t::principal().remove(key, mode); }
void env_universal_barrier() { env_stack_t::principal().universal_barrier(); } void env_universal_barrier() { env_stack_t::principal().universal_barrier(); }
wcstring env_get_pwd_slash() { return env_stack_t::principal().get_pwd_slash(); } wcstring env_get_pwd_slash() { return env_stack_t::principal().get_pwd_slash(); }

View File

@ -155,16 +155,6 @@ int env_set_one(const wcstring &key, env_mode_flags_t mode, wcstring val);
/// Sets the variable with the specified name to no values. /// Sets the variable with the specified name to no values.
int env_set_empty(const wcstring &key, env_mode_flags_t mode); int env_set_empty(const wcstring &key, env_mode_flags_t mode);
/// Remove environment variable.
///
/// \param key The name of the variable to remove
/// \param mode should be ENV_USER if this is a remove request from the user, 0 otherwise. If this
/// is a user request, read-only variables can not be removed. The mode may also specify the scope
/// of the variable that should be erased.
///
/// \return zero if the variable existed, and non-zero if the variable did not exist
int env_remove(const wcstring &key, int mode);
/// Synchronizes all universal variable changes: writes everything out, reads stuff in. /// Synchronizes all universal variable changes: writes everything out, reads stuff in.
void env_universal_barrier(); void env_universal_barrier();

View File

@ -2762,7 +2762,7 @@ static void test_autosuggest_suggest_special() {
perform_one_completion_cd_test(L"cd ~haha", L"ha/", __LINE__); perform_one_completion_cd_test(L"cd ~haha", L"ha/", __LINE__);
perform_one_completion_cd_test(L"cd ~hahaha/", L"path1/", __LINE__); perform_one_completion_cd_test(L"cd ~hahaha/", L"path1/", __LINE__);
env_remove(L"HOME", ENV_LOCAL | ENV_EXPORT); parser_t::principal_parser().vars().remove(L"HOME", ENV_LOCAL | ENV_EXPORT);
popd(); popd();
} }
@ -4284,9 +4284,10 @@ static void test_highlighting() {
{L"self%not", highlight_spec_param}, {L"self%not", highlight_spec_param},
}); });
auto &vars = parser_t::principal_parser().vars();
// Verify variables and wildcards in commands using /bin/cat. // Verify variables and wildcards in commands using /bin/cat.
env_set(L"VARIABLE_IN_COMMAND", ENV_LOCAL, {L"a"}); vars.set(L"VARIABLE_IN_COMMAND", ENV_LOCAL, {L"a"});
env_set(L"VARIABLE_IN_COMMAND2", ENV_LOCAL, {L"at"}); vars.set(L"VARIABLE_IN_COMMAND2", ENV_LOCAL, {L"at"});
highlight_tests.push_back( highlight_tests.push_back(
{{L"/bin/ca", highlight_spec_command, ns}, {L"*", highlight_spec_operator, ns}}); {{L"/bin/ca", highlight_spec_command, ns}, {L"*", highlight_spec_operator, ns}});
@ -4319,7 +4320,7 @@ static void test_highlighting() {
do_test(expected_colors.size() == text.size()); do_test(expected_colors.size() == text.size());
std::vector<highlight_spec_t> colors(text.size()); std::vector<highlight_spec_t> colors(text.size());
highlight_shell(text, colors, 20, NULL, env_vars_snapshot_t::current()); highlight_shell(text, colors, 20, NULL, vars);
if (expected_colors.size() != colors.size()) { if (expected_colors.size() != colors.size()) {
err(L"Color vector has wrong size! Expected %lu, actual %lu", expected_colors.size(), err(L"Color vector has wrong size! Expected %lu, actual %lu", expected_colors.size(),
@ -4338,8 +4339,8 @@ static void test_highlighting() {
} }
} }
} }
env_remove(L"VARIABLE_IN_COMMAND", ENV_DEFAULT); vars.remove(L"VARIABLE_IN_COMMAND", ENV_DEFAULT);
env_remove(L"VARIABLE_IN_COMMAND2", ENV_DEFAULT); vars.remove(L"VARIABLE_IN_COMMAND2", ENV_DEFAULT);
} }
static void test_wcstring_tok() { static void test_wcstring_tok() {