Feature flag support for ? wildcard

This partially reverts 6e56637cf0 and #4520
by bringing back the ? wildcard, guarded by the qmark-noglob feature flag.
This commit is contained in:
ridiculousfish
2018-05-05 19:11:57 -07:00
parent dc8d603f98
commit 762c31be87
13 changed files with 117 additions and 41 deletions

View File

@@ -4093,7 +4093,7 @@ static void test_wcstring_tok() {
}
int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv);
static void run_one_string_test(const wchar_t **argv, int expected_rc,
static void run_one_string_test(const wchar_t *const *argv, int expected_rc,
const wchar_t *expected_out) {
parser_t parser;
io_streams_t streams(0);
@@ -4115,7 +4115,7 @@ static void run_one_string_test(const wchar_t **argv, int expected_rc,
}
static void test_string() {
static struct string_test {
const struct string_test {
const wchar_t *argv[15];
int expected_rc;
const wchar_t *expected_out;
@@ -4159,16 +4159,15 @@ static void test_string() {
{{L"string", L"match", 0}, STATUS_INVALID_ARGS, L""},
{{L"string", L"match", L"", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"", L"", 0}, STATUS_CMD_OK, L"\n"},
{{L"string", L"match", L"?", L"a", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"?", L"a", 0}, STATUS_CMD_OK, L"a\n"},
{{L"string", L"match", L"*", L"", 0}, STATUS_CMD_OK, L"\n"},
{{L"string", L"match", L"**", L"", 0}, STATUS_CMD_OK, L"\n"},
{{L"string", L"match", L"*", L"xyzzy", 0}, STATUS_CMD_OK, L"xyzzy\n"},
{{L"string", L"match", L"**", L"plugh", 0}, STATUS_CMD_OK, L"plugh\n"},
{{L"string", L"match", L"a*b", L"axxb", 0}, STATUS_CMD_OK, L"axxb\n"},
{{L"string", L"match", L"a??b", L"axxb", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"a??b", L"a??b", 0}, STATUS_CMD_OK, L"a??b\n"},
{{L"string", L"match", L"-i", L"a??B", L"axxb", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"-i", L"a??b", L"Axxb", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"a??b", L"axxb", 0}, STATUS_CMD_OK, L"axxb\n"},
{{L"string", L"match", L"-i", L"a??B", L"axxb", 0}, STATUS_CMD_OK, L"axxb\n"},
{{L"string", L"match", L"-i", L"a??b", L"Axxb", 0}, STATUS_CMD_OK, L"Axxb\n"},
{{L"string", L"match", L"a*", L"axxb", 0}, STATUS_CMD_OK, L"axxb\n"},
{{L"string", L"match", L"*a", L"xxa", 0}, STATUS_CMD_OK, L"xxa\n"},
{{L"string", L"match", L"*a*", L"axa", 0}, STATUS_CMD_OK, L"axa\n"},
@@ -4177,14 +4176,9 @@ static void test_string() {
{{L"string", L"match", L"*a", L"a", 0}, STATUS_CMD_OK, L"a\n"},
{{L"string", L"match", L"a*", L"a", 0}, STATUS_CMD_OK, L"a\n"},
{{L"string", L"match", L"a*b*c", L"axxbyyc", 0}, STATUS_CMD_OK, L"axxbyyc\n"},
{{L"string", L"match", L"a*b?c", L"axxb?c", 0}, STATUS_CMD_OK, L"axxb?c\n"},
{{L"string", L"match", L"*?", L"a", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"*?", L"ab", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"?*", L"a", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"?*", L"ab", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"\\*", L"*", 0}, STATUS_CMD_OK, L"*\n"},
{{L"string", L"match", L"a*\\", L"abc\\", 0}, STATUS_CMD_OK, L"abc\\\n"},
{{L"string", L"match", L"a*\\?", L"abc?", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"a*\\?", L"abc?", 0}, STATUS_CMD_OK, L"abc?\n"},
{{L"string", L"match", L"?", L"", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"?", L"ab", 0}, STATUS_CMD_ERROR, L""},
@@ -4403,15 +4397,36 @@ static void test_string() {
{{L"string", L"trim", L"-c", L"\\/", L"/a\\"}, STATUS_CMD_OK, L"a\n"},
{{L"string", L"trim", L"-c", L"\\/", L"a/"}, STATUS_CMD_OK, L"a\n"},
{{L"string", L"trim", L"-c", L"\\/", L"\\a/"}, STATUS_CMD_OK, L"a\n"},
{{L"string", L"trim", L"-c", L"", L".a."}, STATUS_CMD_ERROR, L".a.\n"},
{{NULL}, STATUS_CMD_ERROR, NULL}};
struct string_test *t = string_tests;
while (t->argv[0]) {
run_one_string_test(t->argv, t->expected_rc, t->expected_out);
t++;
{{L"string", L"trim", L"-c", L"", L".a."}, STATUS_CMD_ERROR, L".a.\n"}};
for (const auto &t : string_tests) {
run_one_string_test(t.argv, t.expected_rc, t.expected_out);
}
const auto saved_flags = fish_features();
const struct string_test qmark_noglob_tests[] = {
{{L"string", L"match", L"a*b?c", L"axxb?c", 0}, STATUS_CMD_OK, L"axxb?c\n"},
{{L"string", L"match", L"*?", L"a", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"*?", L"ab", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"?*", L"a", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"?*", L"ab", 0}, STATUS_CMD_ERROR, L""},
{{L"string", L"match", L"a*\\?", L"abc?", 0}, STATUS_CMD_ERROR, L""}};
mutable_fish_features().set(features_t::qmark_noglob, true);
for (const auto &t : qmark_noglob_tests) {
run_one_string_test(t.argv, t.expected_rc, t.expected_out);
}
const struct string_test qmark_glob_tests[] = {
{{L"string", L"match", L"a*b?c", L"axxbyc", 0}, STATUS_CMD_OK, L"axxbyc\n"},
{{L"string", L"match", L"*?", L"a", 0}, STATUS_CMD_OK, L"a\n"},
{{L"string", L"match", L"*?", L"ab", 0}, STATUS_CMD_OK, L"ab\n"},
{{L"string", L"match", L"?*", L"a", 0}, STATUS_CMD_OK, L"a\n"},
{{L"string", L"match", L"?*", L"ab", 0}, STATUS_CMD_OK, L"ab\n"},
{{L"string", L"match", L"a*\\?", L"abc?", 0}, STATUS_CMD_OK, L"abc?\n"}};
mutable_fish_features().set(features_t::qmark_noglob, false);
for (const auto &t : qmark_glob_tests) {
run_one_string_test(t.argv, t.expected_rc, t.expected_out);
}
mutable_fish_features() = saved_flags;
}
/// Helper for test_timezone_env_vars().
@@ -4468,15 +4483,11 @@ static void test_illegal_command_exit_code() {
};
const command_result_tuple_t tests[] = {
{L"echo -n", STATUS_CMD_OK},
{L"pwd", STATUS_CMD_OK},
// a `)` without a matching `(` is now a tokenizer error, and cannot be executed even as an
// illegal command
{L"echo -n", STATUS_CMD_OK}, {L"pwd", STATUS_CMD_OK},
// a `)` without a matching `(` is now a tokenizer error, and cannot be executed even as an illegal command
// {L")", STATUS_ILLEGAL_CMD}, {L") ", STATUS_ILLEGAL_CMD}, {L") ", STATUS_ILLEGAL_CMD}
{L"*", STATUS_ILLEGAL_CMD},
{L"**", STATUS_ILLEGAL_CMD},
{L"?", STATUS_CMD_UNKNOWN},
{L"abc?def", STATUS_CMD_UNKNOWN},
{L"*", STATUS_ILLEGAL_CMD}, {L"**", STATUS_ILLEGAL_CMD},
{L"?", STATUS_ILLEGAL_CMD}, {L"abc?def", STATUS_ILLEGAL_CMD},
};
int res = 0;