build-emacs-utils.scm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2022 Fredrik Salomonsson <plattfot@posteo.net>
  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 build-emacs-utils)
  19. #:use-module (guix tests)
  20. #:use-module (guix build emacs-utils)
  21. #:use-module (guix build utils)
  22. #:use-module ((guix utils)
  23. #:select (call-with-temporary-directory))
  24. #:use-module (ice-9 regex)
  25. #:use-module (srfi srfi-34)
  26. #:use-module (srfi srfi-64))
  27. (test-begin "build-emacs-utils")
  28. ;; Only run the following tests if emacs is present.
  29. (test-skip (if (which "emacs") 0 5))
  30. (test-equal "emacs-batch-script: print foo from emacs"
  31. "foo"
  32. (emacs-batch-script '(princ "foo")))
  33. (test-assert "emacs-batch-script: raise &emacs-batch-error on failure"
  34. (guard (c ((emacs-batch-error? c)
  35. ;; The error message format changed between Emacs 27 and Emacs
  36. ;; 28.
  37. (string-match "[Ww]rong.*argument.*numberp.*\"three\""
  38. (emacs-batch-error-message c))))
  39. (emacs-batch-script '(mapcar 'number-to-string (list 1 2 "three")))))
  40. (call-with-temporary-directory
  41. (lambda (directory)
  42. (let ((mock-elisp-file (string-append directory "/foo.el")))
  43. (call-with-output-file mock-elisp-file
  44. (lambda (port)
  45. (display ";;; foo --- mock emacs package -*- lexical-binding: t -*-
  46. ;; Created: 4 Jun 2022
  47. ;; Keywords: lisp test
  48. ;; Version: 1.0.0
  49. ;;; Commentary:
  50. ;;; Code:
  51. ;;; foo.el ends here
  52. "
  53. port)))
  54. (test-equal "emacs-header-parse: fetch version"
  55. "1.0.0"
  56. (emacs-header-parse "version" mock-elisp-file))
  57. (test-equal "emacs-header-parse: fetch keywords"
  58. "lisp test"
  59. (emacs-header-parse "keywords" mock-elisp-file))
  60. (test-equal "emacs-header-parse: fetch nonexistent author"
  61. "nil"
  62. (emacs-header-parse "author" mock-elisp-file)))))
  63. (test-end "build-emacs-utils")