aboutsummaryrefslogtreecommitdiffhomepage
path: root/fish_tests.cpp
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-09-25 19:45:54 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-09-25 19:45:54 -0700
commit7935b86cb2f06385f5fcb8774efcc0ae8f47a0b8 (patch)
treeec95c26a0521fbdb85ba9e70f4e618222812be7a /fish_tests.cpp
parentfb8eb22e569948b7b4fc0bf6a7c77e680e147ec3 (diff)
Report expand errors better in fish tests
Print the expected and actual results if an error occurs.
Diffstat (limited to 'fish_tests.cpp')
-rw-r--r--fish_tests.cpp76
1 files changed, 47 insertions, 29 deletions
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<completion_t> 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<completion_t>::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<completion_t>::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());
}
}