You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

148 lines
5.5 KiB

  1. ;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
  2. ;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of Guix.
  5. ;;;
  6. ;;; 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. ;;; 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 Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-packages)
  19. #:use-module (guix store)
  20. #:use-module (guix utils)
  21. #:use-module (guix derivations)
  22. #:use-module (guix packages)
  23. #:use-module (guix build-system trivial)
  24. #:use-module (guix build-system gnu)
  25. #:use-module (distro)
  26. #:use-module (distro packages base)
  27. #:use-module (srfi srfi-26)
  28. #:use-module (srfi srfi-64)
  29. #:use-module (ice-9 match))
  30. ;; Test the high-level packaging layer.
  31. (define %store
  32. (false-if-exception (open-connection)))
  33. (when %store
  34. ;; Make sure we build everything by ourselves.
  35. (set-build-options %store #:use-substitutes? #f))
  36. (define %bootstrap-inputs
  37. ;; Use the bootstrap inputs so it doesn't take ages to run these tests.
  38. ;; This still involves building GNU Make and GNU Diffutils.
  39. (@@ (distro packages base) %boot0-inputs))
  40. (define %bootstrap-guile
  41. (@@ (distro packages base) %bootstrap-guile))
  42. (test-begin "packages")
  43. (define-syntax-rule (dummy-package name* extra-fields ...)
  44. (package (name name*) (version "0") (source #f)
  45. (build-system gnu-build-system)
  46. (description #f) (long-description #f)
  47. (home-page #f)
  48. extra-fields ...))
  49. (test-assert "package-transitive-inputs"
  50. (let* ((a (dummy-package "a"))
  51. (b (dummy-package "b"
  52. (propagated-inputs `(("a" ,a)))))
  53. (c (dummy-package "c"
  54. (inputs `(("a" ,a)))))
  55. (d (dummy-package "d"
  56. (propagated-inputs `(("x" "something.drv")))))
  57. (e (dummy-package "e"
  58. (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
  59. (and (null? (package-transitive-inputs a))
  60. (equal? `(("a" ,a)) (package-transitive-inputs b))
  61. (equal? `(("a" ,a)) (package-transitive-inputs c))
  62. (equal? (package-propagated-inputs d)
  63. (package-transitive-inputs d))
  64. (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c)
  65. ("d" ,d) ("d/x" "something.drv"))
  66. (pk 'x (package-transitive-inputs e))))))
  67. (test-skip (if (not %store) 2 0))
  68. (test-assert "trivial"
  69. (let* ((p (package (inherit (dummy-package "trivial"))
  70. (build-system trivial-build-system)
  71. (source #f)
  72. (arguments
  73. `(#:guile ,%bootstrap-guile
  74. #:builder
  75. (begin
  76. (mkdir %output)
  77. (call-with-output-file (string-append %output "/test")
  78. (lambda (p)
  79. (display '(hello guix) p))))))))
  80. (d (package-derivation %store p)))
  81. (and (build-derivations %store (list d))
  82. (let ((p (pk 'drv d (derivation-path->output-path d))))
  83. (equal? '(hello guix)
  84. (call-with-input-file (string-append p "/test") read))))))
  85. (test-assert "trivial with system-dependent input"
  86. (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
  87. (build-system trivial-build-system)
  88. (source #f)
  89. (arguments
  90. `(#:guile ,%bootstrap-guile
  91. #:builder
  92. (let ((out (assoc-ref %outputs "out"))
  93. (bash (assoc-ref %build-inputs "bash")))
  94. (zero? (system* bash "-c"
  95. (format #f "echo hello > ~a" out))))))
  96. (inputs `(("bash" ,(lambda (system)
  97. (search-bootstrap-binary "bash"
  98. system)))))))
  99. (d (package-derivation %store p)))
  100. (and (build-derivations %store (list d))
  101. (let ((p (pk 'drv d (derivation-path->output-path d))))
  102. (eq? 'hello (call-with-input-file p read))))))
  103. (test-assert "GNU Hello"
  104. (let ((hello (package-with-explicit-inputs hello %bootstrap-inputs
  105. #:guile %bootstrap-guile)))
  106. (and (package? hello)
  107. (or (location? (package-location hello))
  108. (not (package-location hello)))
  109. (let* ((drv (package-derivation %store hello))
  110. (out (derivation-path->output-path drv)))
  111. (and (build-derivations %store (list drv))
  112. (file-exists? (string-append out "/bin/hello")))))))
  113. (test-assert "find-packages-by-name"
  114. (match (find-packages-by-name "hello")
  115. (((? (cut eq? hello <>))) #t)
  116. (wrong (pk 'find-packages-by-name wrong #f))))
  117. (test-assert "find-packages-by-name with version"
  118. (match (find-packages-by-name "hello" (package-version hello))
  119. (((? (cut eq? hello <>))) #t)
  120. (wrong (pk 'find-packages-by-name wrong #f))))
  121. (test-end "packages")
  122. (exit (= (test-runner-fail-count (test-runner-current)) 0))
  123. ;;; Local Variables:
  124. ;;; eval: (put 'test-assert 'scheme-indent-function 1)
  125. ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
  126. ;;; End: