inferior.scm 10 KB

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