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.
 
 
 
 
 
 

104 lines
3.3 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 David Thompson <davet@gnu.org>
  3. ;;; Copyright © 2016 David Craven <david@craven.ch>
  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-crate)
  20. #:use-module (guix import crate)
  21. #:use-module (guix base32)
  22. #:use-module (guix build-system cargo)
  23. #:use-module (gcrypt hash)
  24. #:use-module (guix tests)
  25. #:use-module (ice-9 iconv)
  26. #:use-module (ice-9 match)
  27. #:use-module (srfi srfi-64))
  28. (define test-crate
  29. "{
  30. \"crate\": {
  31. \"max_version\": \"1.0.0\",
  32. \"name\": \"foo\",
  33. \"license\": \"MIT/Apache-2.0\",
  34. \"description\": \"summary\",
  35. \"homepage\": \"http://example.com\",
  36. \"repository\": \"http://example.com\",
  37. }
  38. }")
  39. (define test-dependencies
  40. "{
  41. \"dependencies\": [
  42. {
  43. \"crate_id\": \"bar\",
  44. \"kind\": \"normal\",
  45. }
  46. ]
  47. }")
  48. (define test-source-hash
  49. "")
  50. (test-begin "crate")
  51. (test-equal "guix-package->crate-name"
  52. "rustc-serialize"
  53. (guix-package->crate-name
  54. (dummy-package
  55. "rust-rustc-serialize"
  56. (source (dummy-origin
  57. (uri (crate-uri "rustc-serialize" "1.0")))))))
  58. (test-assert "crate->guix-package"
  59. ;; Replace network resources with sample data.
  60. (mock ((guix http-client) http-fetch
  61. (lambda (url . rest)
  62. (match url
  63. ("https://crates.io/api/v1/crates/foo"
  64. (open-input-string test-crate))
  65. ("https://crates.io/api/v1/crates/foo/1.0.0/download"
  66. (set! test-source-hash
  67. (bytevector->nix-base32-string
  68. (sha256 (string->bytevector "empty file\n" "utf-8"))))
  69. (open-input-string "empty file\n"))
  70. ("https://crates.io/api/v1/crates/foo/1.0.0/dependencies"
  71. (open-input-string test-dependencies))
  72. (_ (error "Unexpected URL: " url)))))
  73. (match (crate->guix-package "foo")
  74. (('package
  75. ('name "rust-foo")
  76. ('version "1.0.0")
  77. ('source ('origin
  78. ('method 'url-fetch)
  79. ('uri ('crate-uri "foo" 'version))
  80. ('file-name ('string-append 'name "-" 'version ".tar.gz"))
  81. ('sha256
  82. ('base32
  83. (? string? hash)))))
  84. ('build-system 'cargo-build-system)
  85. ('inputs
  86. ('quasiquote
  87. (("rust-bar" ('unquote 'rust-bar) "src"))))
  88. ('home-page "http://example.com")
  89. ('synopsis "summary")
  90. ('description "summary")
  91. ('license ('list 'license:expat 'license:asl2.0)))
  92. (string=? test-source-hash hash))
  93. (x
  94. (pk 'fail x #f)))))
  95. (test-end "crate")