2018-06-10 17:35:57 +03:00
|
|
|
# Testing parse error messages for accuracy and usefulness.
|
|
|
|
|
2018-06-10 18:04:45 +03:00
|
|
|
# A journal with an incomplete date.
|
2018-06-10 17:35:57 +03:00
|
|
|
<
|
|
|
|
2018
|
|
|
|
|
2019-04-20 19:25:09 +03:00
|
|
|
# XXX depends on the executable being named "hledger" (prepended by GHC.Err.error)
|
2018-06-10 18:04:45 +03:00
|
|
|
# 1.
|
2018-06-10 17:35:57 +03:00
|
|
|
$ hledger -f - print
|
|
|
|
>2
|
|
|
|
hledger: -:1:5:
|
2018-06-11 23:43:19 +03:00
|
|
|
|
|
|
|
|
1 | 2018
|
|
|
|
| ^
|
2018-06-10 17:35:57 +03:00
|
|
|
unexpected newline
|
2018-09-30 04:32:08 +03:00
|
|
|
expecting date separator or digit
|
2018-06-10 17:35:57 +03:00
|
|
|
|
|
|
|
>=1
|
|
|
|
|
2018-06-10 18:04:45 +03:00
|
|
|
# A journal with an unbalanced transaction.
|
2018-06-10 17:35:57 +03:00
|
|
|
<
|
|
|
|
2018/1/1
|
|
|
|
a 1
|
|
|
|
|
2018-06-10 18:04:45 +03:00
|
|
|
# 2. When read from stdin, this example actually passes because hledger tries all readers.
|
|
|
|
# If they all failed, it would show the error from the first (journal reader).
|
|
|
|
# But in this case the timedot reader can parse it.
|
|
|
|
$ hledger -f - print
|
2018-06-10 17:35:57 +03:00
|
|
|
>
|
2018-06-10 18:04:45 +03:00
|
|
|
2018/01/01 *
|
|
|
|
(a) 1.00
|
|
|
|
|
|
|
|
>=
|
2018-06-10 17:35:57 +03:00
|
|
|
|
2018-06-10 17:53:23 +03:00
|
|
|
# 3. So in these tests we must sometimes force the desired format, like so.
|
|
|
|
# Now we see the error from the journal reader.
|
2018-06-10 18:04:45 +03:00
|
|
|
$ hledger -f journal:- print
|
2018-10-24 01:23:26 +03:00
|
|
|
>2 /could not balance this transaction \(real postings are off by 1\)/
|
|
|
|
>=1
|
|
|
|
|
|
|
|
# 4. We expect to have reference to line number with last posting
|
|
|
|
$ hledger -f journal:- print
|
|
|
|
>2 /\<2\>/
|
2018-06-10 17:35:57 +03:00
|
|
|
>=1
|
|
|
|
|
2018-06-10 18:04:45 +03:00
|
|
|
# A posting without two spaces between account and amount.
|
2018-06-10 17:35:57 +03:00
|
|
|
<
|
|
|
|
2018/1/1
|
|
|
|
(a) 1
|
|
|
|
|
2018-10-24 01:23:26 +03:00
|
|
|
# 5. hledger doesn't detect this as an error directly, it parses account name "(a) 1" and
|
2018-06-10 18:04:45 +03:00
|
|
|
# amount 0 here.
|
2018-06-10 17:53:23 +03:00
|
|
|
$ hledger -f - print -x
|
2018-06-10 17:35:57 +03:00
|
|
|
2018/01/01
|
|
|
|
(a) 1 0
|
|
|
|
|
|
|
|
>=
|
|
|
|
|
2018-10-24 01:23:26 +03:00
|
|
|
# 6. Two (or more) postings with implicit amount cannot be balanced.
|
|
|
|
<
|
|
|
|
2018/1/1
|
|
|
|
a 1
|
|
|
|
b
|
|
|
|
c
|
|
|
|
|
|
|
|
$ hledger -f journal:- print
|
2019-02-15 21:34:40 +03:00
|
|
|
>2 /could not balance this transaction - can't have more than one real posting with no amount/
|
2018-10-24 01:23:26 +03:00
|
|
|
>=1
|
|
|
|
|
|
|
|
# 7. Two (or more) virtual postings with implicit amount cannot be balanced.
|
2019-02-15 21:34:40 +03:00
|
|
|
# (And the error message contains line numbers).
|
2018-10-24 01:23:26 +03:00
|
|
|
<
|
|
|
|
2018/1/1
|
|
|
|
[a] 1
|
|
|
|
[b]
|
|
|
|
[c]
|
|
|
|
|
|
|
|
$ hledger -f journal:- print
|
2019-02-15 21:34:40 +03:00
|
|
|
>2 /lines 1-4/
|
2018-10-24 01:23:26 +03:00
|
|
|
>=1
|