Instantize env_get

This removes env_get(). All fish variable accesses must go through an
environment_t.
This commit is contained in:
ridiculousfish
2018-09-25 00:17:05 -04:00
parent b98812dd1a
commit 77884bc21a
11 changed files with 44 additions and 60 deletions

View File

@@ -1787,59 +1787,62 @@ static void test_abbreviations() {
if (ret != 0) err(L"Unable to set abbreviation variable");
}
if (expand_abbreviation(L"")) err(L"Unexpected success with empty abbreviation");
if (expand_abbreviation(L"nothing")) err(L"Unexpected success with missing abbreviation");
if (expand_abbreviation(L"", vars)) err(L"Unexpected success with empty abbreviation");
if (expand_abbreviation(L"nothing", vars)) err(L"Unexpected success with missing abbreviation");
auto mresult = expand_abbreviation(L"gc");
auto mresult = expand_abbreviation(L"gc", vars);
if (!mresult) err(L"Unexpected failure with gc abbreviation");
if (*mresult != L"git checkout") err(L"Wrong abbreviation result for gc");
mresult = expand_abbreviation(L"foo");
mresult = expand_abbreviation(L"foo", vars);
if (!mresult) err(L"Unexpected failure with foo abbreviation");
if (*mresult != L"bar") err(L"Wrong abbreviation result for foo");
bool expanded;
wcstring result;
expanded = reader_expand_abbreviation_in_command(L"just a command", 3, &result);
expanded = reader_expand_abbreviation_in_command(L"just a command", 3, vars, &result);
if (expanded) err(L"Command wrongly expanded on line %ld", (long)__LINE__);
expanded = reader_expand_abbreviation_in_command(L"gc somebranch", 0, &result);
expanded = reader_expand_abbreviation_in_command(L"gc somebranch", 0, vars, &result);
if (!expanded) err(L"Command not expanded on line %ld", (long)__LINE__);
expanded = reader_expand_abbreviation_in_command(L"gc somebranch", wcslen(L"gc"), &result);
expanded =
reader_expand_abbreviation_in_command(L"gc somebranch", wcslen(L"gc"), vars, &result);
if (!expanded) err(L"gc not expanded");
if (result != L"git checkout somebranch")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// Space separation.
expanded = reader_expand_abbreviation_in_command(L"gx somebranch", wcslen(L"gc"), &result);
expanded =
reader_expand_abbreviation_in_command(L"gx somebranch", wcslen(L"gc"), vars, &result);
if (!expanded) err(L"gx not expanded");
if (result != L"git checkout somebranch")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
expanded = reader_expand_abbreviation_in_command(L"echo hi ; gc somebranch",
wcslen(L"echo hi ; g"), &result);
wcslen(L"echo hi ; g"), vars, &result);
if (!expanded) err(L"gc not expanded on line %ld", (long)__LINE__);
if (result != L"echo hi ; git checkout somebranch")
err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
expanded = reader_expand_abbreviation_in_command(
L"echo (echo (echo (echo (gc ", wcslen(L"echo (echo (echo (echo (gc"), &result);
L"echo (echo (echo (echo (gc ", wcslen(L"echo (echo (echo (echo (gc"), vars, &result);
if (!expanded) err(L"gc not expanded on line %ld", (long)__LINE__);
if (result != L"echo (echo (echo (echo (git checkout ")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// If commands should be expanded.
expanded = reader_expand_abbreviation_in_command(L"if gc", wcslen(L"if gc"), &result);
expanded = reader_expand_abbreviation_in_command(L"if gc", wcslen(L"if gc"), vars, &result);
if (!expanded) err(L"gc not expanded on line %ld", (long)__LINE__);
if (result != L"if git checkout")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// Others should not be.
expanded = reader_expand_abbreviation_in_command(L"of gc", wcslen(L"of gc"), &result);
expanded = reader_expand_abbreviation_in_command(L"of gc", wcslen(L"of gc"), vars, &result);
if (expanded) err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
// Others should not be.
expanded = reader_expand_abbreviation_in_command(L"command gc", wcslen(L"command gc"), &result);
expanded =
reader_expand_abbreviation_in_command(L"command gc", wcslen(L"command gc"), vars, &result);
if (expanded) err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
vars.pop();
@@ -2662,9 +2665,9 @@ static void perform_one_autosuggestion_cd_test(const wcstring &command, const wc
}
static void perform_one_completion_cd_test(const wcstring &command, const wcstring &expected,
long line) {
const environment_t &vars, long line) {
std::vector<completion_t> comps;
complete(command, &comps, COMPLETION_REQUEST_DEFAULT, env_vars_snapshot_t{});
complete(command, &comps, COMPLETION_REQUEST_DEFAULT, vars);
bool expects_error = (expected == L"<error>");
@@ -2795,8 +2798,8 @@ static void test_autosuggest_suggest_special() {
if (system("mkdir -p '~hahaha/path1/path2/'")) err(L"mkdir failed");
perform_one_autosuggestion_cd_test(L"cd ~haha", L"ha/path1/path2/", vars, __LINE__);
perform_one_autosuggestion_cd_test(L"cd ~hahaha/", L"path1/path2/", vars, __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 ~haha", L"ha/", vars, __LINE__);
perform_one_completion_cd_test(L"cd ~hahaha/", L"path1/", vars, __LINE__);
parser_t::principal_parser().vars().remove(L"HOME", ENV_LOCAL | ENV_EXPORT);
popd();