Permalink
Browse files

Merge remote-tracking branch 'origin/master' into next

  • Loading branch information...
jwiegley committed Jul 20, 2018
2 parents 8283abb + 2b98192 commit 5d02402291a923d30e66e4b0a08975ebf22361c3
Showing with 29 additions and 4 deletions.
  1. +1 −0 src/context.h
  2. +3 −2 src/error.h
  3. +1 −1 src/global.h
  4. +6 −1 src/textual.cc
  5. +18 −0 test/python/JournalTest.py
@@ -70,6 +70,7 @@ class parse_context_t
std::size_t errors;
std::size_t count;
std::size_t sequence;
std::string last;
explicit parse_context_t(const path& cwd)
: current_directory(cwd), master(NULL), scope(NULL),
@@ -95,8 +95,9 @@ string source_context(const path& file,
struct error_count {
std::size_t count;
explicit error_count(std::size_t _count) : count(_count) {}
const char * what() const { return ""; }
std::string message;
explicit error_count(std::size_t _count, std::string _msg) : count(_count), message(_msg) {}
const char * what() const { return message.c_str(); }
};
} // namespace ledger
@@ -166,7 +166,7 @@ See LICENSE file included with the distribution for details and disclaimer.");
OPTION_(global_scope_t, version, DO() { // -v
parent->show_version_info(std::cout);
throw error_count(0); // exit immediately
throw error_count(0, ""); // exit immediately
});
};
@@ -282,6 +282,10 @@ void instance_t::parse()
std::cerr << _("Error: ") << err.what() << std::endl;
context.errors++;
if (! current_context.empty())
context.last = current_context + "\n" + err.what();
else
context.last = err.what();
}
}
@@ -2030,7 +2034,8 @@ std::size_t journal_t::read_textual(parse_context_stack_t& context_stack)
TRACE_FINISH(parsing_total, 1);
if (context_stack.get_current().errors > 0)
throw error_count(context_stack.get_current().errors);
throw error_count(context_stack.get_current().errors,
context_stack.get_current().last);
return context_stack.get_current().count;
}
@@ -22,6 +22,24 @@ def testBasicRead(self):
for post in journal.query("food"):
self.assertEqual(str(post.account), "Expenses:Food")
self.assertEqual(post.amount, Amount("$21.34"))
def testParseError(self):
# TODO: ledger spits out parse errors to standard out.
# This should not happen, especially when the error
# has already been captured by a Python exception.
def fun():
read_journal_from_string("""
2012-03-01 KFC
Expenses:Food rsnetnirsnti
Assets:Cash
""")
self.assertRaises(RuntimeError, fun)
try:
fun()
except RuntimeError as e:
self.assertEquals(str(e).splitlines()[-1],
"No quantity specified for amount")
def suite():
return unittest.TestLoader().loadTestsFromTestCase(JournalTestCase)

0 comments on commit 5d02402

Please sign in to comment.