inferior.scm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018, 2019, 2020 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-exception"
  56. '(a b c d)
  57. (let ((inferior (open-inferior %top-builddir
  58. #:command "scripts/guix")))
  59. (guard (c ((inferior-exception? c)
  60. (close-inferior inferior)
  61. (and (eq? inferior (inferior-exception-inferior c))
  62. (match (inferior-exception-stack c)
  63. (((_ (files lines columns)) ..1)
  64. (member "guix/repl.scm" files)))
  65. (inferior-exception-arguments c))))
  66. (inferior-eval '(throw 'a 'b 'c 'd) inferior)
  67. 'badness)))
  68. (test-equal "inferior-packages"
  69. (take (sort (fold-packages (lambda (package lst)
  70. (cons (list (package-name package)
  71. (package-version package)
  72. (package-home-page package)
  73. (package-location package))
  74. lst))
  75. '())
  76. (lambda (x y)
  77. (string<? (car x) (car y))))
  78. 10)
  79. (let* ((inferior (open-inferior %top-builddir
  80. #:command "scripts/guix"))
  81. (packages (inferior-packages inferior)))
  82. (and (every string? (map inferior-package-synopsis packages))
  83. (let ()
  84. (define result
  85. (take (sort (map (lambda (package)
  86. (list (inferior-package-name package)
  87. (inferior-package-version package)
  88. (inferior-package-home-page package)
  89. (inferior-package-location package)))
  90. packages)
  91. (lambda (x y)
  92. (string<? (car x) (car y))))
  93. 10))
  94. (close-inferior inferior)
  95. result))))
  96. (test-equal "inferior-available-packages"
  97. (take (sort (fold-available-packages
  98. (lambda* (name version result
  99. #:key supported? deprecated?
  100. #:allow-other-keys)
  101. (if (and supported? (not deprecated?))
  102. (alist-cons name version result)
  103. result))
  104. '())
  105. (lambda (x y)
  106. (string<? (car x) (car y))))
  107. 10)
  108. (let* ((inferior (open-inferior %top-builddir
  109. #:command "scripts/guix"))
  110. (packages (inferior-available-packages inferior)))
  111. (close-inferior inferior)
  112. (take (sort packages (lambda (x y)
  113. (string<? (car x) (car y))))
  114. 10)))
  115. (test-equal "lookup-inferior-packages"
  116. (let ((->list (lambda (package)
  117. (list (package-name package)
  118. (package-version package)
  119. (package-location package)))))
  120. (list (map ->list (find-packages-by-name "guile" #f))
  121. (map ->list (find-packages-by-name "guile" "2.2"))))
  122. (let* ((inferior (open-inferior %top-builddir
  123. #:command "scripts/guix"))
  124. (->list (lambda (package)
  125. (list (inferior-package-name package)
  126. (inferior-package-version package)
  127. (inferior-package-location package))))
  128. (lst1 (map ->list
  129. (lookup-inferior-packages inferior "guile")))
  130. (lst2 (map ->list
  131. (lookup-inferior-packages inferior
  132. "guile" "2.2"))))
  133. (close-inferior inferior)
  134. (list lst1 lst2)))
  135. (test-assert "lookup-inferior-packages and eq?-ness"
  136. (let* ((inferior (open-inferior %top-builddir
  137. #:command "scripts/guix"))
  138. (lst1 (lookup-inferior-packages inferior "guile"))
  139. (lst2 (lookup-inferior-packages inferior "guile")))
  140. (close-inferior inferior)
  141. (every eq? lst1 lst2)))
  142. (test-equal "inferior-package-inputs"
  143. (let ((->list (match-lambda
  144. ((label (? package? package) . rest)
  145. `(,label
  146. (package ,(package-name package)
  147. ,(package-version package)
  148. ,(package-location package))
  149. ,@rest)))))
  150. (list (map ->list (package-inputs guile-2.2))
  151. (map ->list (package-native-inputs guile-2.2))
  152. (map ->list (package-propagated-inputs guile-2.2))))
  153. (let* ((inferior (open-inferior %top-builddir
  154. #:command "scripts/guix"))
  155. (guile (first (lookup-inferior-packages inferior "guile")))
  156. (->list (match-lambda
  157. ((label (? inferior-package? package) . rest)
  158. `(,label
  159. (package ,(inferior-package-name package)
  160. ,(inferior-package-version package)
  161. ,(inferior-package-location package))
  162. ,@rest))))
  163. (result (list (map ->list (inferior-package-inputs guile))
  164. (map ->list
  165. (inferior-package-native-inputs guile))
  166. (map ->list
  167. (inferior-package-propagated-inputs
  168. guile)))))
  169. (close-inferior inferior)
  170. result))
  171. (test-equal "inferior-package-search-paths"
  172. (package-native-search-paths guile-3.0)
  173. (let* ((inferior (open-inferior %top-builddir
  174. #:command "scripts/guix"))
  175. (guile (first (lookup-inferior-packages inferior "guile")))
  176. (result (inferior-package-native-search-paths guile)))
  177. (close-inferior inferior)
  178. result))
  179. (test-equal "inferior-eval-with-store"
  180. (add-text-to-store %store "foo" "Hello, world!")
  181. (let* ((inferior (open-inferior %top-builddir
  182. #:command "scripts/guix")))
  183. (inferior-eval-with-store inferior %store
  184. '(lambda (store)
  185. (add-text-to-store store "foo"
  186. "Hello, world!")))))
  187. (test-assert "inferior-eval-with-store, &store-protocol-error"
  188. (let* ((inferior (open-inferior %top-builddir
  189. #:command "scripts/guix")))
  190. (guard (c ((store-protocol-error? c)
  191. (string-contains (store-protocol-error-message c)
  192. "invalid character")))
  193. (inferior-eval-with-store inferior %store
  194. '(lambda (store)
  195. (add-text-to-store store "we|rd/?!@"
  196. "uh uh")))
  197. #f)))
  198. (test-equal "inferior-package-derivation"
  199. (map derivation-file-name
  200. (list (package-derivation %store %bootstrap-guile "x86_64-linux")
  201. (package-derivation %store %bootstrap-guile "armhf-linux")))
  202. (let* ((inferior (open-inferior %top-builddir
  203. #:command "scripts/guix"))
  204. (packages (inferior-packages inferior))
  205. (guile (find (lambda (package)
  206. (string=? (package-name %bootstrap-guile)
  207. (inferior-package-name package)))
  208. packages)))
  209. (map derivation-file-name
  210. (list (inferior-package-derivation %store guile "x86_64-linux")
  211. (inferior-package-derivation %store guile "armhf-linux")))))
  212. (test-equal "inferior-package->manifest-entry"
  213. (manifest-entry->list (package->manifest-entry
  214. (first (find-best-packages-by-name "guile" #f))))
  215. (let* ((inferior (open-inferior %top-builddir
  216. #:command "scripts/guix"))
  217. (guile (first (lookup-inferior-packages inferior "guile")))
  218. (entry (inferior-package->manifest-entry guile)))
  219. (close-inferior inferior)
  220. (manifest-entry->list entry)))
  221. (test-equal "packages->manifest"
  222. (map manifest-entry->list
  223. (manifest-entries (packages->manifest
  224. (find-best-packages-by-name "guile" #f))))
  225. (let* ((inferior (open-inferior %top-builddir
  226. #:command "scripts/guix"))
  227. (guile (first (lookup-inferior-packages inferior "guile")))
  228. (manifest (packages->manifest (list guile))))
  229. (close-inferior inferior)
  230. (map manifest-entry->list (manifest-entries manifest))))
  231. (test-end "inferior")