| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 |
|
| 20 | (define-module (test-cran)
|
| 21 | #:use-module (gnu packages statistics)
|
| 22 | #:use-module (guix import cran)
|
| 23 | #:use-module (guix sets)
|
| 24 | #:use-module (guix tests)
|
| 25 | #:use-module (srfi srfi-1)
|
| 26 | #:use-module (srfi srfi-64)
|
| 27 | #:use-module (srfi srfi-26)
|
| 28 | #:use-module (ice-9 match))
|
| 29 |
|
| 30 | (define description "
|
| 31 | Package: My-Example
|
| 32 | Type: Package
|
| 33 | Title: Example package
|
| 34 | Version: 1.2.3
|
| 35 | Date: 2015-12-10
|
| 36 | Author: Ricardo Wurmus
|
| 37 | Maintainer: Guix Schmeeks <[email protected]>
|
| 38 | URL: http://gnu.org/s/my-example
|
| 39 | Description: This is a long description
|
| 40 | spanning multiple lines: and it could confuse the parser that this line is very long or perhaps the fact that
|
| 41 | there is a colon : on the lines.
|
| 42 | And: this line continues the description.
|
| 43 | biocViews: 0
|
| 44 | SystemRequirements: Cairo (>= 0)
|
| 45 | Depends: A C++11 compiler. Version 4.6.* of g++ (as
|
| 46 | currently in Rtools) is insufficient; versions 4.8.*, 4.9.* or
|
| 47 | later will be fine.
|
| 48 | License: GPL (>= 3)
|
| 49 | Imports: Rcpp (>= 0.11.5), proto, Scales
|
| 50 | LinkingTo: Rcpp, BH
|
| 51 | NeedsCompilation: yes
|
| 52 | Repository: CRAN
|
| 53 | Date/Publication: 2015-07-14 14:15:16
|
| 54 | ")
|
| 55 |
|
| 56 | (define description-alist
|
| 57 | (description->alist description))
|
| 58 |
|
| 59 | (define simple-alist
|
| 60 | '(("Key" . "Value")
|
| 61 | ("SimpleList" . "R, Rcpp, something, whatever")
|
| 62 | ("BadList" . "This is not a real list, you know?")
|
| 63 | ("List" . "R (>= 2.2), BH (for no reason), GenomicRanges")))
|
| 64 |
|
| 65 | (test-begin "cran")
|
| 66 |
|
| 67 | (test-assert "description->alist: contains all valid keys"
|
| 68 | (let ((keys '("Package" "Type" "Title" "Version" "Date"
|
| 69 | "Author" "Maintainer" "URL" "Description"
|
| 70 | "SystemRequirements" "Depends" "License"
|
| 71 | "Imports" "biocViews" "LinkingTo"
|
| 72 | "NeedsCompilation" "Repository"
|
| 73 | "Date/Publication")))
|
| 74 | (lset= string=? keys (map car description-alist))))
|
| 75 |
|
| 76 | (test-equal "listifyx: return empty list if key cannot be found"
|
| 77 | '()
|
| 78 | ((@@ (guix import cran) listify) simple-alist "Letters"))
|
| 79 |
|
| 80 | (test-equal "listify: split comma-separated value into elements"
|
| 81 | '("R" "Rcpp" "something" "whatever")
|
| 82 | ((@@ (guix import cran) listify) simple-alist "SimpleList"))
|
| 83 |
|
| 84 | (test-equal "listify: strip off parentheses"
|
| 85 | '("R" "BH" "GenomicRanges")
|
| 86 | ((@@ (guix import cran) listify) simple-alist "List"))
|
| 87 |
|
| 88 | (test-equal "listify: ignore values that are no lists"
|
| 89 | '()
|
| 90 | ((@@ (guix import cran) listify) simple-alist "BadList"))
|
| 91 |
|
| 92 | (test-equal "extract-imports: finds data.table"
|
| 93 | (list "data.table")
|
| 94 | (set->list ((@ (guix import cran) extract-imports) "abc + data.table::some_procedure()")))
|
| 95 |
|
| 96 | (test-equal "extract-imports: ignores text inside strings"
|
| 97 | (list)
|
| 98 | (set->list ((@ (guix import cran) extract-imports)
|
| 99 | "\"hello::world\", \"this is not data.table::some_procedure(), actually\"")))
|
| 100 |
|
| 101 | (test-equal "extract-imports: extracts text inside single quotes"
|
| 102 | (list "FDb.InfiniumMethylation.hg19")
|
| 103 | (set->list ((@ (guix import cran) extract-imports)
|
| 104 | "suppressPackageStartupMessages(require('FDb.InfiniumMethylation.hg19'))")))
|
| 105 |
|
| 106 | (test-equal "extract-imports: ignores other colon separated things"
|
| 107 | (list)
|
| 108 | (set->list ((@ (guix import cran) extract-imports)
|
| 109 | "this:is:not::a:procedure")))
|
| 110 |
|
| 111 | (test-equal "extract-imports: matches things before a comma"
|
| 112 | (list "MASS")
|
| 113 | (set->list ((@ (guix import cran) extract-imports)
|
| 114 | "check_installed(\"MASS\",")))
|
| 115 |
|
| 116 | (test-equal "r-minimal is not a cran package"
|
| 117 | #f
|
| 118 | ((@@ (guix import cran) cran-package?) r-minimal))
|
| 119 |
|
| 120 | (test-assert "description->package"
|
| 121 | |
| 122 | (mock ((guix build download) url-fetch
|
| 123 | (lambda* (url file-name
|
| 124 | #:key
|
| 125 | (mirrors '()) verify-certificate?)
|
| 126 | (with-output-to-file file-name
|
| 127 | (lambda ()
|
| 128 | (display
|
| 129 | (match url
|
| 130 | ("mirror://cran/src/contrib/My-Example_1.2.3.tar.gz"
|
| 131 | "source")
|
| 132 | (_ (error "Unexpected URL: " url))))))))
|
| 133 | (match (description->package 'cran description-alist)
|
| 134 | (('package
|
| 135 | ('name "r-my-example")
|
| 136 | ('version "1.2.3")
|
| 137 | ('source ('origin
|
| 138 | ('method 'url-fetch)
|
| 139 | ('uri ('cran-uri "My-Example" 'version))
|
| 140 | ('sha256
|
| 141 | ('base32
|
| 142 | (? string? hash)))))
|
| 143 | ('properties ('quasiquote (('upstream-name . "My-Example"))))
|
| 144 | ('build-system 'r-build-system)
|
| 145 | ('inputs ('list 'cairo))
|
| 146 | ('propagated-inputs
|
| 147 | ('list 'r-bh 'r-proto 'r-rcpp 'r-scales))
|
| 148 | ('home-page "http://gnu.org/s/my-example")
|
| 149 | ('synopsis "Example package")
|
| 150 | ('description
|
| 151 | "\
|
| 152 | This is a long description spanning multiple lines: and it could confuse the
|
| 153 | parser that this line is very long or perhaps the fact that there is a colon :
|
| 154 | on the lines. And: this line continues the description.")
|
| 155 | ('license 'gpl3+))
|
| 156 | #t)
|
| 157 | (x
|
| 158 | (begin
|
| 159 | (format #t "~s\n" x)
|
| 160 | (pk 'fail x #f))))))
|
| 161 |
|
| 162 | (test-end "cran")
|