Skip to content
Browse files

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.
  • Loading branch information...
1 parent 556b633 commit dfd435a3d4020702a03110ec5dc4fa808ae68d99 @dm3 dm3 committed with fogus
View
40 test/marginalia/test/helpers.clj
@@ -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))))
View
35 test/marginalia/test/multidoc.clj
@@ -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)))
-
-(defn files-in [dir]
- (seq (.listFiles (file dir))))
+ metadata))
-(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)))
View
12 test/marginalia/test/uberdoc.clj
@@ -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)))
View
6 test_projects/single_page/src/first_part.clj
@@ -0,0 +1,6 @@
+;; # The First Part
+(ns first-part)
+
+;; This function represents the essence of the essence
+(defn essence [essence]
+ (+ essence essence))
View
6 test_projects/single_page/src/second_part.clj
@@ -0,0 +1,6 @@
+;; # The Second Part
+(ns second-part)
+
+;; This function represents the nature of the nature
+(defn nature [nature]
+ (+ nature nature))

0 comments on commit dfd435a

Please sign in to comment.
Something went wrong with that request. Please try again.