egg.scm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
  3. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (test-eggs)
  20. #:use-module (guix import egg)
  21. #:use-module (guix gexp)
  22. #:use-module (guix base32)
  23. #:use-module (gcrypt hash)
  24. #:use-module (guix tests)
  25. #:use-module ((guix build syscalls) #:select (mkdtemp!))
  26. #:use-module ((guix build utils) #:select (delete-file-recursively mkdir-p which))
  27. #:use-module ((guix utils) #:select (call-with-temporary-output-file))
  28. #:use-module (srfi srfi-1)
  29. #:use-module (srfi srfi-64)
  30. #:use-module (web uri)
  31. #:use-module (ice-9 match))
  32. (define test-egg-1
  33. '((synopsis "Example egg")
  34. (license "GPL-3/MIT")
  35. (version "1.0.0")
  36. (test-dependencies test srfi-1)
  37. (foreign-dependencies libgit2)
  38. (build-dependencies begin-syntax)
  39. (dependencies datatype)
  40. (author "John Doe")))
  41. (define test-egg-2
  42. '((synopsis "Example egg")
  43. (license "GPL-3+")
  44. (version "0.3")
  45. (test-dependencies test)
  46. (foreign-dependencies libgit2)
  47. (build-dependencies begin-syntax)
  48. (dependencies datatype)
  49. (author "Alice Bobson")))
  50. (define test-egg-1-file "/tmp/guix-egg-1")
  51. (define test-egg-2-file "/tmp/guix-egg-2")
  52. (test-begin "egg")
  53. (test-equal "guix-package->egg-name"
  54. "bar"
  55. (guix-package->egg-name
  56. (dummy-package "dummy"
  57. (name "chicken-bar"))))
  58. ;; Copied from tests/hackage.scm
  59. (define-syntax-rule (define-package-matcher name pattern)
  60. (define* (name obj)
  61. (match obj
  62. (pattern #t)
  63. (x (pk 'fail x #f)))))
  64. (define (eval-test-with-egg-file egg-name egg-test egg-file matcher)
  65. (call-with-output-file egg-file
  66. (lambda (port)
  67. (write egg-test port)))
  68. (matcher (egg->guix-package egg-name #f
  69. #:file egg-file
  70. #:source (plain-file
  71. (string-append egg-name "-egg")
  72. "content"))))
  73. (define-package-matcher match-chicken-foo
  74. ('package
  75. ('name "chicken-foo")
  76. ('version "1.0.0")
  77. ('source (? file-like? source))
  78. ('build-system 'chicken-build-system)
  79. ('arguments ('quasiquote ('#:egg-name "foo")))
  80. ('native-inputs
  81. ('list 'chicken-test 'chicken-srfi-1 'chicken-begin-syntax))
  82. ('inputs ('list 'libgit2))
  83. ('propagated-inputs ('list 'chicken-datatype))
  84. ('home-page "https://wiki.call-cc.org/egg/foo")
  85. ('synopsis "Example egg")
  86. ('description #f)
  87. ('license '(list license:gpl3 license:expat))))
  88. (define-package-matcher match-chicken-bar
  89. ('package
  90. ('name "chicken-bar")
  91. ('version "0.3")
  92. ('source (? file-like? source))
  93. ('build-system 'chicken-build-system)
  94. ('arguments ('quasiquote ('#:egg-name "bar")))
  95. ('native-inputs ('list 'chicken-test 'chicken-begin-syntax))
  96. ('inputs ('list 'libgit2))
  97. ('propagated-inputs ('list 'chicken-datatype))
  98. ('home-page "https://wiki.call-cc.org/egg/bar")
  99. ('synopsis "Example egg")
  100. ('description #f)
  101. ('license 'license:gpl3+)))
  102. (test-assert "egg->guix-package local file, multiple licenses"
  103. (eval-test-with-egg-file "foo" test-egg-1 test-egg-1-file match-chicken-foo))
  104. (test-assert "egg->guix-package local file, single license"
  105. (eval-test-with-egg-file "bar" test-egg-2 test-egg-2-file match-chicken-bar))
  106. (test-end "egg")