egg.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
  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-eggs)
  19. #:use-module (guix import egg)
  20. #:use-module (guix gexp)
  21. #:use-module (guix base32)
  22. #:use-module (gcrypt hash)
  23. #:use-module (guix tests)
  24. #:use-module ((guix build syscalls) #:select (mkdtemp!))
  25. #:use-module ((guix build utils) #:select (delete-file-recursively mkdir-p which))
  26. #:use-module ((guix utils) #:select (call-with-temporary-output-file))
  27. #:use-module (srfi srfi-1)
  28. #:use-module (srfi srfi-64)
  29. #:use-module (web uri)
  30. #:use-module (ice-9 match))
  31. (define test-egg-1
  32. '((synopsis "Example egg")
  33. (license "GPL-3/MIT")
  34. (version "1.0.0")
  35. (test-dependencies test srfi-1)
  36. (foreign-dependencies libgit2)
  37. (build-dependencies begin-syntax)
  38. (dependencies datatype)
  39. (author "John Doe")))
  40. (define test-egg-2
  41. '((synopsis "Example egg")
  42. (license "GPL-3+")
  43. (version "0.3")
  44. (test-dependencies test)
  45. (foreign-dependencies libgit2)
  46. (build-dependencies begin-syntax)
  47. (dependencies datatype)
  48. (author "Alice Bobson")))
  49. (define test-egg-1-file "/tmp/guix-egg-1")
  50. (define test-egg-2-file "/tmp/guix-egg-2")
  51. (test-begin "egg")
  52. (test-equal "guix-package->egg-name"
  53. "bar"
  54. (guix-package->egg-name
  55. (dummy-package "dummy"
  56. (name "chicken-bar"))))
  57. ;; Copied from tests/hackage.scm
  58. (define-syntax-rule (define-package-matcher name pattern)
  59. (define* (name obj)
  60. (match obj
  61. (pattern #t)
  62. (x (pk 'fail x #f)))))
  63. (define (eval-test-with-egg-file egg-name egg-test egg-file matcher)
  64. (call-with-output-file egg-file
  65. (lambda (port)
  66. (write egg-test port)))
  67. (matcher (egg->guix-package egg-name
  68. #:file egg-file
  69. #:source (plain-file
  70. (string-append egg-name "-egg")
  71. "content"))))
  72. (define-package-matcher match-chicken-foo
  73. ('package
  74. ('name "chicken-foo")
  75. ('version "1.0.0")
  76. ('source (? file-like? source))
  77. ('build-system 'chicken-build-system)
  78. ('arguments ('quasiquote ('#:egg-name "foo")))
  79. ('native-inputs
  80. ('quasiquote
  81. (("chicken-test" ('unquote chicken-test))
  82. ("chicken-srfi-1" ('unquote chicken-srfi-1))
  83. ("chicken-begin-syntax" ('unquote chicken-begin-syntax)))))
  84. ('inputs
  85. ('quasiquote
  86. (("libgit2" ('unquote libgit2)))))
  87. ('propagated-inputs
  88. ('quasiquote
  89. (("chicken-datatype" ('unquote chicken-datatype)))))
  90. ('home-page "https://wiki.call-cc.org/egg/foo")
  91. ('synopsis "Example egg")
  92. ('description #f)
  93. ('license '(list license:gpl3 license:expat))))
  94. (define-package-matcher match-chicken-bar
  95. ('package
  96. ('name "chicken-bar")
  97. ('version "0.3")
  98. ('source (? file-like? source))
  99. ('build-system 'chicken-build-system)
  100. ('arguments ('quasiquote ('#:egg-name "bar")))
  101. ('native-inputs
  102. ('quasiquote
  103. (("chicken-test" ('unquote chicken-test))
  104. ("chicken-begin-syntax" ('unquote chicken-begin-syntax)))))
  105. ('inputs
  106. ('quasiquote
  107. (("libgit2" ('unquote libgit2)))))
  108. ('propagated-inputs
  109. ('quasiquote
  110. (("chicken-datatype" ('unquote chicken-datatype)))))
  111. ('home-page "https://wiki.call-cc.org/egg/bar")
  112. ('synopsis "Example egg")
  113. ('description #f)
  114. ('license 'license:gpl3+)))
  115. (test-assert "egg->guix-package local file, multiple licenses"
  116. (eval-test-with-egg-file "foo" test-egg-1 test-egg-1-file match-chicken-foo))
  117. (test-assert "egg->guix-package local file, single license"
  118. (eval-test-with-egg-file "bar" test-egg-2 test-egg-2-file match-chicken-bar))
  119. (test-end "egg")