1 ;;; finalizer-tests.el --- Finalizer tests -*- lexical-binding: t -*-
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
5 ;; Author: Daniel Colascione <dancol@dancol.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
32 (ert-deftest finalizer-basic
()
33 "Test that finalizers run at all."
34 (skip-unless gc-precise
)
35 (let* ((finalized nil
)
36 (finalizer (make-finalizer (lambda () (setf finalized t
)))))
38 (should (equal finalized nil
))
41 (should (equal finalized t
))))
43 (ert-deftest finalizer-circular-reference
()
44 "Test references from a callback to a finalizer."
45 (skip-unless gc-precise
)
46 (let ((finalized nil
))
48 (finalizer (make-finalizer (lambda () (setf finalized value
)))))
49 (setf value finalizer
)
54 (ert-deftest finalizer-cross-reference
()
55 "Test that between-finalizer references do not prevent collection."
56 (skip-unless gc-precise
)
58 (let* ((f1-data (cons nil nil
))
59 (f2-data (cons nil nil
))
61 (lambda () (cl-incf fc
) (setf d f1-data
))))
63 (lambda () (cl-incf fc
) (setf d f2-data
)))))
67 (should (equal fc
2))))
69 (ert-deftest finalizer-error
()
70 "Test that finalizer errors are suppressed"
71 (skip-unless gc-precise
)
72 (make-finalizer (lambda () (error "ABCDEF")))
74 (with-current-buffer "*Messages*"
76 (goto-char (point-max))
79 (buffer-substring (point) (point-at-eol))
80 "finalizer failed: (error \"ABCDEF\")")))))
82 (ert-deftest finalizer-object-type
()
83 (should (equal (type-of (make-finalizer nil
)) 'finalizer
)))