test.scm 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix import test)
  19. #:use-module (srfi srfi-1)
  20. #:use-module (guix packages)
  21. #:use-module (guix upstream)
  22. #:use-module ((guix utils) #:select (version-prefix?))
  23. #:use-module (ice-9 vlist)
  24. #:use-module (ice-9 match)
  25. #:export (%test-updater))
  26. ;;; Commentary:
  27. ;;;
  28. ;;; This module defines a pseudo updater whose sole purpose is to allow
  29. ;;; testing of the whole 'guix refresh' command.
  30. ;;;
  31. ;;; Code:
  32. (define test-target-version
  33. ;; VHash that maps package names to version/URL tuples.
  34. (make-parameter
  35. (or (and=> (getenv "GUIX_TEST_UPDATER_TARGETS")
  36. (lambda (str)
  37. (alist->vhash (call-with-input-string str read))))
  38. vlist-null)))
  39. (define (available-updates package)
  40. "Return the list of available <upstream-source> records for PACKAGE."
  41. (vhash-fold* (lambda (version+updates result)
  42. (match version+updates
  43. ((version (updates ...))
  44. (if (version-prefix? version
  45. (package-version package))
  46. (append (map (match-lambda
  47. ((version url)
  48. (upstream-source
  49. (package (package-name package))
  50. (version version)
  51. (urls (list url))))
  52. ((version url (inputs ...))
  53. (upstream-source
  54. (package (package-name package))
  55. (version version)
  56. (urls (list url))
  57. (inputs
  58. (map (lambda (name)
  59. (upstream-input
  60. (name name)
  61. (downstream-name name)))
  62. inputs)))))
  63. updates)
  64. result)
  65. result))))
  66. '()
  67. (package-name package)
  68. (test-target-version)))
  69. (define (test-package? package)
  70. "Return true if PACKAGE has pseudo updates available."
  71. (and (not (vlist-null? (test-target-version))) ;cheap test
  72. (pair? (available-updates package))))
  73. (define* (import-release package #:key (version #f))
  74. "Return the <upstream-source> record denoting either the latest version of
  75. PACKAGE or VERSION."
  76. (match (available-updates package)
  77. (() #f)
  78. ((sources ...)
  79. (if version
  80. (find (lambda (source)
  81. (string=? (upstream-source-version source)
  82. version))
  83. sources)
  84. (first sources)))))
  85. (define %test-updater
  86. (upstream-updater
  87. (name 'test)
  88. (description "Pseudo updater for testing purposes.")
  89. (pred test-package?)
  90. (import import-release)))