hash: Close or flush sha256 output ports before calling their 'get' procedure.
[jackhill/guix/guix.git] / tests / cran.scm
CommitLineData
e1248602
RW
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)
0f6b9e98 22 #:use-module (srfi srfi-1)
e1248602 23 #:use-module (srfi srfi-64)
0f6b9e98 24 #:use-module (srfi srfi-26)
e1248602
RW
25 #:use-module (ice-9 match))
26
0f6b9e98
RW
27(define description "
28Package: My-Example
29Type: Package
30Title: Example package
31Version: 1.2.3
32Date: 2015-12-10
33Author: Ricardo Wurmus
34Maintainer: Guix Schmeeks <guix@gnu.org>
35URL: http://gnu.org/s/my-example
36Description: This is a long description
37spanning multiple lines: and it could confuse the parser that
38there is a colon : on the lines.
39 And: this line continues the description.
40biocViews: 0
41SystemRequirements: Cairo (>= 0)
42Depends: 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.
45License: GPL (>= 3)
46Imports: Rcpp (>= 0.11.5), proto, Scales
47LinkingTo: Rcpp, BH
48NeedsCompilation: yes
49Repository: CRAN
50Date/Publication: 2015-07-14 14:15:16
51")
e1248602 52
0f6b9e98
RW
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")))
e1248602
RW
61
62(test-begin "cran")
63
0f6b9e98
RW
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))))
e1248602 72
0f6b9e98 73(test-equal "listify: return empty list if key cannot be found"
e1248602 74 '()
0f6b9e98
RW
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"))
e1248602 80
0f6b9e98
RW
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"
e1248602 86 '()
0f6b9e98
RW
87 ((@@ (guix import cran) listify) simple-alist "BadList"))
88
0f6b9e98 89(test-assert "description->package"
e1248602
RW
90 ;; Replace network resources with sample data.
91 (mock ((guix build download) url-fetch
324a2ba5
LC
92 (lambda* (url file-name
93 #:key
94 (mirrors '()) verify-certificate?)
e1248602
RW
95 (with-output-to-file file-name
96 (lambda ()
97 (display
98 (match url
0f6b9e98 99 ("mirror://cran/src/contrib/My-Example_1.2.3.tar.gz"
e1248602
RW
100 "source")
101 (_ (error "Unexpected URL: " url))))))))
d0bd632f 102 (match ((@@ (guix import cran) description->package) 'cran description-alist)
e1248602 103 (('package
0f6b9e98 104 ('name "r-my-example")
e1248602
RW
105 ('version "1.2.3")
106 ('source ('origin
107 ('method 'url-fetch)
0f6b9e98 108 ('uri ('cran-uri "My-Example" 'version))
e1248602
RW
109 ('sha256
110 ('base32
111 (? string? hash)))))
0f6b9e98 112 ('properties ('quasiquote (('upstream-name . "My-Example"))))
e1248602
RW
113 ('build-system 'r-build-system)
114 ('inputs
115 ('quasiquote
116 (("cairo" ('unquote 'cairo)))))
117 ('propagated-inputs
118 ('quasiquote
0f6b9e98
RW
119 (("r-bh" ('unquote 'r-bh))
120 ("r-proto" ('unquote 'r-proto))
e1248602
RW
121 ("r-rcpp" ('unquote 'r-rcpp))
122 ("r-scales" ('unquote 'r-scales)))))
0f6b9e98
RW
123 ('home-page "http://gnu.org/s/my-example")
124 ('synopsis "Example package")
125 ('description
126 "This is a long description spanning multiple lines: \
127and it could confuse the parser that there is a colon : on the \
128lines. And: this line continues the description.")
129 ('license 'gpl3+)))
e1248602
RW
130 (x
131 (begin
132 (format #t "~s\n" x)
133 (pk 'fail x #f))))))
134
135(test-end "cran")