Skip to content

Commit

Permalink
[report-core] disallow define-report with incomplete export info
Browse files Browse the repository at this point in the history
if exporting is allowed, 'export-types and 'export-thunk must both be
defined.
  • Loading branch information
christopherlam committed May 5, 2021
1 parent 45cb454 commit 85a4bae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions gnucash/report/report-core.scm
Expand Up @@ -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
Expand All @@ -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)))))
Expand Down Expand Up @@ -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) ", ")))
Expand Down
16 changes: 16 additions & 0 deletions gnucash/report/test/test-report.scm
Expand Up @@ -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)
Expand All @@ -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"
Expand Down

0 comments on commit 85a4bae

Please sign in to comment.