scripts-build.scm 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2017 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-scripts-build)
  19. #:use-module (guix tests)
  20. #:use-module (guix store)
  21. #:use-module (guix packages)
  22. #:use-module (guix scripts build)
  23. #:use-module (guix ui)
  24. #:use-module (guix utils)
  25. #:use-module (gnu packages)
  26. #:use-module (gnu packages base)
  27. #:use-module (gnu packages busybox)
  28. #:use-module (ice-9 match)
  29. #:use-module (srfi srfi-64))
  30. (test-begin "scripts-build")
  31. (test-assert "options->transformation, no transformations"
  32. (let ((p (dummy-package "foo"))
  33. (t (options->transformation '())))
  34. (with-store store
  35. (eq? (t store p) p))))
  36. (test-assert "options->transformation, with-source"
  37. ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm' source should
  38. ;; be applicable.
  39. (let* ((p (dummy-package "guix.scm"))
  40. (s (search-path %load-path "guix.scm"))
  41. (t (options->transformation `((with-source . ,s)))))
  42. (with-store store
  43. (let ((new (t store p)))
  44. (and (not (eq? new p))
  45. (string=? (package-source new)
  46. (add-to-store store "guix.scm" #t
  47. "sha256" s)))))))
  48. (test-assert "options->transformation, with-source, replacement"
  49. ;; Same, but this time the original package has a 'replacement' field. We
  50. ;; expect that replacement to be set to #f in the new package.
  51. (let* ((p (dummy-package "guix.scm" (replacement coreutils)))
  52. (s (search-path %load-path "guix.scm"))
  53. (t (options->transformation `((with-source . ,s)))))
  54. (with-store store
  55. (let ((new (t store p)))
  56. (and (not (eq? new p))
  57. (string=? (package-source new)
  58. (add-to-store store "guix.scm" #t "sha256" s))
  59. (not (package-replacement new)))))))
  60. (test-assert "options->transformation, with-source, with version"
  61. ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm-2.0' source
  62. ;; should be applicable, and its version should be extracted.
  63. (let ((p (dummy-package "foo"))
  64. (s (search-path %load-path "guix.scm")))
  65. (call-with-temporary-directory
  66. (lambda (directory)
  67. (let* ((f (string-append directory "/foo-42.0.tar.gz"))
  68. (t (options->transformation `((with-source . ,f)))))
  69. (copy-file s f)
  70. (with-store store
  71. (let ((new (t store p)))
  72. (and (not (eq? new p))
  73. (string=? (package-name new) (package-name p))
  74. (string=? (package-version new) "42.0")
  75. (string=? (package-source new)
  76. (add-to-store store (basename f) #t
  77. "sha256" f))))))))))
  78. (test-assert "options->transformation, with-source, no matches"
  79. ;; When a transformation in not applicable, a warning must be raised.
  80. (let* ((p (dummy-package "foobar"))
  81. (s (search-path %load-path "guix.scm"))
  82. (t (options->transformation `((with-source . ,s)))))
  83. (with-store store
  84. (let* ((port (open-output-string))
  85. (new (parameterize ((guix-warning-port port))
  86. (t store p))))
  87. (and (eq? new p)
  88. (string-contains (get-output-string port)
  89. "had no effect"))))))
  90. (test-assert "options->transformation, with-source, PKG=URI"
  91. (let* ((p (dummy-package "foo"))
  92. (s (search-path %load-path "guix.scm"))
  93. (f (string-append "foo=" s))
  94. (t (options->transformation `((with-source . ,f)))))
  95. (with-store store
  96. (let ((new (t store p)))
  97. (and (not (eq? new p))
  98. (string=? (package-name new) (package-name p))
  99. (string=? (package-version new)
  100. (package-version p))
  101. (string=? (package-source new)
  102. (add-to-store store (basename s) #t
  103. "sha256" s)))))))
  104. (test-assert "options->transformation, with-source, PKG@VER=URI"
  105. (let* ((p (dummy-package "foo"))
  106. (s (search-path %load-path "guix.scm"))
  107. (f (string-append "foo@42.0=" s))
  108. (t (options->transformation `((with-source . ,f)))))
  109. (with-store store
  110. (let ((new (t store p)))
  111. (and (not (eq? new p))
  112. (string=? (package-name new) (package-name p))
  113. (string=? (package-version new) "42.0")
  114. (string=? (package-source new)
  115. (add-to-store store (basename s) #t
  116. "sha256" s)))))))
  117. (test-assert "options->transformation, with-input"
  118. (let* ((p (dummy-package "guix.scm"
  119. (inputs `(("foo" ,(specification->package "coreutils"))
  120. ("bar" ,(specification->package "grep"))
  121. ("baz" ,(dummy-package "chbouib"
  122. (native-inputs `(("x" ,grep)))))))))
  123. (t (options->transformation '((with-input . "coreutils=busybox")
  124. (with-input . "grep=findutils")))))
  125. (with-store store
  126. (let ((new (t store p)))
  127. (and (not (eq? new p))
  128. (match (package-inputs new)
  129. ((("foo" dep1) ("bar" dep2) ("baz" dep3))
  130. (and (eq? dep1 busybox)
  131. (eq? dep2 findutils)
  132. (string=? (package-name dep3) "chbouib")
  133. (match (package-native-inputs dep3)
  134. ((("x" dep))
  135. (eq? dep findutils)))))))))))
  136. (test-assert "options->transformation, with-graft"
  137. (let* ((p (dummy-package "guix.scm"
  138. (inputs `(("foo" ,grep)
  139. ("bar" ,(dummy-package "chbouib"
  140. (native-inputs `(("x" ,grep)))))))))
  141. (t (options->transformation '((with-graft . "grep=findutils")))))
  142. (with-store store
  143. (let ((new (t store p)))
  144. (and (not (eq? new p))
  145. (match (package-inputs new)
  146. ((("foo" dep1) ("bar" dep2))
  147. (and (string=? (package-full-name dep1)
  148. (package-full-name grep))
  149. (eq? (package-replacement dep1) findutils)
  150. (string=? (package-name dep2) "chbouib")
  151. (match (package-native-inputs dep2)
  152. ((("x" dep))
  153. (eq? (package-replacement dep) findutils)))))))))))
  154. (test-end)