mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Add some tests for parse_util_detect_errors_in_argument
This commit is contained in:
parent
d659e55646
commit
e780637cf4
3 changed files with 66 additions and 0 deletions
|
@ -511,6 +511,20 @@ static void test_iothread(void)
|
||||||
delete int_ptr;
|
delete int_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static parser_test_error_bits_t detect_argument_errors(const wcstring &src)
|
||||||
|
{
|
||||||
|
parse_node_tree_t tree;
|
||||||
|
if (! parse_tree_from_string(src, parse_flag_none, &tree, NULL, symbol_argument_list))
|
||||||
|
{
|
||||||
|
return PARSER_TEST_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(! tree.empty());
|
||||||
|
const parse_node_t *first_arg = tree.next_node_in_node_list(tree.at(0), symbol_argument, NULL);
|
||||||
|
assert(first_arg != NULL);
|
||||||
|
return parse_util_detect_errors_in_argument(*first_arg, first_arg->get_source(src));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Test the parser
|
Test the parser
|
||||||
*/
|
*/
|
||||||
|
@ -592,12 +606,57 @@ static void test_parser()
|
||||||
err(L"'and' command in pipeline not reported as error");
|
err(L"'and' command in pipeline not reported as error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! parse_util_detect_errors(L"cat | or cat"))
|
||||||
|
{
|
||||||
|
err(L"'or' command in pipeline not reported as error");
|
||||||
|
}
|
||||||
|
|
||||||
if (! parse_util_detect_errors(L"cat | exec") || ! parse_util_detect_errors(L"exec | cat"))
|
if (! parse_util_detect_errors(L"cat | exec") || ! parse_util_detect_errors(L"exec | cat"))
|
||||||
{
|
{
|
||||||
err(L"'exec' command in pipeline not reported as error");
|
err(L"'exec' command in pipeline not reported as error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (detect_argument_errors(L"foo"))
|
||||||
|
{
|
||||||
|
err(L"simple argument reported as error");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detect_argument_errors(L"''"))
|
||||||
|
{
|
||||||
|
err(L"Empty string reported as error");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (! (detect_argument_errors(L"foo$$") & PARSER_TEST_ERROR))
|
||||||
|
{
|
||||||
|
err(L"Bad variable expansion not reported as error");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! (detect_argument_errors(L"foo$@") & PARSER_TEST_ERROR))
|
||||||
|
{
|
||||||
|
err(L"Bad variable expansion not reported as error");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Within command substitutions, we should be able to detect everything that parse_util_detect_errors can detect */
|
||||||
|
if (! (detect_argument_errors(L"foo(cat | or cat)") & PARSER_TEST_ERROR))
|
||||||
|
{
|
||||||
|
err(L"Bad command substitution not reported as error");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! (detect_argument_errors(L"foo\\xFF9") & PARSER_TEST_ERROR))
|
||||||
|
{
|
||||||
|
err(L"Bad escape not reported as error");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! (detect_argument_errors(L"foo(echo \\xFF9)") & PARSER_TEST_ERROR))
|
||||||
|
{
|
||||||
|
err(L"Bad escape in command substitution not reported as error");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! (detect_argument_errors(L"foo(echo (echo (echo \\xFF9)))") & PARSER_TEST_ERROR))
|
||||||
|
{
|
||||||
|
err(L"Bad escape in nested command substitution not reported as error");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
say(L"Testing basic evaluation");
|
say(L"Testing basic evaluation");
|
||||||
|
|
|
@ -1091,6 +1091,8 @@ void parse_util_expand_variable_error(const parse_node_t &node, const wcstring &
|
||||||
*/
|
*/
|
||||||
parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t &node, const wcstring &arg_src, parse_error_list_t *out_errors)
|
parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t &node, const wcstring &arg_src, parse_error_list_t *out_errors)
|
||||||
{
|
{
|
||||||
|
assert(node.type == symbol_argument);
|
||||||
|
|
||||||
int err=0;
|
int err=0;
|
||||||
|
|
||||||
wchar_t *paran_begin, *paran_end;
|
wchar_t *paran_begin, *paran_end;
|
||||||
|
|
|
@ -171,6 +171,11 @@ std::vector<int> parse_util_compute_indents(const wcstring &src);
|
||||||
|
|
||||||
parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, parse_error_list_t *out_errors = NULL);
|
parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, parse_error_list_t *out_errors = NULL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Test if this argument contains any errors. Detected errors include syntax errors in command substitutions, improperly escaped characters and improper use of the variable expansion operator.
|
||||||
|
|
||||||
|
This does NOT currently detect unterminated quotes.
|
||||||
|
*/
|
||||||
parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t &node, const wcstring &arg_src, parse_error_list_t *out_errors = NULL);
|
parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t &node, const wcstring &arg_src, parse_error_list_t *out_errors = NULL);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue