build-utils.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2015, 2016 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-build-utils)
  19. #:use-module (guix tests)
  20. #:use-module (guix build utils)
  21. #:use-module ((guix utils)
  22. #:select (%current-system call-with-temporary-directory))
  23. #:use-module (gnu packages)
  24. #:use-module (gnu packages bootstrap)
  25. #:use-module (srfi srfi-34)
  26. #:use-module (srfi srfi-64)
  27. #:use-module (rnrs io ports)
  28. #:use-module (ice-9 popen))
  29. (test-begin "build-utils")
  30. (test-equal "alist-cons-before"
  31. '((a . 1) (x . 42) (b . 2) (c . 3))
  32. (alist-cons-before 'b 'x 42 '((a . 1) (b . 2) (c . 3))))
  33. (test-equal "alist-cons-before, reference not found"
  34. '((a . 1) (b . 2) (c . 3) (x . 42))
  35. (alist-cons-before 'z 'x 42 '((a . 1) (b . 2) (c . 3))))
  36. (test-equal "alist-cons-after"
  37. '((a . 1) (b . 2) (x . 42) (c . 3))
  38. (alist-cons-after 'b 'x 42 '((a . 1) (b . 2) (c . 3))))
  39. (test-equal "alist-cons-after, reference not found"
  40. '((a . 1) (b . 2) (c . 3) (x . 42))
  41. (alist-cons-after 'z 'x 42 '((a . 1) (b . 2) (c . 3))))
  42. (test-equal "alist-replace"
  43. '((a . 1) (b . 77) (c . 3))
  44. (alist-replace 'b 77 '((a . 1) (b . 2) (c . 3))))
  45. (test-assert "alist-replace, key not found"
  46. (not (false-if-exception
  47. (alist-replace 'z 77 '((a . 1) (b . 2) (c . 3))))))
  48. (test-equal "fold-port-matches"
  49. (make-list 3 "Guix")
  50. (call-with-input-string "Guix is cool, Guix rocks, and it uses Guile, Guix!"
  51. (lambda (port)
  52. (fold-port-matches cons '() "Guix" port))))
  53. (test-equal "fold-port-matches, trickier"
  54. (reverse '("Guix" "guix" "Guix" "guiX" "Guix"))
  55. (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
  56. (lambda (port)
  57. (fold-port-matches cons '()
  58. (list (char-set #\G #\g)
  59. (char-set #\u)
  60. (char-set #\i)
  61. (char-set #\x #\X))
  62. port))))
  63. (test-equal "fold-port-matches, with unmatched chars"
  64. '("Guix" #\, #\space
  65. "guix" #\, #\space
  66. #\G #\u #\i "Guix" "guiX" #\, #\space
  67. "Guix")
  68. (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
  69. (lambda (port)
  70. (reverse
  71. (fold-port-matches cons '()
  72. (list (char-set #\G #\g)
  73. (char-set #\u)
  74. (char-set #\i)
  75. (char-set #\x #\X))
  76. port
  77. cons)))))
  78. (test-equal "wrap-program, one input, multiple calls"
  79. "hello world\n"
  80. (call-with-temporary-directory
  81. (lambda (directory)
  82. (let ((bash (search-bootstrap-binary "bash" (%current-system)))
  83. (foo (string-append directory "/foo")))
  84. (call-with-output-file foo
  85. (lambda (p)
  86. (format p
  87. "#!~a~%echo \"${GUIX_FOO} ${GUIX_BAR}\"~%"
  88. bash)))
  89. (chmod foo #o777)
  90. ;; wrap-program uses `which' to find bash for the wrapper shebang, but
  91. ;; it can't know about the bootstrap bash in the store, since it's not
  92. ;; named "bash". Help it out a bit by providing a symlink it this
  93. ;; package's output.
  94. (setenv "PATH" (dirname bash))
  95. (wrap-program foo `("GUIX_FOO" prefix ("hello")))
  96. (wrap-program foo `("GUIX_BAR" prefix ("world")))
  97. ;; The bootstrap Bash is linked against an old libc and would abort with
  98. ;; an assertion failure when trying to load incompatible locale data.
  99. (unsetenv "LOCPATH")
  100. (let* ((pipe (open-input-pipe foo))
  101. (str (get-string-all pipe)))
  102. (with-directory-excursion directory
  103. (for-each delete-file '("foo" ".foo-real")))
  104. (and (zero? (close-pipe pipe))
  105. str))))))
  106. (test-end)