Skip to content

Commit 85f64d4

Browse files
author
Jason Duncan
committed
Setting up testing.
1 parent 4c9cfcb commit 85f64d4

File tree

4 files changed

+192
-1
lines changed

4 files changed

+192
-1
lines changed

Cask

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(source melpa)
2+
3+
(package-file "dashboard-project-status.el")
4+
5+
(development
6+
(depends-on "dash")
7+
(depends-on "dashboard")
8+
(depends-on "ert")
9+
(depends-on "ert-runner")
10+
(depends-on "git")
11+
(depends-on "undercover")
12+
(depends-on "ert-expectations")
13+
(depends-on "el-mock"))

Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
PACKAGE = dashboard-project-status
2+
VERSION = $$(grep "^;; Version: " $(PACKAGE).el | cut -f3 -d' ')
3+
ARCHIVE = $(PACKAGE)-$(VERSION).tar
4+
EMACS ?= emacs
5+
CASK ?= cask
6+
LANG=en_US.UTF-8
7+
8+
.PHONY: clean
9+
10+
# pr:
11+
# hub pull-request -b org-trello:master
12+
13+
deps:
14+
${CASK}
15+
16+
build:
17+
${CASK} build
18+
19+
clean-dist:
20+
rm -rf dist/
21+
22+
clean: clean-dist
23+
rm -rf *.tar
24+
${CASK} clean-elc
25+
26+
install:
27+
${CASK} install
28+
29+
test: clean
30+
${CASK} exec ert-runner
31+
32+
pkg-file:
33+
${CASK} pkg-file
34+
35+
pkg-el: pkg-file
36+
${CASK} package
37+
38+
package: clean pkg-el
39+
cp dist/$(ARCHIVE) .
40+
make clean-dist
41+
42+
info:
43+
${CASK} info
44+
45+
# install-package-from-melpa:
46+
# ./install-package-from.sh melpa
47+
48+
# install-file-with-deps-from-melpa: package
49+
# ./install-file-with-deps-from.sh melpa $(VERSION)
50+
51+
# release:
52+
# ./release.sh $(VERSION) $(PACKAGE)
53+
54+
version:
55+
@echo "application $(PACKAGE): $(VERSION)\npackage: $(ARCHIVE)"
56+
57+
install-cask:
58+
curl -fsSkL https://raw.github.com/cask/cask/master/go | python
59+
60+
# emacs-install-clean: package
61+
# ~/bin/emacs/emacs-install-clean.sh ./$(ARCHIVE)
62+
63+
tests:
64+
./run-tests.sh 25.1-travis 25.2-travis 25.3-travis 26.1-travis

test/dashboard-project-status-test.el

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
;;; dashboard-project-status-test.el --- Tests for dashboard-project-status -*- lexical-binding: t; -*-
2+
3+
;; Author: Jason Duncan <[email protected]>
4+
5+
;;; Code:
6+
7+
(require 'cl)
8+
9+
(expectations
10+
(desc "dashboard-project-status without UPDATE value")
11+
(expect (not-called git-run)
12+
(stub dashboard-project-status-insert-heading)
13+
(stub dashboard-project-status-insert-body)
14+
(funcall (dashboard-project-status "foo") nil))
15+
(desc "dashboard-project-status with non-nil UPDATE value")
16+
(expect (mock (git-run "remote" "update") => nil)
17+
(stub dashboard-project-status-insert-heading)
18+
(stub dashboard-project-status-insert-body)
19+
(funcall (dashboard-project-status "foo" t) nil))
20+
(desc "dashboard-project-status inserts a heading")
21+
(expect (mock (dashboard-project-status-insert-heading) => nil)
22+
(stub dashboard-project-status-insert-body)
23+
(funcall (dashboard-project-status "foo") nil))
24+
(desc "dashboard-project-status inserts a body")
25+
(expect (mock (dashboard-project-status-insert-body) => nil)
26+
(stub dashboard-project-status-insert-heading)
27+
(funcall (dashboard-project-status "foo") nil))
28+
(desc "dashboard-project-status-insert-heading when magit is present inserts status text")
29+
;; the blank in the middle is where the widget should go,
30+
;; but I cannot as yet figure out a way to test that
31+
(expect "Project is up-to-date."
32+
(stub dashboard-project-status-git-local-is-behind?)
33+
(stub widget-create)
34+
(with-temp-buffer
35+
(let ((git-repo "foo"))
36+
(mocklet (((functionp 'magit-status) => t))
37+
(dashboard-project-status-insert-heading)))
38+
(buffer-string)))
39+
(desc "dashboard-project-status-insert-heading when magit is not present only inserts text")
40+
(expect "Project foo is up-to-date."
41+
(stub dashboard-project-status-git-local-is-behind?)
42+
(with-temp-buffer
43+
(let ((git-repo "foo"))
44+
(mocklet (((functionp 'magit-status)))
45+
(dashboard-project-status-insert-heading)))
46+
(buffer-string)))
47+
(desc "dashboard-project-status-insert-body inserts nothing when no items")
48+
(expect ""
49+
(stub git-untracked-files)
50+
(stub dashboard-project-status-git-unstaged-files)
51+
(stub git-staged-files)
52+
(with-temp-buffer
53+
(dashboard-project-status-insert-body)
54+
(buffer-string)))
55+
(desc "dashboard-project-status-insert-body inserts untracked files")
56+
(expect (concat "\nUntracked Files:"
57+
"\n "
58+
(abbreviate-file-name
59+
(expand-file-name
60+
(concat (file-name-as-directory "foo") "foo")))
61+
"\n "
62+
(abbreviate-file-name
63+
(expand-file-name
64+
(concat (file-name-as-directory "foo") "bar"))))
65+
(stub git-untracked-files => '("foo" "bar"))
66+
(stub dashboard-project-status-git-unstaged-files)
67+
(stub git-staged-files)
68+
(with-temp-buffer
69+
(let ((git-repo "foo"))
70+
(flet ((widget-create (&rest args)
71+
(insert (car (last args)))))
72+
(dashboard-project-status-insert-body)))
73+
(buffer-string)))
74+
(desc "dashboard-project-status-insert-body inserts unstaged files")
75+
(expect (concat "\nUnstaged Files:"
76+
"\n "
77+
(abbreviate-file-name
78+
(expand-file-name
79+
(concat (file-name-as-directory "foo") "foo")))
80+
"\n "
81+
(abbreviate-file-name
82+
(expand-file-name
83+
(concat (file-name-as-directory "foo") "bar"))))
84+
(stub git-untracked-files)
85+
(stub dashboard-project-status-git-unstaged-files => '("foo" "bar"))
86+
(stub git-staged-files)
87+
(with-temp-buffer
88+
(let ((git-repo "foo"))
89+
(flet ((widget-create (&rest args)
90+
(insert (car (last args)))))
91+
(dashboard-project-status-insert-body)))
92+
(buffer-string)))
93+
(desc "dashboard-project-status-insert-body inserts staged files")
94+
(expect (concat "\nStaged Files:"
95+
"\n "
96+
(abbreviate-file-name
97+
(expand-file-name
98+
(concat (file-name-as-directory "foo") "foo")))
99+
"\n "
100+
(abbreviate-file-name
101+
(expand-file-name
102+
(concat (file-name-as-directory "foo") "bar"))))
103+
(stub git-untracked-files)
104+
(stub dashboard-project-status-git-unstaged-files)
105+
(stub git-staged-files => '("foo" "bar"))
106+
(with-temp-buffer
107+
(let ((git-repo "foo"))
108+
(flet ((widget-create (&rest args)
109+
(insert (car (last args)))))
110+
(dashboard-project-status-insert-body)))
111+
(buffer-string)))
112+
)

test/test-helper.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
(undercover "*.el"
55
(:exclude "*-tests.el")))
66

7-
(require 'format-table)
7+
(require 'el-mock)
8+
(require 'ert-expectations)
9+
(require 'dashboard-project-status)

0 commit comments

Comments
 (0)