Merge from gnulib
[emacs.git] / test / automated / url-future-tests.el
blob66ce7d632f3874a3076f4cff1d37b2927fcd38c8
1 ;;; url-future-tests.el --- Test suite for url-future.
3 ;; Copyright (C) 2011-2015 Free Software Foundation, Inc.
5 ;; Author: Teodor Zlatanov <tzz@lifelogs.com>
6 ;; Keywords: data
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/>.
23 ;;; Code:
25 (require 'ert)
26 (require 'url-future)
28 (ert-deftest url-future-tests ()
29 (let* (saver
30 (text "running future")
31 (good (make-url-future :value (lambda () (format text))
32 :callback (lambda (f) (set 'saver f))))
33 (bad (make-url-future :value (lambda () (/ 1 0))
34 :errorback (lambda (&rest d) (set 'saver d))))
35 (tocancel (make-url-future :value (lambda () (/ 1 0))
36 :callback (lambda (f) (set 'saver f))
37 :errorback (lambda (&rest d)
38 (set 'saver d)))))
39 (should (equal good (url-future-call good)))
40 (should (equal good saver))
41 (should (equal text (url-future-value good)))
42 (should (url-future-completed-p good))
43 (should-error (url-future-call good))
44 (setq saver nil)
45 (should (equal bad (url-future-call bad)))
46 (should-error (url-future-call bad))
47 (should (equal saver (list bad '(arith-error))))
48 (should (url-future-errored-p bad))
49 (setq saver nil)
50 (should (equal (url-future-cancel tocancel) tocancel))
51 (should-error (url-future-call tocancel))
52 (should (null saver))
53 (should (url-future-cancelled-p tocancel))))
55 (provide 'url-future-tests)
57 ;;; url-future-tests.el ends here