-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unittest: Add basic unit test for export
Signed-off-by: Yen-Chin Lee <coldnew.tw@gmail.com>
- Loading branch information
Showing
3 changed files
with
65 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ | |
*.out | ||
*.exe | ||
.#* | ||
.cask | ||
.cask/ | ||
flycheck_* | ||
.sandbox/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |