cran.scm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
  3. ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
  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-cran)
  20. #:use-module (gnu packages statistics)
  21. #:use-module (guix import cran)
  22. #:use-module (guix tests)
  23. #:use-module (srfi srfi-1)
  24. #:use-module (srfi srfi-64)
  25. #:use-module (srfi srfi-26)
  26. #:use-module (ice-9 match))
  27. (define description "
  28. Package: My-Example
  29. Type: Package
  30. Title: Example package
  31. Version: 1.2.3
  32. Date: 2015-12-10
  33. Author: Ricardo Wurmus
  34. Maintainer: Guix Schmeeks <guix@gnu.org>
  35. URL: http://gnu.org/s/my-example
  36. Description: This is a long description
  37. spanning multiple lines: and it could confuse the parser that this line is very long or perhaps the fact that
  38. there is a colon : on the lines.
  39. And: this line continues the description.
  40. biocViews: 0
  41. SystemRequirements: Cairo (>= 0)
  42. Depends: A C++11 compiler. Version 4.6.* of g++ (as
  43. currently in Rtools) is insufficient; versions 4.8.*, 4.9.* or
  44. later will be fine.
  45. License: GPL (>= 3)
  46. Imports: Rcpp (>= 0.11.5), proto, Scales
  47. LinkingTo: Rcpp, BH
  48. NeedsCompilation: yes
  49. Repository: CRAN
  50. Date/Publication: 2015-07-14 14:15:16
  51. ")
  52. (define description-alist
  53. (description->alist description))
  54. (define simple-alist
  55. '(("Key" . "Value")
  56. ("SimpleList" . "R, Rcpp, something, whatever")
  57. ("BadList" . "This is not a real list, you know?")
  58. ("List" . "R (>= 2.2), BH (for no reason), GenomicRanges")))
  59. (test-begin "cran")
  60. (test-assert "description->alist: contains all valid keys"
  61. (let ((keys '("Package" "Type" "Title" "Version" "Date"
  62. "Author" "Maintainer" "URL" "Description"
  63. "SystemRequirements" "Depends" "License"
  64. "Imports" "biocViews" "LinkingTo"
  65. "NeedsCompilation" "Repository"
  66. "Date/Publication")))
  67. (lset= string=? keys (map car description-alist))))
  68. (test-equal "listifyx: return empty list if key cannot be found"
  69. '()
  70. ((@@ (guix import cran) listify) simple-alist "Letters"))
  71. (test-equal "listify: split comma-separated value into elements"
  72. '("R" "Rcpp" "something" "whatever")
  73. ((@@ (guix import cran) listify) simple-alist "SimpleList"))
  74. (test-equal "listify: strip off parentheses"
  75. '("R" "BH" "GenomicRanges")
  76. ((@@ (guix import cran) listify) simple-alist "List"))
  77. (test-equal "listify: ignore values that are no lists"
  78. '()
  79. ((@@ (guix import cran) listify) simple-alist "BadList"))
  80. (test-equal "r-mininal is not a cran package"
  81. #f
  82. ((@@ (guix import cran) cran-package?) r-minimal))
  83. (test-assert "description->package"
  84. ;; Replace network resources with sample data.
  85. (mock ((guix build download) url-fetch
  86. (lambda* (url file-name
  87. #:key
  88. (mirrors '()) verify-certificate?)
  89. (with-output-to-file file-name
  90. (lambda ()
  91. (display
  92. (match url
  93. ("mirror://cran/src/contrib/My-Example_1.2.3.tar.gz"
  94. "source")
  95. (_ (error "Unexpected URL: " url))))))))
  96. (match (description->package 'cran description-alist)
  97. (('package
  98. ('name "r-my-example")
  99. ('version "1.2.3")
  100. ('source ('origin
  101. ('method 'url-fetch)
  102. ('uri ('cran-uri "My-Example" 'version))
  103. ('sha256
  104. ('base32
  105. (? string? hash)))))
  106. ('properties ('quasiquote (('upstream-name . "My-Example"))))
  107. ('build-system 'r-build-system)
  108. ('inputs ('list 'cairo))
  109. ('propagated-inputs
  110. ('list 'r-bh 'r-proto 'r-rcpp 'r-scales))
  111. ('home-page "http://gnu.org/s/my-example")
  112. ('synopsis "Example package")
  113. ('description
  114. "\
  115. This is a long description spanning multiple lines: and it could confuse the
  116. parser that this line is very long or perhaps the fact that there is a colon :
  117. on the lines. And: this line continues the description.")
  118. ('license 'gpl3+))
  119. #t)
  120. (x
  121. (begin
  122. (format #t "~s\n" x)
  123. (pk 'fail x #f))))))
  124. (test-end "cran")