cpan.scm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. ;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (test-cpan)
  21. #:use-module (guix import cpan)
  22. #:use-module (guix base32)
  23. #:use-module (gcrypt hash)
  24. #:use-module (guix tests http)
  25. #:use-module (guix grafts)
  26. #:use-module (srfi srfi-64)
  27. #:use-module (web client)
  28. #:use-module (ice-9 match))
  29. ;; Globally disable grafts because they can trigger early builds.
  30. (%graft? #f)
  31. (define test-json
  32. "{
  33. \"metadata\" : {
  34. \"name\" : \"Foo-Bar\",
  35. \"version\" : \"0.1\"
  36. }
  37. \"name\" : \"Foo-Bar-0.1\",
  38. \"distribution\" : \"Foo-Bar\",
  39. \"license\" : [
  40. \"perl_5\"
  41. ],
  42. \"dependency\": [
  43. { \"relationship\": \"requires\",
  44. \"phase\": \"runtime\",
  45. \"version\": \"1.05\",
  46. \"module\": \"Test::Script\"
  47. }
  48. ],
  49. \"abstract\" : \"Fizzle Fuzz\",
  50. \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\",
  51. \"author\" : \"Guix\",
  52. \"version\" : \"0.1\"
  53. }")
  54. (define test-source
  55. "foobar")
  56. ;; Avoid collisions with other tests.
  57. (%http-server-port 10400)
  58. (test-begin "cpan")
  59. (test-assert "cpan->guix-package"
  60. ;; Replace network resources with sample data.
  61. (with-http-server `((200 ,test-json)
  62. (200 ,test-source)
  63. (200 "{ \"distribution\" : \"Test-Script\" }"))
  64. (parameterize ((%metacpan-base-url (%local-url))
  65. (current-http-proxy (%local-url)))
  66. (match (cpan->guix-package "Foo::Bar")
  67. (('package
  68. ('name "perl-foo-bar")
  69. ('version "0.1")
  70. ('source ('origin
  71. ('method 'url-fetch)
  72. ('uri ('string-append "http://example.com/Foo-Bar-"
  73. 'version ".tar.gz"))
  74. ('sha256
  75. ('base32
  76. (? string? hash)))))
  77. ('build-system 'perl-build-system)
  78. ('propagated-inputs
  79. ('quasiquote
  80. (("perl-test-script" ('unquote 'perl-test-script)))))
  81. ('home-page "https://metacpan.org/release/Foo-Bar")
  82. ('synopsis "Fizzle Fuzz")
  83. ('description 'fill-in-yourself!)
  84. ('license 'perl-license))
  85. (string=? (bytevector->nix-base32-string
  86. (call-with-input-string test-source port-sha256))
  87. hash))
  88. (x
  89. (pk 'fail x #f))))))
  90. (test-equal "metacpan-url->mirror-url, http"
  91. "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"
  92. (metacpan-url->mirror-url
  93. "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))
  94. (test-equal "metacpan-url->mirror-url, https"
  95. "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"
  96. (metacpan-url->mirror-url
  97. "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))
  98. (test-end "cpan")