Basic tests for uberdoc!/multidoc!
Introduced `with-project` macro which runs clojure.test assertions against the context of a project defined in `test_projects` folder.
This commit is contained in:
parent
cb7a90ff93
commit
a5f2aeb19f
5 changed files with 69 additions and 30 deletions
40
test/marginalia/test/helpers.clj
Normal file
40
test/marginalia/test/helpers.clj
Normal file
|
@ -0,0 +1,40 @@
|
|||
(ns marginalia.test.helpers
|
||||
(:use clojure.test)
|
||||
(:use [clojure.java.io :only (file)])
|
||||
(:use [clojure.contrib.java-utils :only (delete-file-recursively)]))
|
||||
|
||||
(defn files-in [dir]
|
||||
(seq (.listFiles (file dir))))
|
||||
|
||||
(defmacro with-project
|
||||
"Runs assertions in the context of a project set up for testing in the `test_projects` directory.
|
||||
Provides the following variables to the assertion context:
|
||||
|
||||
* `number-of-generated-pages` - result of running the `doc-generator`
|
||||
function (which should ultimately call one of the marginalias' own
|
||||
functions.
|
||||
|
||||
* `project-name` - the name of the project
|
||||
* `doc-generator` - function which invokes marginalia (actually produces
|
||||
output). Function accepts three arguments: path to source files, path to
|
||||
output files and test project metadata
|
||||
* `tests` - assertions to be run after the output has been produced"
|
||||
[project-name doc-generator & tests]
|
||||
(let [project (file "test_projects" project-name)
|
||||
test-project-src (str (file project "src"))
|
||||
test-project-target (str (file project "docs"))
|
||||
test-metadata {
|
||||
:dependencies [["some/dep" "0.0.1"]]
|
||||
:description "Test project"
|
||||
:name "test"
|
||||
:dev-dependencies []
|
||||
:version "0.0.1"
|
||||
}]
|
||||
|
||||
`(do
|
||||
(delete-file-recursively ~test-project-target true)
|
||||
(.mkdirs (file ~test-project-target))
|
||||
(~doc-generator ~test-project-src ~test-project-target ~test-metadata)
|
||||
(let [~'number-of-generated-pages (count (files-in ~test-project-target))]
|
||||
~@tests)
|
||||
(delete-file-recursively ~test-project-target true))))
|
|
@ -1,37 +1,12 @@
|
|||
(ns marginalia.test.multidoc
|
||||
(:require marginalia.core)
|
||||
(:use clojure.test)
|
||||
(:use [clojure.java.io :only (file)])
|
||||
(:use [clojure.contrib.java-utils :only (delete-file-recursively)]))
|
||||
(:use marginalia.test.helpers))
|
||||
|
||||
(def multi-page-project (file "test_projects" "multi_page"))
|
||||
(def test-project-src (file multi-page-project "src"))
|
||||
(def test-project-target (file multi-page-project "docs"))
|
||||
|
||||
(use-fixtures :each (fn [f]
|
||||
(delete-file-recursively test-project-target true)
|
||||
(.mkdirs test-project-target)
|
||||
(f)))
|
||||
;;(delete-file-recursively test-project-target true)))
|
||||
|
||||
(def test-metadata {
|
||||
:dependencies [["some/dep" "0.0.1"]]
|
||||
:description "Test project"
|
||||
:name "test"
|
||||
:dev-dependencies []
|
||||
:version "0.0.1"
|
||||
})
|
||||
|
||||
(defn run-marginalia [source-dir output-dir]
|
||||
(binding [marginalia.html/*resources* ""]
|
||||
(with-project "multi_page"
|
||||
(fn [source-dir output-dir metadata]
|
||||
(marginalia.core/multidoc! output-dir
|
||||
(marginalia.core/find-clojure-file-paths source-dir)
|
||||
test-metadata)))
|
||||
metadata))
|
||||
|
||||
(defn files-in [dir]
|
||||
(seq (.listFiles (file dir))))
|
||||
|
||||
(deftest test-multi-page-generation
|
||||
(do (run-marginalia test-project-src test-project-target)
|
||||
(is (= (count (files-in test-project-target))
|
||||
(+ (count (files-in test-project-src)) 1))))) ;; Additional index file
|
||||
(is (= number-of-generated-pages 3)))
|
||||
|
|
12
test/marginalia/test/uberdoc.clj
Normal file
12
test/marginalia/test/uberdoc.clj
Normal file
|
@ -0,0 +1,12 @@
|
|||
(ns marginalia.test.uberdoc
|
||||
(:require marginalia.core)
|
||||
(:use marginalia.test.helpers)
|
||||
(:use clojure.test))
|
||||
|
||||
(with-project "single_page"
|
||||
(fn [source-dir output-dir metadata]
|
||||
(marginalia.core/uberdoc! (clojure.java.io/file output-dir "index.html")
|
||||
(marginalia.core/find-clojure-file-paths source-dir)
|
||||
metadata))
|
||||
|
||||
(is (= number-of-generated-pages 1)))
|
6
test_projects/single_page/src/first_part.clj
Normal file
6
test_projects/single_page/src/first_part.clj
Normal file
|
@ -0,0 +1,6 @@
|
|||
;; # The First Part
|
||||
(ns first-part)
|
||||
|
||||
;; This function represents the essence of the essence
|
||||
(defn essence [essence]
|
||||
(+ essence essence))
|
6
test_projects/single_page/src/second_part.clj
Normal file
6
test_projects/single_page/src/second_part.clj
Normal file
|
@ -0,0 +1,6 @@
|
|||
;; # The Second Part
|
||||
(ns second-part)
|
||||
|
||||
;; This function represents the nature of the nature
|
||||
(defn nature [nature]
|
||||
(+ nature nature))
|
Loading…
Reference in a new issue