From 7935b86cb2f06385f5fcb8774efcc0ae8f47a0b8 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Thu, 25 Sep 2014 19:45:54 -0700 Subject: Report expand errors better in fish tests Print the expected and actual results if an error occurs. --- fish_tests.cpp | 76 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 29 deletions(-) (limited to 'fish_tests.cpp') diff --git a/fish_tests.cpp b/fish_tests.cpp index 156fdc04..ffff6ff4 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -1310,58 +1310,76 @@ static bool expand_test(const wchar_t *in, expand_flags_t flags, ...) { std::vector output; va_list va; - size_t i=0; bool res=true; wchar_t *arg; + parse_error_list_t errors; - if (expand_string(in, output, flags, NULL)) - { - - } -#if 0 - printf("input: %ls\n", in); - for (size_t idx=0; idx < output.size(); idx++) + if (expand_string(in, output, flags, &errors) == EXPAND_ERROR) { - printf("%ls\n", output.at(idx).completion.c_str()); + if (errors.empty()) + { + err(L"Bug: Parse error reported but no error text found."); + } + else + { + err(L"%ls", errors.at(0).describe(wcstring(in)).c_str()); + } + return false; } -#endif - va_start(va, flags); + wcstring_list_t expected; + va_start(va, flags); while ((arg=va_arg(va, wchar_t *))!= 0) { - if (output.size() == i) - { - res=false; - break; - } + expected.push_back(wcstring(arg)); + } + va_end(va); - if (output.at(i).completion != arg) + wcstring_list_t::const_iterator exp_it = expected.begin(), exp_end = expected.end(); + std::vector::const_iterator out_it = output.begin(), out_end = output.end(); + for (; exp_it != exp_end || out_it != out_end; ++exp_it, ++out_it) + { + if (exp_it == exp_end || out_it == out_end) { - res=false; + // sizes don't match + res = false; break; } - i++; - - if (!res) + if (out_it->completion != *exp_it) { - // empty the rest of the args - while(va_arg(va, wchar_t *) != 0); + res = false; break; } } - if (output.size() != i) - { - res = false; - } - if (!res) { if ((arg = va_arg(va, wchar_t *)) != 0) { - err(arg); + wcstring msg = L"Expected ["; + bool first = true; + for (wcstring_list_t::const_iterator it = expected.begin(), end = expected.end(); it != end; ++it) + { + if (!first) msg += L", "; + first = false; + msg += '"'; + msg += *it; + msg += '"'; + } + msg += L"], found ["; + first = true; + for (std::vector::const_iterator it = output.begin(), end = output.end(); it != end; ++it) + { + if (!first) msg += L", "; + first = false; + msg += '"'; + msg += it->completion; + msg += '"'; + } + msg += L"]"; + err(L"%ls\n%ls", arg, msg.c_str()); } } -- cgit v1.2.3