diff options
author | 2013-12-08 21:54:06 -0800 | |
---|---|---|
committer | 2013-12-08 21:54:06 -0800 | |
commit | 7a3f5afee7b6a6ab9f801ca3cd65c2c552554987 (patch) | |
tree | a4a0f885f92b215ee44b31b04760782356ea15c0 /fish_tests.cpp | |
parent | 5769fa6aed981e02d9e0f9f7c83f77e677f8c84f (diff) |
Initial work towars improved error reporting. Tests currently fail.
Diffstat (limited to 'fish_tests.cpp')
-rw-r--r-- | fish_tests.cpp | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/fish_tests.cpp b/fish_tests.cpp index 16f657fc..c43381b3 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -2333,7 +2333,7 @@ static void test_new_parser_ll2(void) } } -static void test_new_parser_ad_hoc(void) +static void test_new_parser_ad_hoc() { /* Very ad-hoc tests for issues encountered */ say(L"Testing new parser ad hoc tests"); @@ -2356,6 +2356,58 @@ static void test_new_parser_ad_hoc(void) } } +static void test_new_parser_errors(void) +{ + say(L"Testing new parser error reporting"); + const struct + { + const wchar_t *src; + parse_error_code_t code; + } + tests[] = + { + {L"echo (abc", parse_error_tokenizer}, + + {L"end", parse_error_unbalancing_end}, + {L"echo hi ; end", parse_error_unbalancing_end}, + + {L"else", parse_error_unbalancing_else}, + {L"if true ; end ; else", parse_error_unbalancing_else}, + + {L"case", parse_error_unbalancing_case}, + {L"if true ; case ; end", parse_error_unbalancing_case} + }; + + for (size_t i = 0; i < sizeof tests / sizeof *tests; i++) + { + const wcstring src = tests[i].src; + parse_error_code_t expected_code = tests[i].code; + + parse_error_list_t errors; + parse_node_tree_t parse_tree; + bool success = parse_t::parse(src, parse_flag_none, &parse_tree, &errors); + if (success) + { + err(L"Source '%ls' was expected to fail to parse, but succeeded", src.c_str()); + } + + if (errors.size() != 1) + { + err(L"Source '%ls' was expected to produce 1 error, but instead produced %lu errors", src.c_str(), errors.size()); + } + else if (errors.at(0).code != expected_code) + { + err(L"Source '%ls' was expected to produce error code %lu, but instead produced error code %lu", src.c_str(), expected_code, (unsigned long)errors.at(0).code); + for (size_t i=0; i < errors.size(); i++) + { + err(L"\t\t%ls", errors.at(i).describe(src).c_str()); + } + } + + } + +} + static void test_highlighting(void) { say(L"Testing syntax highlighting"); @@ -2574,6 +2626,7 @@ int main(int argc, char **argv) if (should_test_function("new_parser_fuzzing")) test_new_parser_fuzzing(); //fuzzing is expensive if (should_test_function("new_parser_correctness")) test_new_parser_correctness(); if (should_test_function("new_parser_ad_hoc")) test_new_parser_ad_hoc(); + if (should_test_function("new_parser_errors")) test_new_parser_errors(); if (should_test_function("escape")) test_unescape_sane(); if (should_test_function("escape")) test_escape_crazy(); if (should_test_function("format")) test_format(); |