gnucash maint: [report-core] disallow define-report with incomplete export info
Christopher Lam
clam at code.gnucash.org
Tue May 4 21:08:00 EDT 2021
Updated via https://github.com/Gnucash/gnucash/commit/85a4baeb (commit)
from https://github.com/Gnucash/gnucash/commit/45cb454b (commit)
commit 85a4baeb21a1b7e1d9158d3a202d69c3c4844c12
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed May 5 08:52:08 2021 +0800
[report-core] disallow define-report with incomplete export info
if exporting is allowed, 'export-types and 'export-thunk must both be
defined.
diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm
index 853afce41..da12f1056 100644
--- a/gnucash/report/report-core.scm
+++ b/gnucash/report/report-core.scm
@@ -237,6 +237,7 @@ not found.")))
(define report-rec (make-report-template))
(define allowable-fields (record-type-fields <report-template>))
(define (not-a-field? fld) (not (memq fld allowable-fields)))
+ (define (xor . args) (fold (lambda (a b) (if a (if b #f a) b)) #f args))
(let loop ((args args))
(match args
@@ -252,6 +253,11 @@ not found.")))
((hash-ref *gnc:_report-templates_* report-guid)
(gui-error (string-append rpterr-dupe report-guid)))
+ ;; has export-type but no export-thunk. or vice versa.
+ ((xor (gnc:report-template-export-thunk report-rec)
+ (gnc:report-template-export-types report-rec))
+ (gui-error (format #f "Export needs both thunk and types: ~a" report-guid)))
+
;; good: new report definition, store into report-templates hash
(else
(hash-set! *gnc:_report-templates_* report-guid report-rec)))))
@@ -836,10 +842,8 @@ not found.")))
(cond
((not export-thunk)
(stderr-log "Only the following reports have export code:\n")
- (show-selected-reports (cut gnc:report-template-export-thunk <>)
- (current-error-port))
+ (show-selected-reports gnc:report-template-export-thunk (current-error-port))
(stderr-log "Use -R show to describe report\n"))
- ((not export-types) (stderr-log "Report ~s has no export-types\n" report))
((not (assoc export-type export-types))
(stderr-log "Export-type disallowed: ~a. Allowed types: ~a\n"
export-type (string-join (map car export-types) ", ")))
diff --git a/gnucash/report/test/test-report.scm b/gnucash/report/test/test-report.scm
index 26074c3bf..012e10aca 100644
--- a/gnucash/report/test/test-report.scm
+++ b/gnucash/report/test/test-report.scm
@@ -11,6 +11,7 @@
;; will create Testing/Temporary/test-asset-performance.log
(test-check1)
(test-check-invalid-field)
+ (test-check-incomplete-export)
(test-check2)
(test-check3)
(test-check4)
@@ -31,6 +32,21 @@
1
(length (gnc:all-report-template-guids))))
+(define (test-check-incomplete-export)
+ ;; it's not legit to define report with ONLY export-thunk or
+ ;; export-types. both must be defined.
+ (gnc:define-report 'version 3
+ 'name "Test Report Template4"
+ 'export-thunk #t
+ 'report-guid "incomplete-export-guid")
+ (gnc:define-report 'version 3
+ 'name "Test Report Template4"
+ 'export-types #t
+ 'report-guid "incomplete-export-guid")
+ (test-equal "report with incomplete export thunk"
+ 1
+ (length (gnc:all-report-template-guids))))
+
(define (test-check-invalid-field)
(gnc:define-report 'version 3
'name "Test Report Template4"
Summary of changes:
gnucash/report/report-core.scm | 10 +++++++---
gnucash/report/test/test-report.scm | 16 ++++++++++++++++
2 files changed, 23 insertions(+), 3 deletions(-)
More information about the gnucash-changes
mailing list