Skip to content

Commit

Permalink
unittest: Add basic unit test for export
Browse files Browse the repository at this point in the history
Signed-off-by: Yen-Chin Lee <coldnew.tw@gmail.com>
  • Loading branch information
coldnew committed Feb 7, 2015
1 parent 18f3fae commit d01dbe4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
*.out
*.exe
.#*
.cask
.cask/
flycheck_*
.sandbox/
55 changes: 43 additions & 12 deletions test/ox-ioslide-test.el
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@

(ert-deftest test-ois/org-ioslide-export-to-html ()
(ert-deftest ox-ioslide-test/org-ioslide--copy-resource()
"Testing copy resource"
(with-sandbox
(org-ioslide--copy-resource)
(should (f-directory? "theme"))
(should (f-directory? "js"))))

(defmacro ox-ioslide-test/test-export-to-html (file)
"Testing export in the Org mode file."
(require 'ox-ioslide)
(let ((html-file (concat (file-name-sans-extension ox-ioslide-test/example-file)
".html")))
(when (file-exists-p html-file) (delete-file html-file))
;; Export the file to HTML.
(org-export-to-file 'ioslide html-file)
;; should create a .html file
(should (file-exists-p html-file))
;; should not create a file with "::" appended to it's name
(should-not (file-exists-p (concat ox-ioslide-test/example-file "::")))
(when (file-exists-p html-file) (delete-file html-file))))
`(let* ((default-directory (file-name-directory ,file))
(html-file (concat (file-name-sans-extension ,file)
".html"))
(my-file ,file)
(visited-p (get-file-buffer my-file))
to-be-removed)

(when (file-exists-p html-file) (delete-file html-file))

;; Export the file to HTML.
(save-window-excursion
(save-match-data
(find-file my-file)
(setq to-be-removed (current-buffer))
(goto-char (point-min))
(org-ioslide-export-to-html)))
(unless visited-p (kill-buffer to-be-removed))

;; should create a .html file
(should (file-exists-p html-file))
;; should not create a file with "::" appended to it's name
(should-not (file-exists-p (concat ,file "::")))))

(ert-deftest ox-ioslide-test/org-ioslide-export-to-html/example ()
"Testing export example file."
(ox-ioslide-test/test-export-to-html example-file))

(ert-deftest ox-ioslide-test/org-ioslide-export-to-html/sandbox ()
"Testing copy example file to other dir then export."
(let ((sandbox-file (f-expand "index.org" root-sandbox-path)))
(with-sandbox
;; Copy example file to sandbox
(copy-file example-file sandbox-file t)
;; Test export file
(ox-ioslide-test/test-export-to-html sandbox-file))))
29 changes: 20 additions & 9 deletions test/test-helper.el
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
;;; ert-loader.el --- Load Ert if not included in Emacs
;;; test-helper.el --- Load Ert if not included in Emacs

(require 'f)
(require 'ert)

(defvar ox-ioslide-test/test-path
(defvar root-test-path
(f-dirname (f-this-file)))

(defvar ox-ioslide-test/root-path
(f-parent ox-ioslide-test/test-path))
(defvar root-path
(f-parent root-test-path))

(defvar ox-ioslide-test/example-path
(f-expand "example" ox-ioslide-test/root-path))
(defvar root-sandbox-path
(f-expand ".sandbox" root-path))

(defvar ox-ioslide-test/example-file
(f-expand "index.org" ox-ioslide-test/example-path))
(defvar root-example-test
(f-expand "example" root-path))

(defvar example-file
(f-expand "index.org" root-example-test))

;; This project uses ert-runner, which in turn uses ox-ioslide so to make
;; sure not those functions are tested, this code unbinds all ox-ioslide
;; functions.
;; (unload-feature 'ox-ioslide 'force)

(load (f-expand "ox-ioslide" ox-ioslide-test/root-path))
(defmacro with-sandbox (&rest body)
"Evaluate BODY in an empty temporary directory."
`(let ((default-directory root-sandbox-path))
(when (f-dir? root-sandbox-path)
(f-delete root-sandbox-path :force))
(f-mkdir root-sandbox-path)
,@body))

(require 'ox-ioslide (f-expand "ox-ioslide" root-path))

0 comments on commit d01dbe4

Please sign in to comment.