diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2016-06-20 22:34:13 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2016-06-20 23:50:46 +0200 |
| commit | 98b65b5ff6b1dea0ad58b0f47dd163c32d0cbf6e (patch) | |
| tree | 7aa29f770d1ff50aea95af404324061ec708cd03 /gnu/tests.scm | |
| parent | 2a6ba870867e31a32faca0dbf0e062bf9f5c0d78 (diff) | |
tests: Add a mechanism to describe and discover system tests.
* gnu/tests.scm (<system-test>): New record type.
(write-system-test, test-modules, fold-system-tests)
(all-system-tests): New procedures.
* gnu/tests/base.scm (%test-basic-os): Turn into a <system-test>.
* gnu/tests/install.scm (%test-installed-os): Likewise.
* build-aux/run-system-tests.scm (%system-tests): Remove.
(run-system-tests): Use 'all-system-tests'.
Diffstat (limited to 'gnu/tests.scm')
| -rw-r--r-- | gnu/tests.scm | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/gnu/tests.scm b/gnu/tests.scm index 348b5ad40fa..ea779ed6f07 100644 --- a/gnu/tests.scm +++ b/gnu/tests.scm | |||
| @@ -18,12 +18,28 @@ | |||
| 18 | 18 | ||
| 19 | (define-module (gnu tests) | 19 | (define-module (gnu tests) |
| 20 | #:use-module (guix gexp) | 20 | #:use-module (guix gexp) |
| 21 | #:use-module (guix utils) | ||
| 22 | #:use-module (guix records) | ||
| 21 | #:use-module (gnu system) | 23 | #:use-module (gnu system) |
| 22 | #:use-module (gnu services) | 24 | #:use-module (gnu services) |
| 23 | #:use-module (gnu services shepherd) | 25 | #:use-module (gnu services shepherd) |
| 26 | #:use-module ((gnu packages) #:select (scheme-modules)) | ||
| 27 | #:use-module (srfi srfi-1) | ||
| 28 | #:use-module (srfi srfi-9 gnu) | ||
| 29 | #:use-module (ice-9 match) | ||
| 24 | #:export (marionette-service-type | 30 | #:export (marionette-service-type |
| 25 | marionette-operating-system | 31 | marionette-operating-system |
| 26 | define-os-with-source)) | 32 | define-os-with-source |
| 33 | |||
| 34 | system-test | ||
| 35 | system-test? | ||
| 36 | system-test-name | ||
| 37 | system-test-value | ||
| 38 | system-test-description | ||
| 39 | system-test-location | ||
| 40 | |||
| 41 | fold-system-tests | ||
| 42 | all-system-tests)) | ||
| 27 | 43 | ||
| 28 | ;;; Commentary: | 44 | ;;; Commentary: |
| 29 | ;;; | 45 | ;;; |
| @@ -147,4 +163,54 @@ the system under test." | |||
| 147 | (use-modules modules ...) | 163 | (use-modules modules ...) |
| 148 | (operating-system fields ...))))))) | 164 | (operating-system fields ...))))))) |
| 149 | 165 | ||
| 166 | |||
| 167 | ;;; | ||
| 168 | ;;; Tests. | ||
| 169 | ;;; | ||
| 170 | |||
| 171 | (define-record-type* <system-test> system-test make-system-test | ||
| 172 | system-test? | ||
| 173 | (name system-test-name) ;string | ||
| 174 | (value system-test-value) ;%STORE-MONAD value | ||
| 175 | (description system-test-description) ;string | ||
| 176 | (location system-test-location (innate) ;<location> | ||
| 177 | (default (and=> (current-source-location) | ||
| 178 | source-properties->location)))) | ||
| 179 | |||
| 180 | (define (write-system-test test port) | ||
| 181 | (match test | ||
| 182 | (($ <system-test> name _ _ ($ <location> file line)) | ||
| 183 | (format port "#<system-test ~a ~a:~a ~a>" | ||
| 184 | name file line | ||
| 185 | (number->string (object-address test) 16))) | ||
| 186 | (($ <system-test> name) | ||
| 187 | (format port "#<system-test ~a ~a>" name | ||
| 188 | (number->string (object-address test) 16))))) | ||
| 189 | |||
| 190 | (set-record-type-printer! <system-test> write-system-test) | ||
| 191 | |||
| 192 | (define (test-modules) | ||
| 193 | "Return the list of modules that define system tests." | ||
| 194 | (scheme-modules (dirname (search-path %load-path "guix.scm")) | ||
| 195 | "gnu/tests")) | ||
| 196 | |||
| 197 | (define (fold-system-tests proc seed) | ||
| 198 | "Invoke PROC on each system test, passing it the test and the previous | ||
| 199 | result." | ||
| 200 | (fold (lambda (module result) | ||
| 201 | (fold (lambda (thing result) | ||
| 202 | (if (system-test? thing) | ||
| 203 | (proc thing result) | ||
| 204 | result)) | ||
| 205 | result | ||
| 206 | (module-map (lambda (sym var) | ||
| 207 | (false-if-exception (variable-ref var))) | ||
| 208 | module))) | ||
| 209 | '() | ||
| 210 | (test-modules))) | ||
| 211 | |||
| 212 | (define (all-system-tests) | ||
| 213 | "Return the list of system tests." | ||
| 214 | (reverse (fold-system-tests cons '()))) | ||
| 215 | |||
| 150 | ;;; tests.scm ends here | 216 | ;;; tests.scm ends here |
