url-future-tests.el 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ;;; url-future-tests.el --- Test suite for url-future.
  2. ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
  3. ;; Author: Teodor Zlatanov <tzz@lifelogs.com>
  4. ;; Keywords: data
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Code:
  17. (require 'ert)
  18. (require 'url-future)
  19. (ert-deftest url-future-tests ()
  20. (let* (saver
  21. (text "running future")
  22. (good (make-url-future :value (lambda () (format text))
  23. :callback (lambda (f) (set 'saver f))))
  24. (bad (make-url-future :value (lambda () (/ 1 0))
  25. :errorback (lambda (&rest d) (set 'saver d))))
  26. (tocancel (make-url-future :value (lambda () (/ 1 0))
  27. :callback (lambda (f) (set 'saver f))
  28. :errorback (lambda (&rest d)
  29. (set 'saver d)))))
  30. (should (equal good (url-future-call good)))
  31. (should (equal good saver))
  32. (should (equal text (url-future-value good)))
  33. (should (url-future-completed-p good))
  34. (should-error (url-future-call good))
  35. (setq saver nil)
  36. (should (equal bad (url-future-call bad)))
  37. (should-error (url-future-call bad))
  38. (should (equal saver (list bad '(arith-error))))
  39. (should (url-future-errored-p bad))
  40. (setq saver nil)
  41. (should (equal (url-future-cancel tocancel) tocancel))
  42. (should-error (url-future-call tocancel))
  43. (should (null saver))
  44. (should (url-future-cancelled-p tocancel))))
  45. (provide 'url-future-tests)
  46. ;;; url-future-tests.el ends here