From f6c087cfe48e6410db61a9367ce7c718a490af77 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 1 Mar 2012 17:32:51 -0600 Subject: Added a new 'python' directive --- test/RegressTests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/RegressTests.py') diff --git a/test/RegressTests.py b/test/RegressTests.py index 28a6c709..def202e4 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -179,7 +179,9 @@ if __name__ == '__main__': if os.path.isdir(tests): tests = [os.path.join(tests, x) - for x in os.listdir(tests) if x.endswith('.test')] + for x in os.listdir(tests) + if (x.endswith('.test') and + (not '_py.test' in x or harness.python))] if pool: pool.map(do_test, tests, 1) else: -- cgit v1.2.3 From c813eafbd8aaad5d66c3eb8857393c9fa1c98db6 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 9 Mar 2012 03:57:30 -0600 Subject: Display file name when a regression test fails --- test/LedgerHarness.py | 4 +++- test/RegressTests.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'test/RegressTests.py') diff --git a/test/LedgerHarness.py b/test/LedgerHarness.py index 7b4dfa83..564a4d32 100755 --- a/test/LedgerHarness.py +++ b/test/LedgerHarness.py @@ -112,8 +112,10 @@ class LedgerHarness: sys.stdout.write(".") self.succeeded += 1 - def failure(self): + def failure(self, name=None): sys.stdout.write("E") + if name: + sys.stdout.write("[%s]" % name) self.failed += 1 def exit(self): diff --git a/test/RegressTests.py b/test/RegressTests.py index def202e4..da5d92ca 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -148,14 +148,14 @@ class RegressFile(object): if success: harness.success() else: - harness.failure() + harness.failure(os.path.basename(self.filename)) else: if success: print if test['exitcode']: self.notify_user("FAILURE in exit code (%d != %d) from %s:" % (test['exitcode'], p.returncode, self.filename), test) - harness.failure() + harness.failure(os.path.basename(self.filename)) def run_tests(self): test = self.read_test() -- cgit v1.2.3 From 2df8edc71c1e805fd54c2208b2b66bdde0460c59 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 9 Mar 2012 20:02:53 -0600 Subject: Improved the behavior of -X --- src/system.hh.in | 2 + src/value.cc | 101 ++++++++++++++++++++++++++++++++++------ test/RegressTests.py | 2 + test/baseline/opt-exchange.test | 57 +++++++++++++++++++++++ test/regress/83B4A0E5.test | 43 +++++++++++++++++ 5 files changed, 192 insertions(+), 13 deletions(-) create mode 100644 test/regress/83B4A0E5.test (limited to 'test/RegressTests.py') diff --git a/src/system.hh.in b/src/system.hh.in index fcc8e2ce..a38deb1f 100644 --- a/src/system.hh.in +++ b/src/system.hh.in @@ -185,6 +185,8 @@ typedef std::ostream::pos_type ostream_pos_type; #include #endif // HAVE_BOOST_REGEX_UNICODE +#include + #include #include diff --git a/src/value.cc b/src/value.cc index 6e1ed79d..87b31cd6 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1436,21 +1436,96 @@ value_t value_t::exchange_commodities(const std::string& commodities, const bool add_prices, const optional& moment) { - scoped_array buf(new char[commodities.length() + 1]); - - std::strcpy(buf.get(), commodities.c_str()); - - for (char * p = std::strtok(buf.get(), ","); - p; - p = std::strtok(NULL, ",")) { - if (commodity_t * commodity = - commodity_pool_t::current_pool->parse_price_expression(p, add_prices, - moment)) { - value_t result = value(moment, *commodity); - if (! result.is_null()) - return result; + if (type() == SEQUENCE) { + value_t temp; + foreach (value_t& value, as_sequence_lval()) + temp.push_back(value.exchange_commodities(commodities, add_prices, moment)); + return temp; + } + + // If we are repricing to just a single commodity, with no price + // expression, skip the expensive logic below. + if (commodities.find(',') == string::npos && + commodities.find('=') == string::npos) + return value(moment, *commodity_pool_t::current_pool->find_or_create(commodities)); + + std::vector comms; + std::vector force; + + typedef tokenizer > tokenizer; + tokenizer tokens(commodities, char_separator(",")); + + foreach (const string& name, tokens) { + string::size_type name_len = name.length(); + + if (commodity_t * commodity = commodity_pool_t::current_pool + ->parse_price_expression(name[name_len - 1] == '!' ? + string(name, 0, name_len - 1) : + name, add_prices, moment)) { + DEBUG("commodity.exchange", "Pricing for commodity: " << commodity->symbol()); + comms.push_back(&commodity->referent()); + force.push_back(name[name_len - 1] == '!'); + } + } + + int index = 0; + foreach (commodity_t * comm, comms) { + switch (type()) { + case AMOUNT: + DEBUG("commodity.exchange", "We have an amount: " << as_amount_lval()); + if (! force[index] && + std::find(comms.begin(), comms.end(), + &as_amount_lval().commodity().referent()) != comms.end()) + break; + + DEBUG("commodity.exchange", "Referent doesn't match, pricing..."); + if (optional val = as_amount_lval().value(moment, *comm)) { + DEBUG("commodity.exchange", "Re-priced amount is: " << *val); + return *val; + } + DEBUG("commodity.exchange", "Was unable to find a price"); + break; + + case BALANCE: { + balance_t temp; + bool repriced = false; + + DEBUG("commodity.exchange", "We have a balance: " << as_balance_lval()); + foreach (const balance_t::amounts_map::value_type& pair, + as_balance_lval().amounts) { + DEBUG("commodity.exchange", "We have a balance amount of commodity: " + << pair.first->symbol() << " == " + << pair.second.commodity().symbol()); + if (! force[index] && + std::find(comms.begin(), comms.end(), + &pair.first->referent()) != comms.end()) { + temp += pair.second; + } else { + DEBUG("commodity.exchange", "Referent doesn't match, pricing..."); + if (optional val = pair.second.value(moment, *comm)) { + DEBUG("commodity.exchange", "Re-priced member amount is: " << *val); + temp += *val; + repriced = true; + } else { + DEBUG("commodity.exchange", "Was unable to find price"); + temp += pair.second; + } + } + } + + if (repriced) { + DEBUG("commodity.exchange", "Re-priced balance is: " << temp); + return temp; + } } + + default: + break; + } + + ++index; } + return *this; } diff --git a/test/RegressTests.py b/test/RegressTests.py index da5d92ca..a22e35bf 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -149,6 +149,8 @@ class RegressFile(object): harness.success() else: harness.failure(os.path.basename(self.filename)) + print "STDERR:" + print p.stderr.read() else: if success: print if test['exitcode']: diff --git a/test/baseline/opt-exchange.test b/test/baseline/opt-exchange.test index cfc48c3f..f5d73f78 100644 --- a/test/baseline/opt-exchange.test +++ b/test/baseline/opt-exchange.test @@ -47,6 +47,63 @@ Assets:Brokerage -155 A [2009/01/06] test reg --exchange=' C, A ' +09-Jan-01 January 1st, 2009 (1) Assets:Brokerage 100 A 100 A + Assets:Brokerage -50 A 50 A +09-Jan-01 January 1st, 2009 (2) Assets:Brokerage 100 A 150 A + Assets:Brokerage -75 A 75 A +09-Jan-01 January 1st, 2009 (3) Assets:Brokerage 100 A 175 A + Assets:Brokerage -100 A 75 A +09-Jan-02 Commodities revalued 225 A + -1800 C 300 A + -1800 C +09-Jan-02 January 2nd, 2009 Assets:Brokerage 500 C 300 A + -1300 C + Assets:Brokerage -500 C 300 A + -1800 C +09-Jan-03 January 3rd, 2009 Assets:Brokerage 600 C 300 A + -1200 C + Assets:Brokerage -600 C 300 A + -1800 C +09-Jan-04 January 4th, 2009 Assets:Brokerage 300 A 600 A + -1800 C + Assets:Brokerage -2400 C 600 A + -4200 C +09-Jan-05 January 5th, 2009 Assets:Brokerage 1280 C 600 A + -2920 C + Assets:Brokerage -1280 C 600 A + -4200 C +09-Jan-06 Commodities revalued 2040 C 600 A + -2160 C +09-Jan-06 January 6th, 2009 Assets:Brokerage 155 A 755 A + -2160 C + Assets:Brokerage -186 C 755 A + -2346 C +09-Jan-07 Commodities revalued -86 C 755 A + -2432 C +09-Jan-07 January 7th, 2009 Assets:Brokerage 155 A 910 A + -2432 C + Assets:Brokerage -200 C 910 A + -2632 C +09-Jan-08 Commodities revalued -5613 C 910 A + -8245 C +09-Jan-08 January 8th, 2009 Assets:Brokerage 155 A 1065 A + -8245 C + Assets:Brokerage -200 C 1065 A + -8445 C +09-Jan-09 Commodities revalued -2800 C 1065 A + -11245 C +09-Jan-09 January 9th, 2009 Assets:Brokerage 200 C 1065 A + -11045 C + Assets:Brokerage -155 A 910 A + -11045 C +09-Jan-10 January 10th, 2009 Assets:Brokerage 200 C 910 A + -10845 C + Assets:Brokerage -155 A 755 A + -10845 C +end test + + +test reg --exchange=' C!, A ' 09-Jan-01 January 1st, 2009 (1) Assets:Brokerage 100 A 100 A Assets:Brokerage -50 A 50 A 09-Jan-01 January 1st, 2009 (2) Assets:Brokerage 100 A 150 A diff --git a/test/regress/83B4A0E5.test b/test/regress/83B4A0E5.test new file mode 100644 index 00000000..f9402a2d --- /dev/null +++ b/test/regress/83B4A0E5.test @@ -0,0 +1,43 @@ +P 2012-03-01 EUR $2 +P 2012-03-01 GBP $2 + +2012-03-05 KFC + Expenses:Food 10 EUR + Assets:Cash + +2012-03-10 KFC + Expenses:Food 10 GBP + Assets:Cash + +test reg food +12-Mar-05 KFC Expenses:Food 10 EUR 10 EUR +12-Mar-10 KFC Expenses:Food 10 GBP 10 EUR + 10 GBP +end test + +test reg food -V +12-Mar-05 KFC Expenses:Food $20 $20 +12-Mar-10 KFC Expenses:Food $20 $40 +end test + +test reg food -X '$' +12-Mar-05 KFC Expenses:Food $20 $20 +12-Mar-10 KFC Expenses:Food $20 $40 +end test + +test reg food -X '$,GBP' +12-Mar-05 KFC Expenses:Food $20 $20 +12-Mar-10 KFC Expenses:Food 10 GBP $20 + 10 GBP +end test + +test reg food -X '$!,GBP' +12-Mar-05 KFC Expenses:Food $20 $20 +12-Mar-10 KFC Expenses:Food $20 $40 +end test + +test reg food -X '$,EUR' +12-Mar-05 KFC Expenses:Food 10 EUR 10 EUR +12-Mar-10 KFC Expenses:Food $20 $20 + 10 EUR +end test -- cgit v1.2.3 From b5664ce2efdd698448f93dbe1248e7f8aeefe3fa Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 23 Mar 2012 04:02:01 -0500 Subject: Allow use of $FILE in stdout checks --- test/RegressTests.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/RegressTests.py') diff --git a/test/RegressTests.py b/test/RegressTests.py index a22e35bf..72667311 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -40,6 +40,7 @@ class RegressFile(object): def transform_line(self, line): line = re.sub('\$sourcepath', harness.sourcepath, line) + line = re.sub('\$FILE', self.filename, line) return line def read_test(self): @@ -130,9 +131,7 @@ class RegressFile(object): printed = False index = 0 if test['error'] is not None: - for line in unified_diff([re.sub('\$FILE', self.filename, line) - for line in test['error']], - harness.readlines(p.stderr)): + for line in unified_diff(test['error'], harness.readlines(p.stderr)): index += 1 if index < 3: continue -- cgit v1.2.3 From 1809e63fb0e6f7e64d7c2af73e41a24225809ea2 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 30 Mar 2012 04:49:45 -0500 Subject: Added a test harness error diagnostic --- test/ConfirmTests.py | 2 ++ test/RegressTests.py | 2 ++ 2 files changed, 4 insertions(+) (limited to 'test/RegressTests.py') diff --git a/test/ConfirmTests.py b/test/ConfirmTests.py index 6fc04336..dffa74a6 100755 --- a/test/ConfirmTests.py +++ b/test/ConfirmTests.py @@ -13,6 +13,8 @@ harness = LedgerHarness(sys.argv) tests = sys.argv[3] if not os.path.isdir(tests) and not os.path.isfile(tests): + sys.stderr.write("'%s' is not a directory or file (cwd %s)" % + (tests, os.getcwd())) sys.exit(1) commands = [ diff --git a/test/RegressTests.py b/test/RegressTests.py index 72667311..a7d51ada 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -31,6 +31,8 @@ harness = LedgerHarness(args) tests = args[3] if not os.path.isdir(tests) and not os.path.isfile(tests): + sys.stderr.write("'%s' is not a directory or file (cwd %s)" % + (tests, os.getcwd())) sys.exit(1) class RegressFile(object): -- cgit v1.2.3 From ee641f353c9a2216533800464d26afe86f1b028e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 15 Apr 2012 01:17:01 -0500 Subject: Resolve some issues with proof builds --- acprep | 5 ++++- src/draft.cc | 14 +++++++------- src/draft.h | 9 +++++++++ src/xact.cc | 3 ++- test/LedgerHarness.py | 4 ++-- test/RegressTests.py | 3 ++- 6 files changed, 26 insertions(+), 12 deletions(-) (limited to 'test/RegressTests.py') diff --git a/acprep b/acprep index 0d7f3cd0..4ebd6914 100755 --- a/acprep +++ b/acprep @@ -1643,7 +1643,10 @@ class PrepareBuild(CommandLineApp): isdir(self.build_directory()): self.log.info('=== Wiping build directory %s ===' % self.build_directory()) - shutil.rmtree(self.build_directory()) + try: + shutil.rmtree(self.build_directory()) + except: + self.execute('rm', '-fr', self.build_directory()) def phase_distcheck(self, *args): self.log.info('Executing phase: distcheck') diff --git a/src/draft.cc b/src/draft.cc index 7edf7edc..43c214cb 100644 --- a/src/draft.cc +++ b/src/draft.cc @@ -507,7 +507,6 @@ value_t template_command(call_scope_t& args) out << std::endl << std::endl; draft_t draft(args.value()); - out << _("--- Transaction template ---") << std::endl; draft.dump(out); @@ -517,15 +516,16 @@ value_t template_command(call_scope_t& args) value_t xact_command(call_scope_t& args) { report_t& report(find_scope(args)); - draft_t draft(args.value()); + draft_t draft(args.value()); - xact_t * new_xact = draft.insert(*report.session.journal.get()); + unique_ptr new_xact(draft.insert(*report.session.journal.get())); + if (new_xact.get()) { + // Only consider actual postings for the "xact" command + report.HANDLER(limit_).on("#xact", "actual"); - // Only consider actual postings for the "xact" command - report.HANDLER(limit_).on("#xact", "actual"); + report.xact_report(post_handler_ptr(new print_xacts(report)), *new_xact.get()); + } - if (new_xact) - report.xact_report(post_handler_ptr(new print_xacts(report)), *new_xact); return true; } diff --git a/src/draft.h b/src/draft.h index 46aa26e1..9023e6da 100644 --- a/src/draft.h +++ b/src/draft.h @@ -81,6 +81,15 @@ class draft_t : public expr_base_t xact_template_t() { TRACE_CTOR(xact_template_t, ""); } + xact_template_t(const xact_template_t& other) + : date(other.date), + code(other.code), + note(other.note), + payee_mask(other.payee_mask), + posts(other.posts) + { + TRACE_CTOR(xact_template_t, "copy"); + } ~xact_template_t() throw() { TRACE_DTOR(xact_template_t); } diff --git a/src/xact.cc b/src/xact.cc index 3f4b753c..226fd5ab 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -56,7 +56,8 @@ xact_base_t::~xact_base_t() // temporary is. assert(! post->has_flags(ITEM_TEMP)); - post->account->remove_post(post); + if (post->account) + post->account->remove_post(post); checked_delete(post); } } diff --git a/test/LedgerHarness.py b/test/LedgerHarness.py index 3477e720..3e797e85 100755 --- a/test/LedgerHarness.py +++ b/test/LedgerHarness.py @@ -44,8 +44,8 @@ class LedgerHarness: print "Cannot find source path at '%s'" % argv[2] sys.exit(1) - self.ledger = argv[1] - self.sourcepath = argv[2] + self.ledger = os.path.abspath(argv[1]) + self.sourcepath = os.path.abspath(argv[2]) self.succeeded = 0 self.failed = 0 self.verify = '--verify' in argv diff --git a/test/RegressTests.py b/test/RegressTests.py index a7d51ada..792c2d3e 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -184,7 +184,8 @@ if __name__ == '__main__': tests = [os.path.join(tests, x) for x in os.listdir(tests) if (x.endswith('.test') and - (not '_py.test' in x or harness.python))] + (not '_py.test' in x or (harness.python and + not harness.verify)))] if pool: pool.map(do_test, tests, 1) else: -- cgit v1.2.3 From a910549ca9f7d07d7610eb27d8b0709dc42802a6 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 25 Apr 2012 03:08:45 -0500 Subject: Fixes so that tests can run under distcheck --- test/LedgerHarness.py | 5 ++--- test/RegressTests.py | 7 ++++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'test/RegressTests.py') diff --git a/test/LedgerHarness.py b/test/LedgerHarness.py index 3e797e85..b8900971 100755 --- a/test/LedgerHarness.py +++ b/test/LedgerHarness.py @@ -52,8 +52,6 @@ class LedgerHarness: self.gmalloc = '--gmalloc' in argv self.python = '--python' in argv - os.chdir(self.sourcepath) - def run(self, command, verify=None, gmalloc=None, columns=True): env = os.environ.copy() @@ -89,7 +87,8 @@ class LedgerHarness: command = valgrind + ' -q ' + command return Popen(command, shell=True, close_fds=True, env=env, - stdin=PIPE, stdout=PIPE, stderr=PIPE) + stdin=PIPE, stdout=PIPE, stderr=PIPE, + cwd=self.sourcepath) def read(self, fd): text = "" diff --git a/test/RegressTests.py b/test/RegressTests.py index 792c2d3e..7d67eb21 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -42,7 +42,7 @@ class RegressFile(object): def transform_line(self, line): line = re.sub('\$sourcepath', harness.sourcepath, line) - line = re.sub('\$FILE', self.filename, line) + line = re.sub('\$FILE', os.path.abspath(self.filename), line) return line def read_test(self): @@ -93,7 +93,7 @@ class RegressFile(object): def notify_user(self, msg, test): print msg print "--" - print test['command'], + print self.transform_line(test['command']), print "--" def run_test(self, test): @@ -101,7 +101,8 @@ class RegressFile(object): if test['command'].find("-f - ") != -1: use_stdin = True else: - test['command'] = (('$ledger -f "%s" ' % self.filename) + + test['command'] = (('$ledger -f "%s" ' % + os.path.abspath(self.filename)) + test['command']) p = harness.run(test['command'], -- cgit v1.2.3