diff options
Diffstat (limited to 'test')
28 files changed, 247 insertions, 42 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b5d8cf09..94ce0a0a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,7 +22,7 @@ macro(add_ledger_harness_tests _class) foreach(TestFile ${${_class}_TESTS}) get_filename_component(TestFile_Name ${TestFile} NAME_WE) string(FIND ${TestFile_Name} "_py" TestFile_IsPythonTest) - if((NOT TestFile_IsPythonTest) OR HAVE_BOOST_PYTHON) + if((TestFile_IsPythonTest EQUAL -1) OR HAVE_BOOST_PYTHON) add_test(${_class}Test_${TestFile_Name} ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/RegressTests.py ${LEDGER_LOCATION} ${PROJECT_SOURCE_DIR} diff --git a/test/LedgerHarness.py b/test/LedgerHarness.py index b8900971..39a31286 100755 --- a/test/LedgerHarness.py +++ b/test/LedgerHarness.py @@ -116,12 +116,14 @@ class LedgerHarness: def success(self): sys.stdout.write(".") + sys.stdout.flush() self.succeeded += 1 def failure(self, name=None): sys.stdout.write("E") if name: sys.stdout.write("[%s]" % name) + sys.stdout.flush() self.failed += 1 def exit(self): diff --git a/test/RegressTests.py b/test/RegressTests.py index 7d67eb21..01e14191 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -98,8 +98,10 @@ class RegressFile(object): def run_test(self, test): use_stdin = False - if test['command'].find("-f - ") != -1: - use_stdin = True + if test['command'].find("-f ") != -1: + test['command'] = '$ledger ' + test['command'] + if re.search("-f (-|/dev/stdin)(\s|$)", test['command']): + use_stdin = True else: test['command'] = (('$ledger -f "%s" ' % os.path.abspath(self.filename)) + diff --git a/test/baseline/cmd-accounts.test b/test/baseline/cmd-accounts.test index be6365fd..2f0310da 100644 --- a/test/baseline/cmd-accounts.test +++ b/test/baseline/cmd-accounts.test @@ -15,12 +15,12 @@ Assets:Testing123ÕßDone test accounts +Assets:AAA Assets:Bank -Equity:Opening balance +Assets:Testing123ÕßDone Assets:XXX -Assets:AAA Assets:♚ -Assets:Testing123ÕßDone +Equity:Opening balance end test test accounts assets:a diff --git a/test/baseline/cmd-commodities.test b/test/baseline/cmd-commodities.test index 0ce6f7a0..719b6798 100644 --- a/test/baseline/cmd-commodities.test +++ b/test/baseline/cmd-commodities.test @@ -15,10 +15,10 @@ Income:Rewards test commodities -GBP -AAA "AA2" "M&M" +AAA +GBP end test test commodities Assets:Rewards diff --git a/test/baseline/cmd-convert.test b/test/baseline/cmd-convert.test index 1c36d4bb..d444da52 100644 --- a/test/baseline/cmd-convert.test +++ b/test/baseline/cmd-convert.test @@ -4,7 +4,7 @@ test -f /dev/null --input-date-format "%m/%d/%Y" convert test/baseline/cmd-conve Expenses:Unknown $10 Equity:Unknown $-10 = $20 -2011/12/12=2011/12/12 * ; +2011/12/12=2011/12/12 * Expenses:Unknown $10 Equity:Unknown end test diff --git a/test/baseline/feat-convert-with-diretives.dat b/test/baseline/feat-convert-with-diretives.dat new file mode 100644 index 00000000..ac13ff81 --- /dev/null +++ b/test/baseline/feat-convert-with-diretives.dat @@ -0,0 +1,3 @@ +date,payee,amount +2012/01/01,KFC,$10 +2012/01/02,"REWE SAGT DANKE 123454321",10€ diff --git a/test/baseline/feat-convert-with-diretives.test b/test/baseline/feat-convert-with-diretives.test new file mode 100644 index 00000000..2f6e0102 --- /dev/null +++ b/test/baseline/feat-convert-with-diretives.test @@ -0,0 +1,28 @@ +account Expenses:Food + payee KFC + payee REWE + +payee REWE + alias REWE SAGT DANKE + +# When reading csv file without directives: +test -f /dev/null convert test/baseline/feat-convert-with-diretives.dat +2012/01/01 * KFC + Expenses:Unknown $10 + Equity:Unknown + +2012/01/02 * REWE SAGT DANKE 123454321 + Expenses:Unknown 10€ + Equity:Unknown +end test + +# When reading csv file with directives: +test --account "Assets:Cash" convert test/baseline/feat-convert-with-diretives.dat +2012/01/01 * KFC + Expenses:Food $10 + Assets:Cash + +2012/01/02 * REWE + Expenses:Food 10€ + Assets:Cash +end test diff --git a/test/baseline/opt-aux-date.test b/test/baseline/opt-aux-date.test index 9d1e73d0..495bb7e6 100644 --- a/test/baseline/opt-aux-date.test +++ b/test/baseline/opt-aux-date.test @@ -10,7 +10,7 @@ Expenses:Books $20.00 Assets:Cash -test reg --effective +test reg --aux-date 08-Jan-01 January Expenses:Books $10.00 $10.00 Assets:Cash $-10.00 0 08-Feb-01 End of January Expenses:Books $10.00 $10.00 diff --git a/test/baseline/opt-count.test b/test/baseline/opt-count.test index 9c5495c8..7c935c7a 100644 --- a/test/baseline/opt-count.test +++ b/test/baseline/opt-count.test @@ -17,14 +17,14 @@ Assets:Cash -30.00 EUR test accounts --count -2 Expenses:Phone 4 Assets:Cash +2 Expenses:Phone 2 Expenses:Rent end test test commodities --count -4 GBP 4 EUR +4 GBP end test test payees --count @@ -33,8 +33,8 @@ test payees --count end test test commodities :rent --count -1 GBP 1 EUR +1 GBP end test test payees tag bnb --count diff --git a/test/regress/0161EB1E.test b/test/regress/0161EB1E.test new file mode 100644 index 00000000..93498ad5 --- /dev/null +++ b/test/regress/0161EB1E.test @@ -0,0 +1,15 @@ +bucket Assets:Checking +2011/04/25 Tom's Used Cars + Auto $ 5,500.00 + ; :nobudget: + +A Assets:Checking +2011/04/27 Book Store + Books $20.00 + +test reg +11-Apr-25 Tom's Used Cars Auto $ 5,500.00 $ 5,500.00 + Assets:Checking $ -5,500.00 0 +11-Apr-27 Book Store Books $ 20.00 $ 20.00 + Assets:Checking $ -20.00 0 +end test diff --git a/test/regress/0DDDEBC0.dat b/test/regress/0DDDEBC0.dat new file mode 100644 index 00000000..21b6fce1 --- /dev/null +++ b/test/regress/0DDDEBC0.dat @@ -0,0 +1,3 @@ +date,posted,amount, +12/12/2011,12/13/2011,$10, +12/12/2011,,$20, diff --git a/test/regress/0DDDEBC0.test b/test/regress/0DDDEBC0.test new file mode 100644 index 00000000..cccb1b6b --- /dev/null +++ b/test/regress/0DDDEBC0.test @@ -0,0 +1,9 @@ +test -f /dev/null --input-date-format '%m/%d/%Y' convert test/regress/0DDDEBC0.dat +2011/12/12=2011/12/13 * + Expenses:Unknown $10 + Equity:Unknown + +2011/12/12 * + Expenses:Unknown $20 + Equity:Unknown +end test diff --git a/test/regress/25A099C9.test b/test/regress/25A099C9.test index d4eab662..fb362a4b 100644 --- a/test/regress/25A099C9.test +++ b/test/regress/25A099C9.test @@ -20,24 +20,24 @@ While parsing file "$sourcepath/src/amount.h", line 121: Error: Unexpected whitespace at beginning of line While parsing file "$sourcepath/src/amount.h", line 132: Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/src/amount.h", line 702: +While parsing file "$sourcepath/src/amount.h", line 711: Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/src/amount.h", line 732: +While parsing file "$sourcepath/src/amount.h", line 741: Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/src/amount.h", line 740: +While parsing file "$sourcepath/src/amount.h", line 749: Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/src/amount.h", line 743: +While parsing file "$sourcepath/src/amount.h", line 752: Error: Invalid date/time: line amount_t amoun -While parsing file "$sourcepath/src/amount.h", line 749: +While parsing file "$sourcepath/src/amount.h", line 758: Error: Invalid date/time: line string amount_ -While parsing file "$sourcepath/src/amount.h", line 755: +While parsing file "$sourcepath/src/amount.h", line 764: Error: Invalid date/time: line string amount_ -While parsing file "$sourcepath/src/amount.h", line 761: +While parsing file "$sourcepath/src/amount.h", line 770: Error: Invalid date/time: line string amount_ -While parsing file "$sourcepath/src/amount.h", line 767: +While parsing file "$sourcepath/src/amount.h", line 776: Error: Invalid date/time: line std::ostream& -While parsing file "$sourcepath/src/amount.h", line 774: +While parsing file "$sourcepath/src/amount.h", line 783: Error: Invalid date/time: line std::istream& -While parsing file "$sourcepath/src/amount.h", line 780: +While parsing file "$sourcepath/src/amount.h", line 789: Error: Unexpected whitespace at beginning of line end test diff --git a/test/regress/68917252.dat b/test/regress/68917252.dat new file mode 100644 index 00000000..8857f741 --- /dev/null +++ b/test/regress/68917252.dat @@ -0,0 +1,2 @@ +date,amount, +12/12/2011,10,test,extra,fields diff --git a/test/regress/68917252.test b/test/regress/68917252.test new file mode 100644 index 00000000..52fde1d9 --- /dev/null +++ b/test/regress/68917252.test @@ -0,0 +1,5 @@ +test -f /dev/null --input-date-format "%m/%d/%Y" convert test/regress/68917252.dat +2011/12/12 * + Expenses:Unknown 10 + Equity:Unknown +end test diff --git a/test/regress/A3FA7601.dat b/test/regress/A3FA7601.dat new file mode 100644 index 00000000..9a734e67 --- /dev/null +++ b/test/regress/A3FA7601.dat @@ -0,0 +1,3 @@ +date,posted,code,payee,amount,total,note, +12/12/2011,12/13/2011,100,Test,$10,$20,test, +12/12/2011,12/12/2011,,,$10,$20, diff --git a/test/regress/A3FA7601.test b/test/regress/A3FA7601.test new file mode 100644 index 00000000..5029f6d8 --- /dev/null +++ b/test/regress/A3FA7601.test @@ -0,0 +1,9 @@ +test -f /dev/null --input-date-format '%m/%d/%Y' convert test/regress/A3FA7601.dat +2011/12/12=2011/12/13 * (100) Test ;test + Expenses:Unknown $10 + Equity:Unknown $-10 = $20 + +2011/12/12=2011/12/12 * + Expenses:Unknown $10 + Equity:Unknown $-10 = $20 +end test diff --git a/test/regress/BF3C1F82-2.test b/test/regress/BF3C1F82-2.test new file mode 100644 index 00000000..453151ce --- /dev/null +++ b/test/regress/BF3C1F82-2.test @@ -0,0 +1,12 @@ +; Check that include directives are relative for "-f /dev/stdin" +include non-existent-ledger-file-BF3C1F82 +test -f - reg -> 1 +__ERROR__ +While parsing file "", line 2: +Error: File to include was not found: "./non-existent-ledger-file-BF3C1F82" +end test +test -f /dev/stdin reg -> 1 +__ERROR__ +While parsing file "", line 2: +Error: File to include was not found: "./non-existent-ledger-file-BF3C1F82" +end test diff --git a/test/regress/BF3C1F82.test b/test/regress/BF3C1F82.test new file mode 100644 index 00000000..50f4106f --- /dev/null +++ b/test/regress/BF3C1F82.test @@ -0,0 +1,19 @@ +; Check that error reporting works for "-f -" + +2012/02/30 * Test + a 1 + b +test -f - reg -> 1 +__ERROR__ +While parsing file "", line 3: +While parsing transaction: +<no source context> +Error: Day of month is not valid for year +end test +test -f /dev/stdin reg -> 1 +__ERROR__ +While parsing file "", line 3: +While parsing transaction: +<no source context> +Error: Day of month is not valid for year +end test diff --git a/test/regress/CAE63F5C-a.test b/test/regress/CAE63F5C-a.test new file mode 100644 index 00000000..4465bd2f --- /dev/null +++ b/test/regress/CAE63F5C-a.test @@ -0,0 +1,17 @@ +2011/03/01 test1 + a 4.00 € + b + +2011/03/02 test2 + a 4.00 € + b + +2011/03/03 test2 + a 4.00 € + b + +test reg a +11-Mar-01 test1 a 4.00 € 4.00 € +11-Mar-02 test2 a 4.00 € 8.00 € +11-Mar-03 test2 a 4.00 € 12.00 € +end test diff --git a/test/regress/CAE63F5C-b.test b/test/regress/CAE63F5C-b.test new file mode 100644 index 00000000..c0b7efd8 --- /dev/null +++ b/test/regress/CAE63F5C-b.test @@ -0,0 +1,15 @@ +2012/08/22 Payment + Accrued €208.00 {=$1.3109} @ $1.2799 + Expenses €4.16 {=$1.2798689} @ $1.2799 + Assets $-271.54 + Income:Currency Conversion $-6.45 + +test bal -X $ + $272.67 Accrued + $-271.54 Assets + $6.45 Equity:Capital Gains + $5.32 Expenses + $-6.45 Income:Currency Conversion +-------------------- + $6.45 +end test diff --git a/test/regress/CAE63F5C-c.test b/test/regress/CAE63F5C-c.test new file mode 100644 index 00000000..ae2d7d10 --- /dev/null +++ b/test/regress/CAE63F5C-c.test @@ -0,0 +1,15 @@ +2012/08/22 Payment + Accrued €208.00 {=$1.3109} @ $1.2798689 + Expenses €4.16 {=$1.2798689} @ $1.2798689 + Assets $-271.54 + Income:Currency Conversion $-6.45 + +test bal -X $ + $272.67 Accrued + $-271.54 Assets + $6.45 Equity:Capital Gains + $5.32 Expenses + $-6.45 Income:Currency Conversion +-------------------- + $6.45 +end test diff --git a/test/regress/CMakeLists.txt b/test/regress/CMakeLists.txt index 4b6232dd..26f55e84 100644 --- a/test/regress/CMakeLists.txt +++ b/test/regress/CMakeLists.txt @@ -1,19 +1 @@ -if(HAVE_BOOST_PYTHON) - set(TEST_PYTHON_FLAGS "--python") -endif() - -if(PYTHONINTERP_FOUND) - file(GLOB REGRESSION_TESTS *.test) - foreach(TestFile ${REGRESSION_TESTS}) - get_filename_component(TestFile_Name ${TestFile} NAME_WE) - string(FIND ${TestFile_Name} "_py" TestFile_IsPythonTest) - if((NOT TestFile_IsPythonTest) OR HAVE_BOOST_PYTHON) - add_test(RegressionTest_${TestFile_Name} - ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/RegressTests.py - ${LEDGER_LOCATION} ${PROJECT_SOURCE_DIR} - ${TestFile} ${TEST_PYTHON_FLAGS}) - set_target_properties(check - PROPERTIES DEPENDS RegressionTest_${TestFile_Name}) - endif() - endforeach() -endif() +add_ledger_harness_tests(Regress) diff --git a/test/regress/xact_code.dat b/test/regress/xact_code.dat new file mode 100644 index 00000000..60956a23 --- /dev/null +++ b/test/regress/xact_code.dat @@ -0,0 +1,3 @@ +2012-11-10 (C0-d3) Payee + Assets:Checking € -12,45 + Expenses:Expenditure diff --git a/test/regress/xact_code.py b/test/regress/xact_code.py new file mode 100644 index 00000000..64abb17d --- /dev/null +++ b/test/regress/xact_code.py @@ -0,0 +1,4 @@ +import ledger + +for post in ledger.read_journal('test/regress/xact_code.dat').query('expenses'): + print post.xact.code diff --git a/test/regress/xact_code_py.test b/test/regress/xact_code_py.test new file mode 100644 index 00000000..c22158e0 --- /dev/null +++ b/test/regress/xact_code_py.test @@ -0,0 +1,3 @@ +test python test/regress/xact_code.py +C0-d3 +end test diff --git a/test/unit/t_amount.cc b/test/unit/t_amount.cc index 07cde8f3..b82de510 100644 --- a/test/unit/t_amount.cc +++ b/test/unit/t_amount.cc @@ -1109,6 +1109,60 @@ BOOST_AUTO_TEST_CASE(testCommodityAbs) BOOST_CHECK(x2.valid()); } +BOOST_AUTO_TEST_CASE(testFloor) +{ + amount_t x0; + amount_t x1("123.123"); + amount_t x2("-123.123"); + + BOOST_CHECK_THROW(x0.floored(), amount_error); + BOOST_CHECK_EQUAL(amount_t(123L), x1.floored()); + BOOST_CHECK_EQUAL(amount_t(-124L), x2.floored()); + + BOOST_CHECK(x0.valid()); + BOOST_CHECK(x1.valid()); + BOOST_CHECK(x2.valid()); +} + +BOOST_AUTO_TEST_CASE(testCommodityFloor) +{ + amount_t x1("$1234.56"); + amount_t x2("$-1234.56"); + + BOOST_CHECK_EQUAL(amount_t("$1234"), x1.floored()); + BOOST_CHECK_EQUAL(amount_t("$-1235"), x2.floored()); + + BOOST_CHECK(x1.valid()); + BOOST_CHECK(x2.valid()); +} + +BOOST_AUTO_TEST_CASE(testCeiling) +{ + amount_t x0; + amount_t x1("123.123"); + amount_t x2("-123.123"); + + BOOST_CHECK_THROW(x0.ceilinged(), amount_error); + BOOST_CHECK_EQUAL(amount_t(124L), x1.ceilinged()); + BOOST_CHECK_EQUAL(amount_t(-123L), x2.ceilinged()); + + BOOST_CHECK(x0.valid()); + BOOST_CHECK(x1.valid()); + BOOST_CHECK(x2.valid()); +} + +BOOST_AUTO_TEST_CASE(testCommodityCeiling) +{ + amount_t x1("$1234.56"); + amount_t x2("$-1234.56"); + + BOOST_CHECK_EQUAL(amount_t("$1235"), x1.ceilinged()); + BOOST_CHECK_EQUAL(amount_t("$-1234"), x2.ceilinged()); + + BOOST_CHECK(x1.valid()); + BOOST_CHECK(x2.valid()); +} + #ifndef NOT_FOR_PYTHON #if 0 BOOST_AUTO_TEST_CASE(testReduction) |