Merge branch 'core-updates'
[jackhill/guix/guix.git] / tests / cran.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (test-cran)
20 #:use-module (guix import cran)
21 #:use-module (guix tests)
22 #:use-module (srfi srfi-1)
23 #:use-module (srfi srfi-64)
24 #:use-module (srfi srfi-26)
25 #:use-module (ice-9 match))
26
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
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
53 (define description-alist
54 ((@@ (guix import cran) description->alist) description))
55
56 (define simple-alist
57 '(("Key" . "Value")
58 ("SimpleList" . "R, Rcpp, something, whatever")
59 ("BadList" . "This is not a real list, you know?")
60 ("List" . "R (>= 2.2), BH (for no reason), GenomicRanges")))
61
62 (test-begin "cran")
63
64 (test-assert "description->alist: contains all valid keys"
65 (let ((keys '("Package" "Type" "Title" "Version" "Date"
66 "Author" "Maintainer" "URL" "Description"
67 "SystemRequirements" "Depends" "License"
68 "Imports" "biocViews" "LinkingTo"
69 "NeedsCompilation" "Repository"
70 "Date/Publication")))
71 (lset= string=? keys (map car description-alist))))
72
73 (test-equal "listify: return empty list if key cannot be found"
74 '()
75 ((@@ (guix import cran) listify) simple-alist "Letters"))
76
77 (test-equal "listify: split comma-separated value into elements"
78 '("R" "Rcpp" "something" "whatever")
79 ((@@ (guix import cran) listify) simple-alist "SimpleList"))
80
81 (test-equal "listify: strip off parentheses"
82 '("R" "BH" "GenomicRanges")
83 ((@@ (guix import cran) listify) simple-alist "List"))
84
85 (test-equal "listify: ignore values that are no lists"
86 '()
87 ((@@ (guix import cran) listify) simple-alist "BadList"))
88
89 (test-assert "description->package"
90 ;; Replace network resources with sample data.
91 (mock ((guix build download) url-fetch
92 (lambda* (url file-name
93 #:key
94 (mirrors '()) verify-certificate?)
95 (with-output-to-file file-name
96 (lambda ()
97 (display
98 (match url
99 ("mirror://cran/src/contrib/My-Example_1.2.3.tar.gz"
100 "source")
101 (_ (error "Unexpected URL: " url))))))))
102 (match ((@@ (guix import cran) description->package) 'cran description-alist)
103 (('package
104 ('name "r-my-example")
105 ('version "1.2.3")
106 ('source ('origin
107 ('method 'url-fetch)
108 ('uri ('cran-uri "My-Example" 'version))
109 ('sha256
110 ('base32
111 (? string? hash)))))
112 ('properties ('quasiquote (('upstream-name . "My-Example"))))
113 ('build-system 'r-build-system)
114 ('inputs
115 ('quasiquote
116 (("cairo" ('unquote 'cairo)))))
117 ('propagated-inputs
118 ('quasiquote
119 (("r-bh" ('unquote 'r-bh))
120 ("r-proto" ('unquote 'r-proto))
121 ("r-rcpp" ('unquote 'r-rcpp))
122 ("r-scales" ('unquote 'r-scales)))))
123 ('home-page "http://gnu.org/s/my-example")
124 ('synopsis "Example package")
125 ('description
126 "This is a long description spanning multiple lines: \
127 and it could confuse the parser that there is a colon : on the \
128 lines. And: this line continues the description.")
129 ('license 'gpl3+)))
130 (x
131 (begin
132 (format #t "~s\n" x)
133 (pk 'fail x #f))))))
134
135 (test-end "cran")