Merge from mh-e; up to 2012-01-03T19:41:14Z!larsi@gnus.org.
[bpt/emacs.git] / test / automated / url-future-tests.el
CommitLineData
6c0c7cfc
TZ
1;;; url-future-tests.el --- Test suite for url-future.
2
ba318903 3;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
6c0c7cfc
TZ
4
5;; Author: Teodor Zlatanov <tzz@lifelogs.com>
6;; Keywords: data
7
8;; This file is part of GNU Emacs.
9
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.
14
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.
19
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/>.
22
23;;; Code:
24
25(require 'ert)
26(require 'url-future)
27
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))))
54
55(provide 'url-future-tests)
56
57;;; url-future-tests.el ends here