result.scm
| 1 | ;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu> |
| 2 | ;;;; |
| 3 | ;;;; This library is free software; you can redistribute it and/or |
| 4 | ;;;; modify it under the terms of the GNU Lesser General Public |
| 5 | ;;;; License as published by the Free Software Foundation; either |
| 6 | ;;;; version 3 of the License, or (at your option) any later version. |
| 7 | ;;;; |
| 8 | ;;;; This library is distributed in the hope that it will be useful, |
| 9 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | ;;;; Lesser General Public License for more details. |
| 12 | ;;;; |
| 13 | ;;;; You should have received a copy of the GNU Lesser General Public |
| 14 | ;;;; License along with this library; if not, write to the Free Software |
| 15 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 | ;;;; |
| 17 | |
| 18 | (define-module (test-modules result) |
| 19 | #:use-module ((config) #:prefix config:) |
| 20 | #:use-module (srfi srfi-9) |
| 21 | #:use-module (srfi srfi-19) |
| 22 | #:use-module (ice-9 match) |
| 23 | #:export (make-test-case |
| 24 | test-case? |
| 25 | test-case-id |
| 26 | test-case-num |
| 27 | test-case-name |
| 28 | test-case-document |
| 29 | test-case-result |
| 30 | test-case-reason |
| 31 | update-test-case |
| 32 | |
| 33 | make-test-driver |
| 34 | test-driver? |
| 35 | test-driver-init |
| 36 | test-driver-print |
| 37 | test-driver-finalize |
| 38 | |
| 39 | tap-driver |
| 40 | earl-driver)) |
| 41 | |
| 42 | ;; A test case is the result of running a test. It has an identifier, a name |
| 43 | ;; and a description. Its result is a symbol, which can be 'skiped, 'pass, |
| 44 | ;; 'fail, 'xpass, or 'xfail. The reason is a string or #f that explains the |
| 45 | ;; result |
| 46 | (define-record-type test-case |
| 47 | (make-test-case id num name description document result reason) |
| 48 | test-case? |
| 49 | (id test-case-id) |
| 50 | (num test-case-num) |
| 51 | (name test-case-name) |
| 52 | (description test-case-description) |
| 53 | (document test-case-document) |
| 54 | (result test-case-result) |
| 55 | (reason test-case-reason)) |
| 56 | |
| 57 | (define* (update-test-case test-case #:key |
| 58 | (id (test-case-id test-case)) |
| 59 | (num (test-case-num test-case)) |
| 60 | (name (test-case-name test-case)) |
| 61 | (description (test-case-description test-case)) |
| 62 | (document (test-case-document test-case)) |
| 63 | (result (test-case-result test-case)) |
| 64 | (reason (test-case-reason test-case))) |
| 65 | (make-test-case id num name description document result reason)) |
| 66 | |
| 67 | ;; A test driver is called at the beginning, on each test result and at the |
| 68 | ;; end of the tests. |
| 69 | (define-record-type test-driver |
| 70 | (make-test-driver init print finalize) |
| 71 | test-driver? |
| 72 | (init test-driver-init) ; list test-case -> () |
| 73 | (print test-driver-print) ; test-case -> () |
| 74 | (finalize test-driver-finalize)) ; list test-case -> () |
| 75 | |
| 76 | (define tap-driver |
| 77 | (make-test-driver |
| 78 | (lambda (cases) |
| 79 | (format #t "1..~a~%" (length cases))) |
| 80 | (match-lambda |
| 81 | (($ test-case id num name description document result reason) |
| 82 | (match result |
| 83 | ('skip |
| 84 | (format #t "ok ~a ~a # SKIP ~a~%" num name reason)) |
| 85 | ('pass |
| 86 | (format #t "ok ~a ~a~%" num name)) |
| 87 | ('fail |
| 88 | (format #t "not ok ~a ~a: ~a~%" num name reason)) |
| 89 | ('xfail |
| 90 | (format #t "not ok ~a ~a # TODO ~a~%" num name reason)) |
| 91 | ('xpass |
| 92 | (format #t "ok ~a ~a # TODO ~a~%" num name reason))) |
| 93 | (force-output))) |
| 94 | (const #t))) |
| 95 | |
| 96 | (define (get-date) |
| 97 | (let* ((date (date->string (current-date) "~4")) |
| 98 | (len (string-length date))) |
| 99 | (string-append |
| 100 | (substring date 0 (- len 2)) |
| 101 | ":" |
| 102 | (substring date (- len 2))))) |
| 103 | |
| 104 | (define (earl-driver port) |
| 105 | "A driver that creates a turtle file report using the earl vocabulary. It |
| 106 | doesn't use any internal representation for RDF or Turtle, it only manipulates |
| 107 | strings." |
| 108 | (make-test-driver |
| 109 | (lambda (cases) |
| 110 | (format port "@prefix dc: <http://purl.org/dc/terms/> .~%") |
| 111 | (format port "@prefix earl: <http://www.w3.org/ns/earl#> .~%") |
| 112 | (format port "@prefix doap: <http://usefulinc.com/ns/doap#> .~%") |
| 113 | (format port "@prefix foaf: <http://xmlns.com/foaf/0.1/> .~%") |
| 114 | (format port "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .~%") |
| 115 | (format port "~%") |
| 116 | (format port "<https://framagit.org/tyreunom/guile-jsonld> a doap:Project;~%") |
| 117 | (format port " dc:creator <https://lepiller.eu/#me>;~%") |
| 118 | (format port " doap:bug-database <https://framait.org/tyreunom/guile-jsonld/issues>;~%") |
| 119 | (format port " doap:description \"Guile implementation of the JsonLD API defined by the W3C.\"@en;~%") |
| 120 | (format port " doap:developer <https://lepiller.eu/#me>;~%") |
| 121 | (format port " doap:homepage <https://framagit.org/tyreunom/guile-jsonld/>;~%") |
| 122 | (format port " doap:implements <https://www.w3.org/TR/json-ld11/>,~%") |
| 123 | (format port " <https://www.w3.org/TR/json-ld11-api/>;~%") |
| 124 | (format port " doap:license <https://www.gnu.org/licenses/gpl-3.0.html>;~%") |
| 125 | (format port " doap:name \"guile-jsonld\"^^xsd:string;~%") |
| 126 | (format port " doap:programming-language \"GNU Guile\"^^xsd:string;~%") |
| 127 | (format port " doap:shortdesc \"JSON-LD support for GNU Guile.\"@en;~%") |
| 128 | (format port " doap:release [~%") |
| 129 | (format port " doap:name \"guile-jsonld-~a\";~%" config:version) |
| 130 | (format port " doap:revision \"~a\";~%" config:version) |
| 131 | (format port " doap:created \"2020-03-29\"^^xsd:date;~%") |
| 132 | (format port " ] .~%") |
| 133 | (format port "~%") |
| 134 | (format port "<https://lepiller.eu/#me> a earl:Assertor, foaf:Person;~%") |
| 135 | (format port " foaf:homepage <https://lepiller.eu>;~%") |
| 136 | (format port " foaf:mbox <mailto:julien@lepiller.eu>;~%") |
| 137 | (format port " foaf:name \"Julien Lepiller\"^^xsd:string .~%") |
| 138 | (format port "~%") |
| 139 | (format port "<> foaf:primaryTopic <https://framagit.org/tyreunom/guile-jsonld>;~%") |
| 140 | (format port " dc:issued \"~a\"^^xsd:dateTime;~%" (get-date)) |
| 141 | (format port " foaf:maker <https://lepiller.eu/#me> .~%") |
| 142 | (format port "~%") |
| 143 | (format #t "~a test cases for report~%" (length cases))) |
| 144 | (lambda (test-case) |
| 145 | (format port "[ a earl:Assertion;~%") |
| 146 | (format port " earl:assertedBy <https://lepiller.eu/#me>;~%") |
| 147 | (format port " earl:subject <https://framagit.org/tyreunom/guile-jsonld>;~%") |
| 148 | (format port " earl:test <~a>;~%" (test-case-id test-case)) |
| 149 | (format port " earl:result [~%") |
| 150 | (format port " a earl:TestResult;~%") |
| 151 | (format port " earl:outcome earl:~a;~%" |
| 152 | (match (test-case-result test-case) |
| 153 | ('skip "inapplicable") |
| 154 | ('pass "passed") |
| 155 | ('fail "failed") |
| 156 | ('xpass "cantTell") |
| 157 | ('xfail "untested"))) |
| 158 | (format port " dc:date \"~a\"^^xsd:dateTime ] ;~%" (get-date)) |
| 159 | (format port " earl:mode earl:automatic ] .~%") |
| 160 | (format port "~%") |
| 161 | (format #t "Tested ~a: ~a~%" |
| 162 | (test-case-num test-case) (test-case-result test-case))) |
| 163 | (lambda _ |
| 164 | (close-port port)))) |
| 165 |