services: openssh: Don't depend on networking.
[guix.git] / tests / cran.scm
blobd785ec5db10be68a751c59fcac6a0ea2acb31d31
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/>.
20 (define-module (test-cran)
21   #:use-module (gnu packages statistics)
22   #:use-module (guix import cran)
23   #:use-module (guix tests)
24   #:use-module (srfi srfi-1)
25   #:use-module (srfi srfi-64)
26   #:use-module (srfi srfi-26)
27   #:use-module (ice-9 match))
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
55 (define description-alist
56   ((@@ (guix import cran) description->alist) description))
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")))
64 (test-begin "cran")
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))))
75 (test-equal "listify: return empty list if key cannot be found"
76   '()
77   ((@@ (guix import cran) listify) simple-alist "Letters"))
79 (test-equal "listify: split comma-separated value into elements"
80   '("R" "Rcpp" "something" "whatever")
81   ((@@ (guix import cran) listify) simple-alist "SimpleList"))
83 (test-equal "listify: strip off parentheses"
84   '("R" "BH" "GenomicRanges")
85   ((@@ (guix import cran) listify) simple-alist "List"))
87 (test-equal "listify: ignore values that are no lists"
88   '()
89   ((@@ (guix import cran) listify) simple-alist "BadList"))
91 (test-equal "r-mininal is not a cran package"
92   #f
93   ((@@ (guix import cran) cran-package?) r-minimal))
95 (test-assert "description->package"
96   ;; Replace network resources with sample data.
97   (mock ((guix build download) url-fetch
98          (lambda* (url file-name
99                        #:key
100                        (mirrors '()) verify-certificate?)
101            (with-output-to-file file-name
102              (lambda ()
103                (display
104                 (match url
105                   ("mirror://cran/src/contrib/My-Example_1.2.3.tar.gz"
106                    "source")
107                   (_ (error "Unexpected URL: " url))))))))
108     (match ((@@ (guix import cran) description->package) 'cran description-alist)
109       (('package
110          ('name "r-my-example")
111          ('version "1.2.3")
112          ('source ('origin
113                     ('method 'url-fetch)
114                     ('uri ('cran-uri "My-Example" 'version))
115                     ('sha256
116                      ('base32
117                       (? string? hash)))))
118          ('properties ('quasiquote (('upstream-name . "My-Example"))))
119          ('build-system 'r-build-system)
120          ('inputs
121           ('quasiquote
122            (("cairo" ('unquote 'cairo)))))
123          ('propagated-inputs
124           ('quasiquote
125            (("r-bh" ('unquote 'r-bh))
126             ("r-proto" ('unquote 'r-proto))
127             ("r-rcpp" ('unquote 'r-rcpp))
128             ("r-scales" ('unquote 'r-scales)))))
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.")
135          ('license 'gpl3+))
136        #t)
137       (x
138        (begin
139          (format #t "~s\n" x)
140          (pk 'fail x #f))))))
142 (test-end "cran")