diff --git a/test/marginalia/test/helpers.clj b/test/marginalia/test/helpers.clj new file mode 100644 index 0000000..a6f5c53 --- /dev/null +++ b/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)))) diff --git a/test/marginalia/test/multidoc.clj b/test/marginalia/test/multidoc.clj index 00be4e9..4362c72 100644 --- a/test/marginalia/test/multidoc.clj +++ b/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))) + 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))) diff --git a/test/marginalia/test/uberdoc.clj b/test/marginalia/test/uberdoc.clj new file mode 100644 index 0000000..5601927 --- /dev/null +++ b/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))) diff --git a/test_projects/single_page/src/first_part.clj b/test_projects/single_page/src/first_part.clj new file mode 100644 index 0000000..693094d --- /dev/null +++ b/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)) diff --git a/test_projects/single_page/src/second_part.clj b/test_projects/single_page/src/second_part.clj new file mode 100644 index 0000000..bc3ab4c --- /dev/null +++ b/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))