cpan.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org>
  3. ;;; Copyright © 2016 Alex Sassmannshausen <alex@pompo.co>
  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-cpan)
  20. #:use-module (guix import cpan)
  21. #:use-module (guix base32)
  22. #:use-module (gcrypt hash)
  23. #:use-module (guix tests)
  24. #:use-module (guix grafts)
  25. #:use-module (srfi srfi-64)
  26. #:use-module (ice-9 match))
  27. ;; Globally disable grafts because they can trigger early builds.
  28. (%graft? #f)
  29. (define test-json
  30. "{
  31. \"metadata\" : {
  32. \"prereqs\" : {
  33. \"runtime\" : {
  34. \"requires\" : {
  35. \"Test::Script\" : \"1.05\",
  36. }
  37. }
  38. }
  39. \"name\" : \"Foo-Bar\",
  40. \"version\" : \"0.1\"
  41. }
  42. \"name\" : \"Foo-Bar-0.1\",
  43. \"distribution\" : \"Foo-Bar\",
  44. \"license\" : [
  45. \"perl_5\"
  46. ],
  47. \"abstract\" : \"Fizzle Fuzz\",
  48. \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\",
  49. \"author\" : \"Guix\",
  50. \"version\" : \"0.1\"
  51. }")
  52. (define test-source
  53. "foobar")
  54. (test-begin "cpan")
  55. (test-assert "cpan->guix-package"
  56. ;; Replace network resources with sample data.
  57. (mock ((guix build download) url-fetch
  58. (lambda* (url file-name
  59. #:key
  60. (mirrors '()) verify-certificate?)
  61. (with-output-to-file file-name
  62. (lambda ()
  63. (display
  64. (match url
  65. ("http://example.com/Foo-Bar-0.1.tar.gz"
  66. test-source)
  67. (_ (error "Unexpected URL: " url))))))))
  68. (mock ((guix http-client) http-fetch
  69. (lambda (url . rest)
  70. (match url
  71. ("https://fastapi.metacpan.org/v1/release/Foo-Bar"
  72. (values (open-input-string test-json)
  73. (string-length test-json)))
  74. ("https://fastapi.metacpan.org/v1/module/Test::Script?fields=distribution"
  75. (let ((result "{ \"distribution\" : \"Test-Script\" }"))
  76. (values (open-input-string result)
  77. (string-length result))))
  78. (_ (error "Unexpected URL: " url)))))
  79. (match (cpan->guix-package "Foo::Bar")
  80. (('package
  81. ('name "perl-foo-bar")
  82. ('version "0.1")
  83. ('source ('origin
  84. ('method 'url-fetch)
  85. ('uri ('string-append "http://example.com/Foo-Bar-"
  86. 'version ".tar.gz"))
  87. ('sha256
  88. ('base32
  89. (? string? hash)))))
  90. ('build-system 'perl-build-system)
  91. ('propagated-inputs
  92. ('quasiquote
  93. (("perl-test-script" ('unquote 'perl-test-script)))))
  94. ('home-page "https://metacpan.org/release/Foo-Bar")
  95. ('synopsis "Fizzle Fuzz")
  96. ('description 'fill-in-yourself!)
  97. ('license 'perl-license))
  98. (string=? (bytevector->nix-base32-string
  99. (call-with-input-string test-source port-sha256))
  100. hash))
  101. (x
  102. (pk 'fail x #f))))))
  103. (test-equal "source-url-http"
  104. ((@@ (guix import cpan) cpan-source-url)
  105. `(("download_url" .
  106. "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")))
  107. "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")
  108. (test-equal "source-url-https"
  109. ((@@ (guix import cpan) cpan-source-url)
  110. `(("download_url" .
  111. "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")))
  112. "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")
  113. (test-end "cpan")