inferior.scm 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018, 2019 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 (test-inferior)
  19. #:use-module (guix tests)
  20. #:use-module (guix inferior)
  21. #:use-module (guix packages)
  22. #:use-module (guix store)
  23. #:use-module (guix profiles)
  24. #:use-module (guix derivations)
  25. #:use-module (gnu packages)
  26. #:use-module (gnu packages bootstrap)
  27. #:use-module (gnu packages guile)
  28. #:use-module (srfi srfi-1)
  29. #:use-module (srfi srfi-64)
  30. #:use-module (ice-9 match))
  31. (define %top-srcdir
  32. (dirname (search-path %load-path "guix.scm")))
  33. (define %top-builddir
  34. (dirname (search-path %load-compiled-path "guix.go")))
  35. (define %store
  36. (open-connection-for-tests))
  37. (define (manifest-entry->list entry)
  38. (list (manifest-entry-name entry)
  39. (manifest-entry-version entry)
  40. (manifest-entry-output entry)
  41. (manifest-entry-search-paths entry)
  42. (map manifest-entry->list (manifest-entry-dependencies entry))))
  43. (test-begin "inferior")
  44. (test-equal "open-inferior"
  45. '(42 #t)
  46. (let ((inferior (open-inferior %top-builddir
  47. #:command "scripts/guix")))
  48. (and (inferior? inferior)
  49. (let ((a (inferior-eval '(apply * '(6 7)) inferior))
  50. (b (inferior-eval '(@ (gnu packages base) coreutils)
  51. inferior)))
  52. (close-inferior inferior)
  53. (list a (inferior-object? b))))))
  54. (test-equal "inferior-packages"
  55. (take (sort (fold-packages (lambda (package lst)
  56. (cons (list (package-name package)
  57. (package-version package)
  58. (package-home-page package)
  59. (package-location package))
  60. lst))
  61. '())
  62. (lambda (x y)
  63. (string<? (car x) (car y))))
  64. 10)
  65. (let* ((inferior (open-inferior %top-builddir
  66. #:command "scripts/guix"))
  67. (packages (inferior-packages inferior)))
  68. (and (every string? (map inferior-package-synopsis packages))
  69. (let ()
  70. (define result
  71. (take (sort (map (lambda (package)
  72. (list (inferior-package-name package)
  73. (inferior-package-version package)
  74. (inferior-package-home-page package)
  75. (inferior-package-location package)))
  76. packages)
  77. (lambda (x y)
  78. (string<? (car x) (car y))))
  79. 10))
  80. (close-inferior inferior)
  81. result))))
  82. (test-equal "inferior-available-packages"
  83. (take (sort (fold-available-packages
  84. (lambda* (name version result
  85. #:key supported? deprecated?
  86. #:allow-other-keys)
  87. (if (and supported? (not deprecated?))
  88. (alist-cons name version result)
  89. result))
  90. '())
  91. (lambda (x y)
  92. (string<? (car x) (car y))))
  93. 10)
  94. (let* ((inferior (open-inferior %top-builddir
  95. #:command "scripts/guix"))
  96. (packages (inferior-available-packages inferior)))
  97. (close-inferior inferior)
  98. (take (sort packages (lambda (x y)
  99. (string<? (car x) (car y))))
  100. 10)))
  101. (test-equal "lookup-inferior-packages"
  102. (let ((->list (lambda (package)
  103. (list (package-name package)
  104. (package-version package)
  105. (package-location package)))))
  106. (list (map ->list (find-packages-by-name "guile" #f))
  107. (map ->list (find-packages-by-name "guile" "2.2"))))
  108. (let* ((inferior (open-inferior %top-builddir
  109. #:command "scripts/guix"))
  110. (->list (lambda (package)
  111. (list (inferior-package-name package)
  112. (inferior-package-version package)
  113. (inferior-package-location package))))
  114. (lst1 (map ->list
  115. (lookup-inferior-packages inferior "guile")))
  116. (lst2 (map ->list
  117. (lookup-inferior-packages inferior
  118. "guile" "2.2"))))
  119. (close-inferior inferior)
  120. (list lst1 lst2)))
  121. (test-assert "lookup-inferior-packages and eq?-ness"
  122. (let* ((inferior (open-inferior %top-builddir
  123. #:command "scripts/guix"))
  124. (lst1 (lookup-inferior-packages inferior "guile"))
  125. (lst2 (lookup-inferior-packages inferior "guile")))
  126. (close-inferior inferior)
  127. (every eq? lst1 lst2)))
  128. (test-equal "inferior-package-inputs"
  129. (let ((->list (match-lambda
  130. ((label (? package? package) . rest)
  131. `(,label
  132. (package ,(package-name package)
  133. ,(package-version package)
  134. ,(package-location package))
  135. ,@rest)))))
  136. (list (map ->list (package-inputs guile-2.2))
  137. (map ->list (package-native-inputs guile-2.2))
  138. (map ->list (package-propagated-inputs guile-2.2))))
  139. (let* ((inferior (open-inferior %top-builddir
  140. #:command "scripts/guix"))
  141. (guile (first (lookup-inferior-packages inferior "guile")))
  142. (->list (match-lambda
  143. ((label (? inferior-package? package) . rest)
  144. `(,label
  145. (package ,(inferior-package-name package)
  146. ,(inferior-package-version package)
  147. ,(inferior-package-location package))
  148. ,@rest))))
  149. (result (list (map ->list (inferior-package-inputs guile))
  150. (map ->list
  151. (inferior-package-native-inputs guile))
  152. (map ->list
  153. (inferior-package-propagated-inputs
  154. guile)))))
  155. (close-inferior inferior)
  156. result))
  157. (test-equal "inferior-package-search-paths"
  158. (package-native-search-paths guile-2.2)
  159. (let* ((inferior (open-inferior %top-builddir
  160. #:command "scripts/guix"))
  161. (guile (first (lookup-inferior-packages inferior "guile")))
  162. (result (inferior-package-native-search-paths guile)))
  163. (close-inferior inferior)
  164. result))
  165. (test-equal "inferior-eval-with-store"
  166. (add-text-to-store %store "foo" "Hello, world!")
  167. (let* ((inferior (open-inferior %top-builddir
  168. #:command "scripts/guix")))
  169. (inferior-eval-with-store inferior %store
  170. '(lambda (store)
  171. (add-text-to-store store "foo"
  172. "Hello, world!")))))
  173. (test-equal "inferior-package-derivation"
  174. (map derivation-file-name
  175. (list (package-derivation %store %bootstrap-guile "x86_64-linux")
  176. (package-derivation %store %bootstrap-guile "armhf-linux")))
  177. (let* ((inferior (open-inferior %top-builddir
  178. #:command "scripts/guix"))
  179. (packages (inferior-packages inferior))
  180. (guile (find (lambda (package)
  181. (string=? (package-name %bootstrap-guile)
  182. (inferior-package-name package)))
  183. packages)))
  184. (map derivation-file-name
  185. (list (inferior-package-derivation %store guile "x86_64-linux")
  186. (inferior-package-derivation %store guile "armhf-linux")))))
  187. (test-equal "inferior-package->manifest-entry"
  188. (manifest-entry->list (package->manifest-entry
  189. (first (find-best-packages-by-name "guile" #f))))
  190. (let* ((inferior (open-inferior %top-builddir
  191. #:command "scripts/guix"))
  192. (guile (first (lookup-inferior-packages inferior "guile")))
  193. (entry (inferior-package->manifest-entry guile)))
  194. (close-inferior inferior)
  195. (manifest-entry->list entry)))
  196. (test-equal "packages->manifest"
  197. (map manifest-entry->list
  198. (manifest-entries (packages->manifest
  199. (find-best-packages-by-name "guile" #f))))
  200. (let* ((inferior (open-inferior %top-builddir
  201. #:command "scripts/guix"))
  202. (guile (first (lookup-inferior-packages inferior "guile")))
  203. (manifest (packages->manifest (list guile))))
  204. (close-inferior inferior)
  205. (map manifest-entry->list (manifest-entries manifest))))
  206. (test-end "inferior")