cpan.scm 3.8 KB

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