cpan.scm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, 2023 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 (guix upstream)
  24. #:use-module ((guix download) #:select (url-fetch))
  25. #:use-module (gcrypt hash)
  26. #:use-module (guix tests)
  27. #:use-module (guix tests http)
  28. #:use-module ((guix store) #:select (%graft?))
  29. #:use-module (srfi srfi-64)
  30. #:use-module (web client)
  31. #:use-module (ice-9 match))
  32. ;; Globally disable grafts because they can trigger early builds.
  33. (%graft? #f)
  34. (define test-json
  35. "{
  36. \"metadata\" : {
  37. \"name\" : \"Foo-Bar\",
  38. \"version\" : \"0.1\"
  39. }
  40. \"name\" : \"Foo-Bar-0.1\",
  41. \"distribution\" : \"Foo-Bar\",
  42. \"license\" : [
  43. \"perl_5\"
  44. ],
  45. \"dependency\": [
  46. { \"relationship\": \"requires\",
  47. \"phase\": \"runtime\",
  48. \"version\": \"1.05\",
  49. \"module\": \"Test::Script\"
  50. }
  51. ],
  52. \"abstract\" : \"Fizzle Fuzz\",
  53. \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\",
  54. \"author\" : \"Guix\",
  55. \"version\" : \"0.1\"
  56. }")
  57. (define test-source
  58. "foobar")
  59. ;; Avoid collisions with other tests.
  60. (%http-server-port 10400)
  61. (test-begin "cpan")
  62. (test-assert "cpan->guix-package"
  63. (with-http-server `((200 ,test-json)
  64. (200 ,test-source)
  65. (200 "{ \"distribution\" : \"Test-Script\" }"))
  66. (parameterize ((%metacpan-base-url (%local-url))
  67. (current-http-proxy (%local-url)))
  68. (match (cpan->guix-package "Foo::Bar")
  69. (`(package
  70. (name "perl-foo-bar")
  71. (version "0.1")
  72. (source (origin
  73. (method url-fetch)
  74. (uri (string-append "http://example.com/Foo-Bar-"
  75. version ".tar.gz"))
  76. (sha256
  77. (base32 ,(? string? hash)))))
  78. (build-system perl-build-system)
  79. (propagated-inputs (list perl-test-script))
  80. (home-page "https://metacpan.org/release/Foo-Bar")
  81. (synopsis "Fizzle Fuzz")
  82. (description fill-in-yourself!)
  83. (license perl-license))
  84. (string=? (bytevector->nix-base32-string
  85. (call-with-input-string test-source port-sha256))
  86. hash))
  87. (x
  88. (pk 'fail x #f))))))
  89. (test-equal "package-latest-release"
  90. (list '("http://example.com/Foo-Bar-0.1.tar.gz")
  91. #f
  92. (list (upstream-input
  93. (name "Test-Script")
  94. (downstream-name "perl-test-script")
  95. (type 'propagated))))
  96. (with-http-server `((200 ,test-json)
  97. (200 ,test-source)
  98. (200 "{ \"distribution\" : \"Test-Script\" }"))
  99. (define source
  100. (parameterize ((%metacpan-base-url (%local-url)))
  101. (package-latest-release
  102. (dummy-package "perl-test-script"
  103. (version "0.0.0")
  104. (source (dummy-origin
  105. (method url-fetch)
  106. (uri "mirror://cpan/Foo-Bar-0.0.0.tgz"))))
  107. (list %cpan-updater))))
  108. (list (upstream-source-urls source)
  109. (upstream-source-signature-urls source)
  110. (upstream-source-inputs source))))
  111. (test-equal "metacpan-url->mirror-url, http"
  112. "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"
  113. (metacpan-url->mirror-url
  114. "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))
  115. (test-equal "metacpan-url->mirror-url, https"
  116. "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"
  117. (metacpan-url->mirror-url
  118. "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))
  119. (test-end "cpan")