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