all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob aff6ff0eb519d4953c8803264e7e4aef13e74d9d 5224 bytes (raw)
name: test/src/pkg-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
 
;;; pkg-tests.el --- tests for src/pkg.c  -*- lexical-binding:t -*-

;; Copyright (C) 2022 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(require 'ert)
(require 'ert-x)
(require 'cl-lib)

(defmacro with-packages (packages &rest body)
  (declare (indent 1))
  (let (vars shoulds makes deletions)
    (dolist (p packages)
      (let ((name (if (consp p) (cl-first p) p))
            (options (if (consp p) (cl-rest p))))
        (push `(,name nil) vars)
        (push `(should (not (find-package ',name))) shoulds)
        (push `(setq ,name (make-package ',name ,@options)) makes)
        (push `(when (packagep ,name) (delete-package ,name)) deletions)))
    `(let (,@vars)
       ,@(nreverse shoulds)
       (unwind-protect
	   (progn ,@(nreverse makes) ,@body)
	 ,@(nreverse deletions)))))

(ert-deftest pkg-tests-make-package-invalid ()
  (should-error (make-package))
  (should-error (make-package 1.0))
  (should-error (make-package "x" :hansi 1))
  (should-error (make-package "x" :nicknames))
  (should-error (make-package "x" :nicknames 1))
  (should-error (make-package "x" :use))
  (should-error (make-package "x" :use 1)))

(ert-deftest pkg-tests-standard-packages ()
  (should (packagep (find-package "emacs")))
  (should (packagep (find-package "keyword")))
  (should (member "" (package-nicknames (find-package "keyword")))))

(ert-deftest pkg-tests-make-package-nicknames ()
  (with-packages ((x :nicknames '(x z)))
    ;; Package name allowed in nicknames.
    (should (equal (package-nicknames x) '("x" "z"))))
  (with-packages ((x :nicknames '(y y z)))
    ;; Duplicates removed, order-preserving.
    (should (equal (package-nicknames x) '("y" "z")))))

(ert-deftest pkg-tests-package-use-list ()
  (should nil))

(ert-deftest pkg-tests-package-used-by-list ()
  (should nil))

(ert-deftest pkg-tests-package-shadowing-symbols ()
  (should nil))

(ert-deftest pkg-tests-list-all-packages ()
  (with-packages (x y z)
    (let ((all (list-all-packages)))
      (should (member x all))
      (should (member y all))
      (should (member z all)))))

(ert-deftest pkg-tests-package-find-package ()
  (with-packages (x)
    (should-error (find-package 1.0))
    (should (eq (find-package 'x) x))
    (should (eq (find-package "x") x))
    (should (eq (find-package ?x) x))
    (should (not (find-package "X"))))
  (with-packages ((x :nicknames '("y" "z")))
    (should (eq (find-package 'y) (find-package 'x)))
    (should (eq (find-package 'z) (find-package 'x)))))

(ert-deftest pkg-tests-delete-package ()
  (with-packages (x)
    (should (delete-package x))
    (should (null (delete-package x)))
    (should (null (package-name x)))
    (should (not (find-package 'x))))
  (with-packages (x)
    (should (delete-package "x"))
    (should-error (delete-package "x")))
  (let ((original (list-all-packages)))
    (with-packages ((x :nicknames '(y)))
      (should (delete-package x))
      (should (null (delete-package x)))
      (should (not (find-package 'x)))
      (should (not (find-package 'y))))))

(ert-deftest pkg-tests-rename-package ()
  (with-packages (x y)
    (should (eq x (rename-package x 'a '(b))))
    (should (not (find-package 'x)))
    (should (eq (find-package 'a) x))
    (should (eq (find-package 'b) x))
    ;; Can't rename to an existing name or nickname.
    (should-error (rename-package y 'a))
    (should-error (rename-package y 'c :nicknames '("b")))
    ;; Original package name and nicknames are unchanged.
    (should (equal (package-name x) "a"))
    (should (equal (package-nicknames x) '("b")))
    ;; Can't rename deleted package.
    (should (delete-package x))
    (should-error (rename-package x 'd))))

(ert-deftest pkg-tests-find-symbol ()
  (should nil))

(ert-deftest pkg-tests-cl-intern ()
  (cl-assert (not (find-symbol "foo")))
  (unwind-protect
      (progn
        (cl-intern "foo")
        (should (find-symbol "foo")))
    (cl-unintern 'foo)))

(ert-deftest pkg-tests-cl-unintern ()
  (cl-assert (not (find-symbol "foo")))
  (unwind-protect
      (progn
        (cl-intern "foo")
        (cl-unintern 'foo)
        (should-not (find-symbol "foo")))
    (cl-unintern 'foo)))

(ert-deftest pkg-tests-export ()
  (should nil))

(ert-deftest pkg-tests-unexport ()
  (should nil))

(ert-deftest pkg-tests-import ()
  (should nil))

(ert-deftest pkg-tests-shadow ()
  (should nil))

(ert-deftest pkg-tests-shadowing-import ()
  (should nil))

(ert-deftest pkg-tests-shadowing-use-package ()
  (should nil))

(ert-deftest pkg-tests-shadowing-unuse-package ()
  (should nil))

debug log:

solving aff6ff0eb5 ...
found aff6ff0eb5 in https://git.savannah.gnu.org/cgit/emacs.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.