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.
 
 
 
 
 
 

119 lines
4.8 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
  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-opam)
  19. #:use-module (guix import opam)
  20. #:use-module (guix base32)
  21. #:use-module (gcrypt hash)
  22. #:use-module (guix tests)
  23. #:use-module ((guix build utils) #:select (delete-file-recursively mkdir-p which))
  24. #:use-module (srfi srfi-64)
  25. #:use-module (web uri)
  26. #:use-module (ice-9 match))
  27. (define test-url-file
  28. "http: \"https://example.org/foo-1.0.0.tar.gz\"
  29. checksum: \"ac8920f39a8100b94820659bc2c20817\"")
  30. (define test-source-hash
  31. "")
  32. (define test-urls
  33. "repo ac8920f39a8100b94820659bc2c20817 0o644
  34. packages/foo/foo.1.0.0/url ac8920f39a8100b94820659bc2c20817 0o644
  35. packages/foo/foo.1.0.0/opam ac8920f39a8100b94820659bc2c20817 0o644
  36. packages/foo/foo.1.0.0/descr ac8920f39a8100b94820659bc2c20817 0o644")
  37. (define test-opam-file
  38. "opam-version: 1.2
  39. maintainer: \"Alice Doe\"
  40. authors: \"Alice Doe, John Doe\"
  41. homepage: \"https://example.org/\"
  42. bug-reports: \"https://example.org/bugs\"
  43. license: \"MIT\"
  44. dev-repo: \"https://example.org/git\"
  45. build: [
  46. \"ocaml\" \"pkg/pkg.ml\" \"build\" \"--pinned\" \"%{pinned}%\"
  47. ]
  48. build-test: [
  49. \"ocaml\" \"pkg/pkg.ml\" \"build\" \"--pinned\" \"%{pinned}%\" \"--tests\" \"true\"
  50. ]
  51. depends: [
  52. \"alcotest\" {test & >= \"0.7.2\"}
  53. \"ocamlbuild\" {build & >= \"0.9.2\"}
  54. ]")
  55. (test-begin "opam")
  56. (test-assert "opam->guix-package"
  57. ;; Replace network resources with sample data.
  58. (mock ((guix import utils) url-fetch
  59. (lambda (url file-name)
  60. (match url
  61. ("https://example.org/foo-1.0.0.tar.gz"
  62. (begin
  63. (mkdir-p "foo-1.0.0")
  64. (system* "tar" "czvf" file-name "foo-1.0.0/")
  65. (delete-file-recursively "foo-1.0.0")
  66. (set! test-source-hash
  67. (call-with-input-file file-name port-sha256))))
  68. (_ (error "Unexpected URL: " url)))))
  69. (mock ((guix http-client) http-fetch/cached
  70. (lambda (url . rest)
  71. (match (uri->string url)
  72. ("https://opam.ocaml.org/urls.txt"
  73. (values (open-input-string test-urls)
  74. (string-length test-urls)))
  75. (_ (error "Unexpected URL: " url)))))
  76. (mock ((guix http-client) http-fetch
  77. (lambda (url . rest)
  78. (match url
  79. ("https://opam.ocaml.org/packages/foo/foo.1.0.0/url"
  80. (values (open-input-string test-url-file)
  81. (string-length test-url-file)))
  82. ("https://opam.ocaml.org/packages/foo/foo.1.0.0/opam"
  83. (values (open-input-string test-opam-file)
  84. (string-length test-opam-file)))
  85. (_ (error "Unexpected URL: " url)))))
  86. (match (opam->guix-package "foo")
  87. (('package
  88. ('name "ocaml-foo")
  89. ('version "1.0.0")
  90. ('source ('origin
  91. ('method 'url-fetch)
  92. ('uri "https://example.org/foo-1.0.0.tar.gz")
  93. ('sha256
  94. ('base32
  95. (? string? hash)))))
  96. ('build-system 'ocaml-build-system)
  97. ('inputs
  98. ('quasiquote
  99. (("ocamlbuild" ('unquote 'ocamlbuild))
  100. ("ocaml-alcotest" ('unquote 'ocaml-alcotest)))))
  101. ('home-page "https://example.org/")
  102. ('synopsis "")
  103. ('description "")
  104. ('license 'license:expat))
  105. (string=? (bytevector->nix-base32-string
  106. test-source-hash)
  107. hash))
  108. (x
  109. (pk 'fail x #f)))))))
  110. (test-end "opam")