summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt31
-rwxr-xr-xtest/DocTests.py22
-rw-r--r--test/baseline/opt-primary-date.test99
-rw-r--r--test/baseline/opt-trace.test15
-rwxr-xr-xtest/convert.py2
-rw-r--r--test/regress/1038_1.test18
-rw-r--r--test/regress/1038_2.test18
-rw-r--r--test/regress/1038_3.test20
-rw-r--r--test/regress/1072.test31
-rw-r--r--test/regress/1074.test161
-rw-r--r--test/regress/5D92A5EB.test2
-rw-r--r--test/regress/730.test37
-rw-r--r--test/regress/A013A73B.test10
13 files changed, 443 insertions, 23 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 0f19ae6f..44db81fb 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -6,8 +6,6 @@ if (NOT PROCESSORS EQUAL 0)
set(CTEST_BUILD_FLAGS -j${JOBS})
endif()
-get_target_property(LEDGER_LOCATION ledger LOCATION)
-
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} ${CTEST_BUILD_FLAGS})
add_subdirectory(unit)
@@ -23,9 +21,9 @@ macro(add_ledger_harness_tests _class)
get_filename_component(TestFile_Name ${TestFile} NAME_WE)
string(FIND ${TestFile_Name} "_py" TestFile_IsPythonTest)
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}
+ add_test(NAME ${_class}Test_${TestFile_Name}
+ COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/RegressTests.py
+ $<TARGET_FILE:ledger> ${PROJECT_SOURCE_DIR}
${TestFile} ${TEST_PYTHON_FLAGS})
set_target_properties(check
PROPERTIES DEPENDS ${_class}Test_${TestFile_Name})
@@ -38,17 +36,16 @@ add_subdirectory(manual)
add_subdirectory(baseline)
add_subdirectory(regress)
-# jww (2014-04-17): This is temporary until we find a fix.
-#if (PYTHONINTERP_FOUND)
-# set(_class DocTests)
-# file(GLOB ${_class}_TESTS ${PROJECT_SOURCE_DIR}/doc/*.texi)
-# foreach(TestFile ${${_class}_TESTS})
-# get_filename_component(TestFile_Name ${TestFile} NAME_WE)
-# add_test(${_class}Test_${TestFile_Name}
-# ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/DocTests.py
-# --ledger ${LEDGER_LOCATION} --file ${TestFile})
-# set_target_properties(check PROPERTIES DEPENDS ${_class}Test_${TestFile_Name})
-# endforeach()
-#endif()
+if (PYTHONINTERP_FOUND)
+ set(_class DocTests)
+ file(GLOB ${_class}_TESTS ${PROJECT_SOURCE_DIR}/doc/*.texi)
+ foreach(TestFile ${${_class}_TESTS})
+ get_filename_component(TestFile_Name ${TestFile} NAME_WE)
+ add_test(NAME ${_class}Test_${TestFile_Name}
+ COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/DocTests.py
+ --ledger $<TARGET_FILE:ledger> --file ${TestFile})
+ set_target_properties(check PROPERTIES DEPENDS ${_class}Test_${TestFile_Name})
+ endforeach()
+endif()
### CMakeLists.txt ends here
diff --git a/test/DocTests.py b/test/DocTests.py
index d2931686..ea32608e 100755
--- a/test/DocTests.py
+++ b/test/DocTests.py
@@ -16,6 +16,7 @@ class DocTests:
self.ledger = os.path.abspath(args.ledger)
self.sourcepath = os.path.abspath(args.file)
self.verbose = args.verbose
+ self.tests = args.examples
self.examples = dict()
self.test_files = list()
@@ -114,8 +115,9 @@ class DocTests:
if command[0] == '$': command.remove('$')
index = command.index('ledger')
command[index] = self.ledger
- command.insert(index+1, '--init-file')
- command.insert(index+2, '/dev/null')
+ for i,argument in enumerate('--args-only --columns 80'.split()):
+ command.insert(index+i+1, argument)
+
try:
findex = command.index('-f')
except ValueError:
@@ -132,7 +134,14 @@ class DocTests:
def test_examples(self):
failed = set()
- for test_id in self.examples:
+ tests = self.examples.keys()
+ if self.tests:
+ tests = list(set(self.tests).intersection(tests))
+ temp = list(set(self.tests).difference(tests))
+ if len(temp) > 0:
+ print >> sys.stderr, 'Skipping non-existent examples: %s' % ', '.join(temp)
+
+ for test_id in tests:
validation = False
if "validate-data" in self.examples[test_id] or "validate-command" in self.examples[test_id]:
validation = True
@@ -212,7 +221,7 @@ class DocTests:
if __name__ == "__main__":
def getargs():
- parser = argparse.ArgumentParser(description='DocTests', prefix_chars='-')
+ parser = argparse.ArgumentParser(prog='DocTests', description='Test ledger examples from the documentation', prefix_chars='-')
parser.add_argument('-v', '--verbose',
dest='verbose',
action='count',
@@ -229,6 +238,11 @@ if __name__ == "__main__":
action='store',
required=True,
help='the texinfo documentation file to run the examples from')
+ parser.add_argument('examples',
+ metavar='EXAMPLE',
+ type=str,
+ nargs='*',
+ help='the examples to test')
return parser.parse_args()
args = getargs()
diff --git a/test/baseline/opt-primary-date.test b/test/baseline/opt-primary-date.test
index e69de29b..e433a8f9 100644
--- a/test/baseline/opt-primary-date.test
+++ b/test/baseline/opt-primary-date.test
@@ -0,0 +1,99 @@
+; primary-date display primary dates for all calculations
+2014/01/01=2014/01/13 Client invoice ; estimated date you'll be paid
+ Assets:Accounts Receivable $100.00
+ Income: Client ABC
+
+2014/01/01=2014/01/15 Client invoice ; actual date money received
+ Assets:Accounts Receivable $100.00
+ Income: Client ABC
+
+; will not affect checking account
+2013/10/16 * (2090) Bountiful Blessings Farm
+ Expenses:Food:Groceries $ 37.50 ; [=2013/10/01]
+ Expenses:Food:Groceries $ 37.50 ; [=2013/11/01]
+ Expenses:Food:Groceries $ 37.50 ; [=2013/12/01]
+ Expenses:Food:Groceries $ 37.50 ; [=2014/01/01]
+ Expenses:Food:Groceries $ 37.50 ; [=2014/02/01]
+ Expenses:Food:Groceries $ 37.50 ; [=2014/03/01]
+ Assets:Checking
+
+
+test bal Income --begin 2014/01/01 --end 2014/01/14
+ $ -200.00 Income: Client ABC
+end test
+
+test bal Income --effective --begin 2014/01/01 --end 2014/01/14
+ $ -100.00 Income: Client ABC
+end test
+
+test bal Income --primary-date --effective --begin 2014/01/01 --end 2014/01/14
+ $ -200.00 Income: Client ABC
+end test
+
+test bal Income --actual-dates --effective --begin 2014/01/01 --end 2014/01/14
+ $ -200.00 Income: Client ABC
+end test
+
+test reg Income --begin 2014/01/01 --end 2014/01/14
+14-Jan-01 Client invoice Income: Client ABC $ -100.00 $ -100.00
+14-Jan-01 Client invoice Income: Client ABC $ -100.00 $ -200.00
+end test
+
+test reg Income --effective --begin 2014/01/01 --end 2014/01/14
+14-Jan-13 Client invoice Income: Client ABC $ -100.00 $ -100.00
+end test
+
+test reg Income --primary-date --effective --begin 2014/01/01 --end 2014/01/14
+14-Jan-01 Client invoice Income: Client ABC $ -100.00 $ -100.00
+14-Jan-01 Client invoice Income: Client ABC $ -100.00 $ -200.00
+end test
+
+test reg Income --actual-dates --effective --begin 2014/01/01 --end 2014/01/14
+14-Jan-01 Client invoice Income: Client ABC $ -100.00 $ -100.00
+14-Jan-01 Client invoice Income: Client ABC $ -100.00 $ -200.00
+end test
+
+test reg checking
+13-Oct-16 Bountiful Blessings.. Assets:Checking $ -225.00 $ -225.00
+end test
+
+test reg checking --primary-date --effective
+13-Oct-16 Bountiful Blessings.. Assets:Checking $ -225.00 $ -225.00
+end test
+
+test register Groceries
+13-Oct-16 Bountiful Blessings.. Expense:Food:Groceries $ 37.50 $ 37.50
+ Expense:Food:Groceries $ 37.50 $ 75.00
+ Expense:Food:Groceries $ 37.50 $ 112.50
+ Expense:Food:Groceries $ 37.50 $ 150.00
+ Expense:Food:Groceries $ 37.50 $ 187.50
+ Expense:Food:Groceries $ 37.50 $ 225.00
+end test
+
+test register Groceries --effective
+13-Oct-01 Bountiful Blessings.. Expense:Food:Groceries $ 37.50 $ 37.50
+13-Nov-01 Bountiful Blessings.. Expense:Food:Groceries $ 37.50 $ 75.00
+13-Dec-01 Bountiful Blessings.. Expense:Food:Groceries $ 37.50 $ 112.50
+14-Jan-01 Bountiful Blessings.. Expense:Food:Groceries $ 37.50 $ 150.00
+14-Feb-01 Bountiful Blessings.. Expense:Food:Groceries $ 37.50 $ 187.50
+14-Mar-01 Bountiful Blessings.. Expense:Food:Groceries $ 37.50 $ 225.00
+end test
+
+test register Groceries --primary-date --effective
+13-Oct-16 Bountiful Blessings.. Expense:Food:Groceries $ 37.50 $ 37.50
+ Expense:Food:Groceries $ 37.50 $ 75.00
+ Expense:Food:Groceries $ 37.50 $ 112.50
+ Expense:Food:Groceries $ 37.50 $ 150.00
+ Expense:Food:Groceries $ 37.50 $ 187.50
+ Expense:Food:Groceries $ 37.50 $ 225.00
+end test
+
+test register Groceries --actual-dates --effective
+13-Oct-16 Bountiful Blessings.. Expense:Food:Groceries $ 37.50 $ 37.50
+ Expense:Food:Groceries $ 37.50 $ 75.00
+ Expense:Food:Groceries $ 37.50 $ 112.50
+ Expense:Food:Groceries $ 37.50 $ 150.00
+ Expense:Food:Groceries $ 37.50 $ 187.50
+ Expense:Food:Groceries $ 37.50 $ 225.00
+end test
+
diff --git a/test/baseline/opt-trace.test b/test/baseline/opt-trace.test
new file mode 100644
index 00000000..9034018e
--- /dev/null
+++ b/test/baseline/opt-trace.test
@@ -0,0 +1,15 @@
+2007/02/02 RD VMMXX
+ Assets:Investments:Vanguard:VMMXX 0.350 VMMXX @ $1.00
+ Income:Dividends:Vanguard:VMMXX $-0.35
+
+; Using values with two or more digits as the argument to the --trace option
+; resulted in a segmentation fault.
+; Since ledger prints debugging information to stderr when the --trace option
+; was given and that debugging information contains timing information, e.g. [1ms]
+; which is likely to differ on each test run, this test only checks that ledger
+; does not crash when the --trace options was specified.
+test reg --trace 10 2>/dev/null
+07-Feb-02 RD VMMXX As:Inves:Vanguar:VMMXX 0.350 VMMXX 0.350 VMMXX
+ In:Divid:Vanguar:VMMXX $-0.35 $-0.35
+ 0.350 VMMXX
+end test
diff --git a/test/convert.py b/test/convert.py
index ae44b39f..5328c4ae 100755
--- a/test/convert.py
+++ b/test/convert.py
@@ -3,7 +3,7 @@
# convert.py: This script converts a Boost.Test unit test into an
# equivalent Python unit test.
#
-# Copyright (c) 2003-2010, John Wiegley. All rights reserved.
+# Copyright (c) 2003-2015, John Wiegley. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
diff --git a/test/regress/1038_1.test b/test/regress/1038_1.test
new file mode 100644
index 00000000..c833816e
--- /dev/null
+++ b/test/regress/1038_1.test
@@ -0,0 +1,18 @@
+Y2014
+
+04/13 Bank
+ Expenses:Loan $400
+ Assets:Cash
+
+05/13 Bug 1038 Test
+ Expenses:Some:Account $500
+ Assets:Cash
+
+06/13 Landlord
+ Expenses:Rent $600
+ Assets:Cash
+
+test reg --now 2014-05-14 -p 'this month'
+14-May-13 Bug 1038 Test Expenses:Some:Account $500 $500
+ Assets:Cash $-500 0
+end test
diff --git a/test/regress/1038_2.test b/test/regress/1038_2.test
new file mode 100644
index 00000000..ce0c046d
--- /dev/null
+++ b/test/regress/1038_2.test
@@ -0,0 +1,18 @@
+year 2014
+
+04/13 Bank
+ Expenses:Loan $400
+ Assets:Cash
+
+05/13 Bug 1038 Test
+ Expenses:Some:Account $500
+ Assets:Cash
+
+06/13 Landlord
+ Expenses:Rent $600
+ Assets:Cash
+
+test reg --now 2014-05-14 -p 'this month'
+14-May-13 Bug 1038 Test Expenses:Some:Account $500 $500
+ Assets:Cash $-500 0
+end test
diff --git a/test/regress/1038_3.test b/test/regress/1038_3.test
new file mode 100644
index 00000000..0e277d71
--- /dev/null
+++ b/test/regress/1038_3.test
@@ -0,0 +1,20 @@
+apply year 2014
+
+04/13 Bank
+ Expenses:Loan $400
+ Assets:Cash
+
+05/13 Bug 1038 Test
+ Expenses:Some:Account $500
+ Assets:Cash
+
+06/13 Landlord
+ Expenses:Rent $600
+ Assets:Cash
+
+end apply
+
+test reg --now 2014-05-14 -p 'this month'
+14-May-13 Bug 1038 Test Expenses:Some:Account $500 $500
+ Assets:Cash $-500 0
+end test
diff --git a/test/regress/1072.test b/test/regress/1072.test
new file mode 100644
index 00000000..3f58b83f
--- /dev/null
+++ b/test/regress/1072.test
@@ -0,0 +1,31 @@
+
+--input-date-format %d/%m/%y
+--date-format %d/%m/%y
+
+1/1/14 * Test
+ A $10
+ B
+
+12/1/14 * Test
+ A $20
+ B
+
+test --input-date-format %d/%m/%y reg --begin 2/1/13
+01/01/14 Test A $10 $10
+ B $-10 0
+12/01/14 Test A $20 $20
+ B $-20 0
+end test
+
+test --input-date-format %d/%m/%y reg --begin 1/1/14
+01/01/14 Test A $10 $10
+ B $-10 0
+12/01/14 Test A $20 $20
+ B $-20 0
+end test
+
+test --input-date-format %d/%m/%y reg --begin 2/1/14
+12/01/14 Test A $20 $20
+ B $-20 0
+end test
+
diff --git a/test/regress/1074.test b/test/regress/1074.test
new file mode 100644
index 00000000..1aaf0ca0
--- /dev/null
+++ b/test/regress/1074.test
@@ -0,0 +1,161 @@
+
+--input-date-format %Y-%m-%d
+--date-format %Y-%m-%d
+
+2011-06-01 * Jun 2011
+ A $10
+ B
+
+2011-07-01 * Jul 2011
+ A $10
+ B
+
+2011-08-01 * Aug 2011
+ A $10
+ B
+
+2012-06-01 * Jun 2012
+ A $10
+ B
+
+2012-07-01 * Jul 2012
+ A $10
+ B
+
+2012-08-01 * Aug 2012
+ A $10
+ B
+
+2013-06-01 * Jun 2013
+ A $10
+ B
+
+2013-07-01 * Jul 2013
+ A $10
+ B
+
+2013-08-01 * Aug 2013
+ A $10
+ B
+
+2014-06-01 * Jun 2014
+ A $10
+ B
+
+2014-07-01 * Jul 2014
+ A $10
+ B
+
+2014-08-01 * Aug 2014
+ A $10
+ B
+
+2015-06-01 * Jun 2015
+ A $10
+ B
+
+2015-07-01 * Jul 2015
+ A $10
+ B
+
+2015-08-01 * Aug 2015
+ A $10
+ B
+
+test --now 2012-02-03 reg -p "from june to july"
+2012-06-01 Jun 2012 A $10 $10
+ B $-10 0
+end test
+
+test --now 2013-02-03 reg -p "from june to july"
+2013-06-01 Jun 2013 A $10 $10
+ B $-10 0
+end test
+
+test --now 2014-02-03 reg -p "from june to july"
+2014-06-01 Jun 2014 A $10 $10
+ B $-10 0
+end test
+
+test --now 2014-10-02 reg -p "from june to july"
+2014-06-01 Jun 2014 A $10 $10
+ B $-10 0
+end test
+
+test --now 2012-02-03 reg -p "from june to july 2014"
+2012-06-01 Jun 2012 A $10 $10
+ B $-10 0
+2012-07-01 Jul 2012 A $10 $10
+ B $-10 0
+2012-08-01 Aug 2012 A $10 $10
+ B $-10 0
+2013-06-01 Jun 2013 A $10 $10
+ B $-10 0
+2013-07-01 Jul 2013 A $10 $10
+ B $-10 0
+2013-08-01 Aug 2013 A $10 $10
+ B $-10 0
+2014-06-01 Jun 2014 A $10 $10
+ B $-10 0
+end test
+
+test --now 2013-10-02 reg -p "from june to july 2014"
+2013-06-01 Jun 2013 A $10 $10
+ B $-10 0
+2013-07-01 Jul 2013 A $10 $10
+ B $-10 0
+2013-08-01 Aug 2013 A $10 $10
+ B $-10 0
+2014-06-01 Jun 2014 A $10 $10
+ B $-10 0
+end test
+
+test --now 2014-01-02 reg -p "from june to july 2014"
+2014-06-01 Jun 2014 A $10 $10
+ B $-10 0
+end test
+
+test --now 2014-10-02 reg -p "from june to july 2014"
+2014-06-01 Jun 2014 A $10 $10
+ B $-10 0
+end test
+
+test --now 2012-02-03 reg -p "from june 2012 to july 2014"
+2012-06-01 Jun 2012 A $10 $10
+ B $-10 0
+2012-07-01 Jul 2012 A $10 $10
+ B $-10 0
+2012-08-01 Aug 2012 A $10 $10
+ B $-10 0
+2013-06-01 Jun 2013 A $10 $10
+ B $-10 0
+2013-07-01 Jul 2013 A $10 $10
+ B $-10 0
+2013-08-01 Aug 2013 A $10 $10
+ B $-10 0
+2014-06-01 Jun 2014 A $10 $10
+ B $-10 0
+end test
+
+test --now 2012-02-03 reg -p "from june 2013 to july 2014"
+2013-06-01 Jun 2013 A $10 $10
+ B $-10 0
+2013-07-01 Jul 2013 A $10 $10
+ B $-10 0
+2013-08-01 Aug 2013 A $10 $10
+ B $-10 0
+2014-06-01 Jun 2014 A $10 $10
+ B $-10 0
+end test
+
+test --now 2015-02-03 reg -p "from june 2013 to july 2014"
+2013-06-01 Jun 2013 A $10 $10
+ B $-10 0
+2013-07-01 Jul 2013 A $10 $10
+ B $-10 0
+2013-08-01 Aug 2013 A $10 $10
+ B $-10 0
+2014-06-01 Jun 2014 A $10 $10
+ B $-10 0
+end test
+
diff --git a/test/regress/5D92A5EB.test b/test/regress/5D92A5EB.test
index 6d29eda6..57fcadb3 100644
--- a/test/regress/5D92A5EB.test
+++ b/test/regress/5D92A5EB.test
@@ -29,6 +29,6 @@ While parsing periodic transaction:
> Liabilities:Education:ULL $100.00
> Liabilities:Mortgage $100.00
> Assets:Bank:Checking
-Error: Posting with null amount's account may be mispelled:
+Error: Posting with null amount's account may be misspelled:
"Expenses:Entertainment:Blizzard $100.00"
end test
diff --git a/test/regress/730.test b/test/regress/730.test
new file mode 100644
index 00000000..d81a1c22
--- /dev/null
+++ b/test/regress/730.test
@@ -0,0 +1,37 @@
+; Using -M in combination with an empty result causes a segmentation fault
+; therefore this test case does not have or need any test data
+
+test -f /dev/null -M reg
+end test
+
+; Tests mentioned in #730
+test reg -M
+end test
+
+test reg -M .foo
+end test
+
+test reg -M -e 2012/01
+end test
+
+
+; Tests mentioned in #1080
+test reg '^Expenses' and expr 'any(account =~ /^Assets:Cash/)' --period 'every week this month'
+end test
+
+test bal '^Expenses' and expr 'any(account =~ /^Assets:Cash/)' --period 'every week this month'
+end test
+
+test bal reg foo and expr 'any(account =~ /bar/)' --period 'every week'
+end test
+
+
+; Tests mentioned in #1084
+test b abc -M
+end test
+
+test reg foo -M
+end test
+
+test bal foo -M
+end test
diff --git a/test/regress/A013A73B.test b/test/regress/A013A73B.test
new file mode 100644
index 00000000..251277ea
--- /dev/null
+++ b/test/regress/A013A73B.test
@@ -0,0 +1,10 @@
+
+2014-01-01 c ; x
+ a 1
+ b
+
+test reg
+14-Jan-01 c a 1 1
+ b -1 0
+end test
+