~ruther/ruthless-guix

5f690393fdc6883c3a756fbceeeeb00e1dd2c0a1 — Rutherther 3 days ago f3d1798
feat: add system tests support
3 files changed, 91 insertions(+), 0 deletions(-)

A etc/manifests/system-tests.scm
A modules/ruther.scm
A modules/ruther/tests.scm
A etc/manifests/system-tests.scm => etc/manifests/system-tests.scm +61 -0
@@ 0,0 1,61 @@
;;; This file has been taken from GNU Guix.
;;; The original copyright header follows.

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016, 2018-2020, 2022 Ludovic Courtès <ludo@gnu.org>
;;;
;;;
;;; GNU Guix 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 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(use-modules (ruther tests)
             (gnu tests)
             (gnu packages package-management)
             (guix monads)
             (guix store)
             ((guix git-download) #:select (git-predicate))
             ((guix utils) #:select (current-source-directory))
             (git)
             (srfi srfi-1)
             (ice-9 match))

(define (system-test->manifest-entry test)
  "Return a manifest entry for TEST, a system test."
  (manifest-entry
    (name (string-append "test." (system-test-name test)))
    (version "0")
    (item test)))

(define* (filter-tests
          #:key
          (tests (ruther-system-tests))
          (filter-tests (getenv "TESTS")))
  (match filter-tests
    (#f
     tests)
    ((= string-tokenize (filter-tests ...))
     (filter (lambda (test)
               (member (system-test-name test) filter-tests))
             tests))))

(define (system-test-manifest)
  "Return a manifest containing all the system tests, or all those selected by
the 'TESTS' environment variable."
  (let* ((tests (filter-tests)))
    (format (current-error-port) "Selected ~a system tests...~%"
            (length tests))

    (manifest (map system-test->manifest-entry tests))))

;; Return the manifest.
(system-test-manifest)

A modules/ruther.scm => modules/ruther.scm +3 -0
@@ 0,0 1,3 @@
(define-module (ruther))

;; Dummy for now.

A modules/ruther/tests.scm => modules/ruther/tests.scm +27 -0
@@ 0,0 1,27 @@
(define-module (ruther tests)
  #:use-module (gnu tests)
  #:use-module (guix discovery)
  #:use-module (guix ui)
  #:export (ruther-test-modules
            fold-ruther-system-tests
            ruther-system-tests))

(define (ruther-test-modules)
  "Return the list of modules that define system tests."
  (scheme-modules (dirname (search-path %load-path "ruther.scm"))
                  "ruther/tests"
                  #:warn warn-about-load-error))

(define (fold-ruther-system-tests proc seed)
  "Invoke PROC on each system test, passing it the test and the previous
result."
  (fold-module-public-variables (lambda (obj result)
                                  (if (system-test? obj)
                                      (cons obj result)
                                      result))
                                '()
                                (ruther-test-modules)))

(define (ruther-system-tests)
  "Return the list of system tests."
  (reverse (fold-ruther-system-tests cons '())))