Skip to content

Commit

Permalink
Add Cask and basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
futpib committed May 6, 2017
1 parent 7adac1f commit a0ce552
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ackrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--ignore-dir=.cask/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.elc
*.html
.cask
14 changes: 14 additions & 0 deletions Cask
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(source gnu)
(source melpa)

(package-file "promise.el")

(depends-on "eieio")
(depends-on "cl-lib")

(development
(depends-on "f")
(depends-on "ert")
(depends-on "ert-async")
(depends-on "ert-runner")
(depends-on "ert-expectations"))
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,11 @@ An example using `url-retrieve 'as a more complicated example.
(promise-catch (lambda (reason)
(message "promise-catch: %s" reason))))))
```

Tests
-----

```
$ cask install
$ cask exec ert-runner
```
47 changes: 47 additions & 0 deletions test/emacs-promise-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
;;; -*- lexical-binding: t -*-

(ert-deftest-async
test/promise/errors-in-resolver-are-rejections (done)
(promise-done
(promise-chain
(promise-new (lambda (resolve reject)
(error "wut")))
(then (lambda (result)
(funcall done "Error did not cause promise rejection")))
(promise-catch (lambda (exception)
(should (equal (error-message-string exception) "wut"))
(funcall done)))
(promise-catch 'done))))

(ert-deftest-async
test/promise/errors-in-then-are-rejections (done)
(promise-done
(promise-chain
(promise-new (lambda (resolve reject)
(funcall resolve "yeah")))
(then (lambda (result)
(error "wut")))
(then (lambda (result)
(funcall done "Error did not cause promise rejection")))
(promise-catch (lambda (exception)
(should (equal (error-message-string exception) "wut"))
(funcall done)))
(promise-catch 'done))))

(ert-deftest-async
test/promise/resolver-called-synchronously (done)
(let ((chain-constructor-has-finished nil)
(resolver-was-called nil))
(promise-done
(promise-chain
(promise-new (lambda (resolve reject)
(should (equal chain-constructor-has-finished nil))
(setq resolver-was-called t)
(funcall resolve 'foo)))
(then (lambda (result)
(should (equal result 'foo))
(funcall done)))
(promise-catch (lambda (exception)
(funcall done exception))))
(setq chain-constructor-has-finished t)
(should (equal resolver-was-called t)))))
14 changes: 14 additions & 0 deletions test/test-helper.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
;;; -*- lexical-binding: t -*-

(require 'f)
(require 'ert-async)

(defvar root-test-path
(f-dirname (f-this-file)))

(defvar root-code-path
(f-parent root-test-path))

(add-to-list 'load-path root-code-path)

(require 'promise)

0 comments on commit a0ce552

Please sign in to comment.