gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Fri Feb 22 10:36:27 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/102a357c (commit)
	 via  https://github.com/Gnucash/gnucash/commit/09e0e02a (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f92b9459 (commit)
	from  https://github.com/Gnucash/gnucash/commit/609bd48a (commit)



commit 102a357cfebb88983ecb9dd63c6116a31562a9b4
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Feb 22 15:03:08 2019 +0800

    [test-register] basic test for register.scm

diff --git a/gnucash/report/standard-reports/test/CMakeLists.txt b/gnucash/report/standard-reports/test/CMakeLists.txt
index 82ad4676c..0d00ec15f 100644
--- a/gnucash/report/standard-reports/test/CMakeLists.txt
+++ b/gnucash/report/standard-reports/test/CMakeLists.txt
@@ -11,6 +11,7 @@ set(scm_test_with_srfi64_SOURCES
   test-transaction.scm
   test-balsheet-pnl.scm
   test-income-gst.scm
+  test-register.scm
 )
 
 set(scm_test_with_textual_ports_SOURCES
diff --git a/gnucash/report/standard-reports/test/test-register.scm b/gnucash/report/standard-reports/test/test-register.scm
new file mode 100644
index 000000000..05ed5db82
--- /dev/null
+++ b/gnucash/report/standard-reports/test/test-register.scm
@@ -0,0 +1,135 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2 of
+;; the License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, contact:
+;;
+;; Free Software Foundation           Voice:  +1-617-542-5942
+;; 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+;; Boston, MA  02110-1301,  USA       gnu at gnu.org
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(use-modules (srfi srfi-1))
+(use-modules (srfi srfi-14))
+(use-modules (srfi srfi-64))
+(use-modules (gnucash gnc-module))
+(use-modules (gnucash engine test srfi64-extras))
+
+;; Guile 2 needs to load external modules at compile time
+;; otherwise the N_ syntax-rule won't be found at compile time
+;; causing the test to fail
+;; That's what the wrapper below is meant for:
+
+(gnc:module-begin-syntax (gnc:module-load "gnucash/report/report-system" 0))
+
+(use-modules (gnucash utilities))
+(use-modules (gnucash report report-system))
+(use-modules (gnucash app-utils))
+(use-modules (gnucash engine))
+(use-modules (sw_engine))
+(use-modules (gnucash report standard-reports register))
+(use-modules (gnucash report report-system test test-extras))
+(use-modules (gnucash report stylesheets))
+(use-modules (gnucash engine test test-extras))
+
+;; Explicitly set locale to make the report output predictable
+(setlocale LC_ALL "C")
+(define uuid "22104e02654c4adba844ee75a3f8d173")
+
+(define (run-test)
+  (test-runner-factory gnc:test-runner)
+  (test-begin "register")
+  (test-register)
+  (test-end "register"))
+
+(define (set-option options page tag value)
+  ((gnc:option-setter (gnc:lookup-option options page tag)) value))
+
+(define (teardown)
+  (gnc-clear-current-session))
+
+(define (options->sxml options test-title)
+  (gnc:options->sxml uuid options "test-register" test-title))
+
+(define (test-register)
+  (let* ((options (gnc:make-report-options uuid))
+         (account-alist (create-test-data))
+         (bank (cdr (assoc "Bank" account-alist))))
+
+    (let ((query (qof-query-create-for-splits)))
+      (qof-query-set-book query (gnc-get-current-book))
+      (xaccQueryAddAccountMatch query (list bank)
+                                QOF-GUID-MATCH-ANY QOF-QUERY-AND)
+      (set-option options "__reg" "query" (gnc-query2scm query)))
+
+    (let ((sxml (options->sxml options "basic")))
+      (test-equal "table has 231 cells"
+        231
+        (length (sxml->table-row-col sxml 1 #f #f)))
+
+      (test-equal "total debit = 2587"
+        '("Total Debits" "$2,587.00")
+        (sxml->table-row-col sxml 1 -3 #f))
+
+      (test-equal "total credits = 401"
+        '("Total Credits" "$401.00")
+        (sxml->table-row-col sxml 1 -1 #f)))
+
+    (set-option options "__reg" "journal" #t)
+    (let ((sxml (options->sxml options "journal")))
+      (test-equal "table has 333 cells"
+        333
+        (length (sxml->table-row-col sxml 1 #f #f)))
+
+      (test-equal "total debit = 2587"
+        '("Total Debits" "$2,587.00")
+        (sxml->table-row-col sxml 1 -3 #f))
+
+      (test-equal "total credits = 401"
+        '("Total Credits" "$401.00")
+        (sxml->table-row-col sxml 1 -1 #f)))
+
+    (set-option options "__reg" "ledger-type" #t)
+    (let ((sxml (options->sxml options "ledger-type")))
+      (test-equal "table has 335 cells"
+        335
+        (length (sxml->table-row-col sxml 1 #f #f)))
+
+      (test-equal "total debit = 2587"
+        '("Total Debits" "$2,587.00")
+        (sxml->table-row-col sxml 1 -5 #f))
+
+      (test-equal "total credits = 401"
+        '("Total Credits" "$401.00")
+        (sxml->table-row-col sxml 1 -3 #f))
+
+      (test-equal "net change = 401"
+        '("Net Change" "$2,186.00")
+        (sxml->table-row-col sxml 1 -1 #f)))
+
+    (set-option options "__reg" "double" #t)
+    (let ((sxml (options->sxml options "double")))
+      (test-equal "table has 339 cells"
+        339
+        (length (sxml->table-row-col sxml 1 #f #f)))
+
+      (test-equal "total debit = 2587"
+        '("Total Debits" "$2,587.00")
+        (sxml->table-row-col sxml 1 -5 #f))
+
+      (test-equal "total credits = 401"
+        '("Total Credits" "$401.00")
+        (sxml->table-row-col sxml 1 -3 #f))
+
+      (test-equal "net change = 401"
+        '("Net Change" "$2,186.00")
+        (sxml->table-row-col sxml 1 -1 #f)))
+    ))

commit 09e0e02a75c29280a505d175b3c1e2ee92f4baa3
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Feb 22 14:31:27 2019 +0800

    [test-extras] abstract test-data skeleton

diff --git a/libgnucash/engine/test/test-extras.scm b/libgnucash/engine/test/test-extras.scm
index 2e06707db..6d53edd77 100644
--- a/libgnucash/engine/test/test-extras.scm
+++ b/libgnucash/engine/test/test-extras.scm
@@ -364,13 +364,111 @@
 	       (list "Petrol")))))
 
 (define (env-create-test-accounts env)
-  (env-create-account-structure-alist env
-				      (list "Root"
-					    (list (cons 'type ACCT-TYPE-ASSET))
-					    (list "Bank")
-					    (list "Wallet")
-					    (list "Other")
-					    (list "Expenses"
-						  (list (cons 'type ACCT-TYPE-EXPENSE))))))
-
-
+  (env-create-account-structure-alist
+   env
+   (list "Root"
+	 (list (cons 'type ACCT-TYPE-ASSET))
+	 (list "Bank")
+	 (list "Wallet")
+	 (list "Other")
+	 (list "Expenses"
+	       (list (cons 'type ACCT-TYPE-EXPENSE))))))
+
+(define (mnemonic->commodity sym)
+    (gnc-commodity-table-lookup
+     (gnc-commodity-table-get-table (gnc-get-current-book))
+     (gnc-commodity-get-namespace (gnc-default-report-currency))
+     sym))
+
+(define-public (create-test-data)
+  (let* ((env (create-test-env))
+         (GBP (mnemonic->commodity "GBP"))
+         (structure
+          (list "Root" (list
+                        (cons 'type ACCT-TYPE-ASSET))
+                (list "Asset"
+                      (list "Bank")
+                      (list "GBP Bank" (list
+                                        (cons 'commodity GBP)))
+                      (list "Wallet"))
+                (list "Income" (list
+                                (cons 'type ACCT-TYPE-INCOME)))
+                (list "Income-GBP" (list
+                                    (cons 'type ACCT-TYPE-INCOME)
+                                    (cons 'commodity GBP)))
+                (list "Expenses" (list
+                                  (cons 'type ACCT-TYPE-EXPENSE)))
+                (list "Liabilities" (list (cons 'type ACCT-TYPE-LIABILITY)))
+                (list "Equity" (list
+                                (cons 'type ACCT-TYPE-EQUITY)))))
+         (account-alist (env-create-account-structure-alist env structure))
+         (bank (cdr (assoc "Bank" account-alist)))
+         (gbp-bank (cdr (assoc "GBP Bank" account-alist)))
+         (wallet (cdr (assoc "Wallet" account-alist)))
+         (income (cdr (assoc "Income" account-alist)))
+         (gbp-income (cdr (assoc "Income-GBP" account-alist)))
+         (expense (cdr (assoc "Expenses" account-alist)))
+         (liability (cdr (assoc "Liabilities" account-alist)))
+         (equity (cdr (assoc "Equity" account-alist))))
+
+    ;; populate datafile with old transactions
+    (env-transfer env 01 01 1970 bank expense       5
+                  #:description "desc-1" #:num "trn1"
+                  #:memo "memo-3")
+
+    (env-transfer env 31 12 1969 income bank       10
+                  #:description "desc-2" #:num "trn2"
+                  #:void-reason "void" #:notes "notes3")
+
+    (env-transfer env 31 12 1969 income bank       29
+                  #:description "desc-3" #:num "trn3"
+                  #:reconcile (cons #\c (gnc-dmy2time64 01 03 1970)))
+
+    (env-transfer env 01 02 1970 bank expense      15
+                  #:description "desc-4" #:num "trn4"
+                  #:notes "notes2" #:memo "memo-1")
+
+    (env-transfer env 10 01 1970 liability expense 10
+                  #:description "desc-5" #:num "trn5"
+                  #:void-reason "any")
+
+    (env-transfer env 10 01 1970 liability expense 11
+                  #:description "desc-6" #:num "trn6"
+                  #:notes "notes1")
+
+    (env-transfer env 10 02 1970 bank liability     8
+                  #:description "desc-7" #:num "trn7"
+                  #:notes "notes1" #:memo "memo-2"
+                  #:reconcile (cons #\y (gnc-dmy2time64 01 03 1970)))
+
+    (env-create-multisplit-transaction
+     env 14 02 1971
+     (list (vector bank  -100 -100)
+           (vector expense 80   80)
+           (vector wallet  20   20))
+     #:description "$100bank -> $80expenses + $20wallet"
+     #:notes "multisplit")
+
+    (let ((closing-txn (env-transfer
+                        env 31 12 1977 expense equity
+                        111 #:description "Closing")))
+      (xaccTransSetIsClosingTxn closing-txn #t))
+
+    (env-transfer-foreign env 15 01 2000 gbp-bank bank
+                          10 14 #:description "GBP 10 to USD 14")
+
+    (env-transfer-foreign env 15 02 2000 bank gbp-bank
+                          9  6 #:description "USD 9 to GBP 6")
+
+    (for-each
+     (lambda (m)
+       (env-transfer env 08 (1+ m) 1978
+                     gbp-income gbp-bank 51 #:description "#51 income")
+       (env-transfer env 03 (1+ m) 1978
+                     income bank  103 #:description "$103 income")
+       (env-transfer env 15 (1+ m) 1978
+                     bank expense  22 #:description "$22 expense")
+       (env-transfer env 09 (1+ m) 1978
+                     income bank  109 #:description "$109 income"))
+     (iota 12))
+    account-alist))

commit f92b9459baaf1260c257ea63b5111004fd31f133
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Feb 22 13:50:46 2019 +0800

    [tests] encapsulate tests with (test-begin/end)
    
    this ensures that any test failures will return #f as appropriate.

diff --git a/gnucash/report/standard-reports/test/test-standard-category-report.scm b/gnucash/report/standard-reports/test/test-standard-category-report.scm
index 6ed306f3d..77ef08ce6 100644
--- a/gnucash/report/standard-reports/test/test-standard-category-report.scm
+++ b/gnucash/report/standard-reports/test/test-standard-category-report.scm
@@ -47,8 +47,10 @@
 
 (define (run-test)
   (test-runner-factory gnc:test-runner)
+  (test-begin "standard-category-report")
   (run-category-income-expense-test category-barchart-income-uuid category-barchart-expense-uuid)
-  (run-category-asset-liability-test category-barchart-asset-uuid category-barchart-liability-uuid))
+  (run-category-asset-liability-test category-barchart-asset-uuid category-barchart-liability-uuid)
+  (test-end "standard-category-report"))
 
 (export run-category-income-expense-test)
 (export run-category-asset-liability-test)
diff --git a/gnucash/report/standard-reports/test/test-standard-net-barchart.scm b/gnucash/report/standard-reports/test/test-standard-net-barchart.scm
index e1892932d..8a6f43637 100644
--- a/gnucash/report/standard-reports/test/test-standard-net-barchart.scm
+++ b/gnucash/report/standard-reports/test/test-standard-net-barchart.scm
@@ -34,7 +34,9 @@
 
 (define (run-test)
   (test-runner-factory gnc:test-runner)
-  (run-net-asset-income-test net-worth-barchart-uuid income-expense-barchart-uuid))
+  (test-begin "standard-net-barchart")
+  (run-net-asset-income-test net-worth-barchart-uuid income-expense-barchart-uuid)
+  (test-end "standard-net-barchart"))
 
 (define (set-option options page tag value)
   ((gnc:option-setter (gnc:lookup-option options page tag)) value))
diff --git a/gnucash/report/standard-reports/test/test-standard-net-linechart.scm b/gnucash/report/standard-reports/test/test-standard-net-linechart.scm
index 4d56e2fe4..d52b04ec7 100644
--- a/gnucash/report/standard-reports/test/test-standard-net-linechart.scm
+++ b/gnucash/report/standard-reports/test/test-standard-net-linechart.scm
@@ -34,7 +34,9 @@
 
 (define (run-test)
   (test-runner-factory gnc:test-runner)
-  (run-net-asset-test net-worth-linechart-uuid))
+  (test-begin "standard-net-linechart")
+  (run-net-asset-test net-worth-linechart-uuid)
+  (test-end "standard-net-linechart"))
 
 (define (set-option options page tag value)
   ((gnc:option-setter (gnc:lookup-option options page tag)) value))



Summary of changes:
 .../report/standard-reports/test/CMakeLists.txt    |   1 +
 .../report/standard-reports/test/test-register.scm | 135 +++++++++++++++++++++
 .../test/test-standard-category-report.scm         |   4 +-
 .../test/test-standard-net-barchart.scm            |   4 +-
 .../test/test-standard-net-linechart.scm           |   4 +-
 libgnucash/engine/test/test-extras.scm             | 118 ++++++++++++++++--
 6 files changed, 253 insertions(+), 13 deletions(-)
 create mode 100644 gnucash/report/standard-reports/test/test-register.scm



More information about the gnucash-changes mailing list