clerk/tests/test.go (view raw)
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | |
| 8 | "github.com/olexsmir/ledger-tools/journal" |
| 9 | ) |
| 10 | |
| 11 | type test struct { |
| 12 | Desc string |
| 13 | Broken bool |
| 14 | } |
| 15 | |
| 16 | var testCases = map[string]test{ |
| 17 | "actual-1ktxns-100accts.journal": {Desc: "hledger stress test: 1000 transactions, 100 accounts, number-only account names"}, |
| 18 | "actual-accounttypes.journal": {Desc: "hledger: account type annotations (type:A, type:L) via comments"}, |
| 19 | "actual-alias.journal": {Desc: "hledger: account alias directives for renaming"}, |
| 20 | "actual-borrowing.journal": {Desc: "hledger: borrowing/lending example with liabilities"}, |
| 21 | "actual-business.journal": {Desc: "hledger: simple business transactions with commodities"}, |
| 22 | "actual-goal-budget-1.journal": {Desc: "hledger: goal budget using periodic transactions"}, |
| 23 | "actual-i18n-en.journal": {Desc: "hledger: internationalization with account types in English"}, |
| 24 | "actual-ledger-input-divzero.dat": {Desc: "ledger-cli: fuzz corpus, designed to cause divide-by-zero"}, |
| 25 | "actual-ledger-input-parsing.dat": {Desc: "ledger-cli: fuzz corpus, tests EOF without newline"}, |
| 26 | "actual-ledger-input-sample.dat": {Desc: "ledger-cli: fuzz corpus, default commodity directive"}, |
| 27 | "actual-ledger-input-standard.dat": {Desc: "ledger-cli: fuzz corpus, standard ledger format"}, |
| 28 | "actual-ledger-input-transfer.dat": {Desc: "ledger-cli: fuzz corpus, byte quantity (non-monetary)"}, |
| 29 | "actual-ledger-input-wow.dat": {Broken: true, Desc: "ledger-cli: fuzz corpus, World of Warcraft currency (1G=100s)"}, |
| 30 | "actual-multicurrency.journal": {Desc: "hledger: multi-currency transactions with HRK/EUR"}, |
| 31 | "actual-personal.journal": {Desc: "hledger: simple personal finance example"}, |
| 32 | "actual-quickstart.journal": {Desc: "hledger: quickstart guide with commodity directive"}, |
| 33 | "actual-sample.journal": {Desc: "hledger: comprehensive sample with account tree"}, |
| 34 | "actual-sample2.journal": {Desc: "hledger: sample2 with balance assertions and account directives"}, |
| 35 | "actual-status.journal": {Desc: "hledger: tests all transaction statuses (unmarked, pending, cleared)"}, |
| 36 | "actual-templates.journal": {Desc: "hledger: entry template examples with comments"}, |
| 37 | "actual-unicode.journal": {Desc: "hledger: unicode in descriptions, account names, currency"}, |
| 38 | "actual-vat.journal": {Desc: "hledger: VAT tracking example"}, |
| 39 | "apply-tag-block.dat": {Desc: "ledger-cli: apply-tag block directive"}, |
| 40 | "automated-posting-rule.dat": {Desc: "ledger-cli: automated posting rules (= /^Expenses/)"}, |
| 41 | "basic-ledger.dat": {Desc: "ledger-cli: basic income/expense transaction"}, |
| 42 | "basic.journal": {Desc: "hledger: minimal setup with account/commodity directives"}, |
| 43 | "broken-double-at.journal": {Broken: true, Desc: "synthetic: intentionally broken (@@) syntax"}, |
| 44 | "broken-rparen.journal": {Broken: true, Desc: "synthetic: intentionally broken unmatched )"}, |
| 45 | "broken-unknown-directive.journal": {Broken: true, Desc: "synthetic: intentionally broken unknown directive (??)"}, |
| 46 | "code-note.dat": {Desc: "ledger-cli: transaction with code, payee, comments"}, |
| 47 | "commodity-space.dat": {Desc: "ledger-cli: commodity with space before amount ($ 10.00)"}, |
| 48 | "cost-balance-assertion.dat": {Desc: "ledger-cli: cost notation and balance assertion (@ 1 USD = 20.00 UAH)"}, |
| 49 | "directives-supported.journal": {Desc: "mixed: tests account, commodity, include, alias directives"}, |
| 50 | "ext-hledger-i18n-no.journal": {Desc: "hledger i18n example: uppercase directive values currently mis-tokenized"}, |
| 51 | "ext-hledger-self-tracking-d.dat": {Desc: "hledger self-tracking example with date+time transaction headers"}, |
| 52 | "ext-hledger-status.journal": {Desc: "hledger status example: ! (virtual:posting)"}, |
| 53 | "ext-ledger-parsing.dat": {Desc: "ledger parsing corpus: -$ amount form"}, |
| 54 | "header-comments.journal": {Desc: "hledger: transaction with header comment"}, |
| 55 | "inclusive-balance-star.journal": {Desc: "hledger: inclusive balance with ==*"}, |
| 56 | "multicurrency-supported.journal": {Desc: "hledger: working multi-currency with EUR exchange"}, |
| 57 | "periodic-basic.journal": {Desc: "hledger: periodic transaction (~ monthly)"}, |
| 58 | "secondary-date-note.journal": {Desc: "hledger: secondary date and transaction note"}, |
| 59 | "status-basic.journal": {Desc: "hledger: transaction status (pending with !)"}, |
| 60 | "unicode-cjk-emoji.journal": {Desc: "synthetic: unicode CJK and emoji in transaction descriptions"}, |
| 61 | "unicode-cyrillic.journal": {Desc: "synthetic: unicode Cyrillic in descriptions and account names"}, |
| 62 | "unicode-mixed-languages.journal": {Desc: "synthetic: mixed latin/cyrillic/cjk in descriptions and account names"}, |
| 63 | "virtual-posting.dat": {Desc: "ledger-cli: virtual/balanced postings with [brackets]"}, |
| 64 | } |
| 65 | |
| 66 | func main() { |
| 67 | failures := 0 |
| 68 | for name, tc := range testCases { |
| 69 | loader := journal.NewLoader() |
| 70 | pf, err := loader.Load(filepath.Join("tests/journal", name)) |
| 71 | if err != nil { |
| 72 | if tc.Broken { |
| 73 | fmt.Printf("SKIP %s: %s\n", name, tc.Desc) |
| 74 | continue |
| 75 | } |
| 76 | fmt.Printf("FAIL %s: %v\n", name, err) |
| 77 | failures++ |
| 78 | continue |
| 79 | } |
| 80 | |
| 81 | if len(pf.Errors)+len(pf.FileErrors) > 0 { |
| 82 | if tc.Broken { |
| 83 | fmt.Printf("SKIP %s: %s\n", name, tc.Desc) |
| 84 | continue |
| 85 | } |
| 86 | |
| 87 | fmt.Printf("FAIL %s: %d parse errors, %d file errors\n", name, len(pf.Errors), len(pf.FileErrors)) |
| 88 | for i, e := range pf.Errors { |
| 89 | if i >= 5 { |
| 90 | fmt.Printf(" ... and %d more parse errors\n", len(pf.Errors)-5) |
| 91 | break |
| 92 | } |
| 93 | fmt.Printf(" %s\n", e.Message) |
| 94 | } |
| 95 | for i, e := range pf.FileErrors { |
| 96 | if i >= 5 { |
| 97 | fmt.Printf(" ... and %d more file errors\n", len(pf.FileErrors)-5) |
| 98 | break |
| 99 | } |
| 100 | fmt.Printf(" [%s] %s\n", e.Path, e.Message) |
| 101 | } |
| 102 | failures++ |
| 103 | } else { |
| 104 | fmt.Printf("PASS %s\n", name) |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | fmt.Printf("\n%d files failed\n", failures) |
| 109 | if failures > 0 { |
| 110 | os.Exit(1) |
| 111 | } |
| 112 | } |