import: Add 'elpa' importer.
[jackhill/guix/guix.git] / tests / elpa.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
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-elpa)
20 #:use-module (guix import elpa)
21 #:use-module (guix tests)
22 #:use-module (srfi srfi-1)
23 #:use-module (srfi srfi-64)
24 #:use-module (ice-9 match))
25
26 (define elpa-mock-archive
27 '(1
28 (ace-window .
29 [(0 9 0)
30 ((avy
31 (0 2 0)))
32 "Quickly switch windows." single
33 ((:url . "https://github.com/abo-abo/ace-window")
34 (:keywords "window" "location"))])
35 (auctex .
36 [(11 88 6)
37 nil "Integrated environment for *TeX*" tar
38 ((:url . "http://www.gnu.org/software/auctex/"))])))
39
40 (define auctex-readme-mock "This is the AUCTeX description.")
41
42 (define* (elpa-package-info-mock name #:optional (repo "gnu"))
43 "Simulate retrieval of 'archive-contents' file from REPO and extraction of
44 information about package NAME. (Function 'elpa-package-info'.)"
45 (let* ((archive elpa-mock-archive)
46 (info (filter (lambda (p) (eq? (first p) (string->symbol name)))
47 (cdr archive))))
48 (if (pair? info) (first info) #f)))
49
50 (define elpa-version->string
51 (@@ (guix import elpa) elpa-version->string))
52
53 (define package-source-url
54 (@@ (guix import elpa) package-source-url))
55
56 (define nil->empty
57 (@@ (guix import elpa) nil->empty))
58
59 (define package-home-page
60 (@@ (guix import elpa) package-home-page))
61
62 (define make-elpa-package
63 (@@ (guix import elpa) make-elpa-package))
64
65 (test-begin "elpa")
66
67 (define (eval-test-with-elpa pkg)
68 (mock
69 ;; replace the two fetching functions
70 ((guix import elpa) fetch-elpa-package
71 (lambda* (name #:optional (repo "gnu"))
72 (let ((pkg (elpa-package-info-mock name repo)))
73 (match pkg
74 ((name version reqs synopsis kind . rest)
75 (let* ((name (symbol->string name))
76 (ver (elpa-version->string version))
77 (url (package-source-url kind name ver repo)))
78 (make-elpa-package name ver
79 (nil->empty reqs) synopsis kind
80 (package-home-page (first rest))
81 auctex-readme-mock
82 url)))
83 (_ #f)))))
84 (match (elpa->guix-package pkg)
85 (('package
86 ('name "emacs-auctex")
87 ('version "11.88.6")
88 ('source
89 ('origin
90 ('method 'url-fetch)
91 ('uri ('string-append
92 "http://elpa.gnu.org/packages/auctex-" 'version ".tar"))
93 ('sha256 ('base32 (? string? hash)))))
94 ('build-system 'emacs-build-system)
95 ('home-page "http://www.gnu.org/software/auctex/")
96 ('synopsis "Integrated environment for *TeX*")
97 ('description (? string?))
98 ('license 'license:gpl3+))
99 #t)
100 (x
101 (pk 'fail x #f)))))
102
103 (test-assert "elpa->guix-package test 1"
104 (eval-test-with-elpa "auctex"))
105
106 (test-end "elpa")
107
108 \f
109 (exit (= (test-runner-fail-count (test-runner-current)) 0))