elpa.scm 3.8 KB

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