diff --git a/src/it/test-with-junit/src/test/clojure/ns_binding_test.clj b/src/it/test-with-junit/src/test/clojure/ns_binding_test.clj new file mode 100644 index 0000000..60e3f2f --- /dev/null +++ b/src/it/test-with-junit/src/test/clojure/ns_binding_test.clj @@ -0,0 +1,5 @@ +(ns ns-binding-test + (:require [clojure.test :refer :all])) + +(deftest atest + (is (= 'ns-binding-test (ns-name *ns*)))) diff --git a/src/it/test-with-junit/verify.bsh b/src/it/test-with-junit/verify.bsh index bdd1b96..65270d3 100644 --- a/src/it/test-with-junit/verify.bsh +++ b/src/it/test-with-junit/verify.bsh @@ -1,35 +1,42 @@ import java.io.*; -File file = new File( basedir, "target/test-reports/succeeding.xml" ); -if ( !file.isFile() ) { - throw new FileNotFoundException( "Could not find generated report: " + file ); +void verifyXmlFile(File baseDir, String namespace) throws Exception { + File file = new File(baseDir, "target/test-reports/" + namespace + ".xml"); + if (!file.isFile()) { + throw new FileNotFoundException("Could not find generated report: " + file); + } + Reader r = new BufferedReader(new FileReader(file)); + String line = r.readLine().trim(); + String expected = ""; + if (!expected.equals(line)) { + throw new RuntimeException("line 1 should be " + expected + " but was:" + line); + } + line = r.readLine().trim(); + if (!"".equals(line)) { + throw new RuntimeException("line 2 should be but was:" + line); + } + line = r.readLine().trim(); + if (!("").equals(line)) { + throw new RuntimeException("line 3 should be but was:" + line); + } + line = r.readLine().trim(); + if (!("").equals(line)) { + throw new RuntimeException("line 4 should be but was:" + line); + } + line = r.readLine().trim(); + if (!"".equals(line)) { + throw new RuntimeException("line 5 should be [] but was:" + line); + } + line = r.readLine().trim(); + if (!"".equals(line)) { + throw new RuntimeException("line 6 should be [] but was:" + line); + } + line = r.readLine().trim(); + if (!"".equals(line)) { + throw new RuntimeException("line 7 should be [] but was:" + line); + } + r.close(); } -Reader r = new BufferedReader(new FileReader(file)); -String line = r.readLine().trim(); -if (!"".equals(line)) { - throw new RuntimeException("line 1 should be but was:" + line); -} -line = r.readLine().trim(); -if (!"".equals(line)) { - throw new RuntimeException("line 2 should be but was:" + line); -} -line = r.readLine().trim(); -if (!"".equals(line)) { - throw new RuntimeException("line 3 should be but was:" + line); -} -line = r.readLine().trim(); -if (!"".equals(line)) { - throw new RuntimeException("line 4 should be [] but was:" + line); -} -line = r.readLine().trim(); -if (!"".equals(line)) { - throw new RuntimeException("line 5 should be [] but was:" + line); -} -line = r.readLine().trim(); -if (!"".equals(line)) { - throw new RuntimeException("line 6 should be [] but was:" + line); -} -line = r.readLine().trim(); -if (!"".equals(line)) { - throw new RuntimeException("line 7 should be [] but was:" + line); -} \ No newline at end of file + +verifyXmlFile(basedir, "succeeding"); +verifyXmlFile(basedir, "ns-binding-test"); diff --git a/src/main/resources/default_test_script.clj b/src/main/resources/default_test_script.clj index bf90549..7dbd4c6 100644 --- a/src/main/resources/default_test_script.clj +++ b/src/main/resources/default_test_script.clj @@ -1,8 +1,8 @@ (ns com.theoryinpractise.clojure.testrunner) -(import `java.util.Properties) -(import `java.io.FileInputStream) -(import `java.io.FileWriter) +(import java.util.Properties) +(import java.io.FileInputStream) +(import java.io.FileWriter) (use 'clojure.test) (use 'clojure.test.junit) @@ -48,38 +48,39 @@ (println "There are test failures."))) (when-not *compile-files* - (let [results (atom {})] - (let [report-orig report - junit-report-orig junit-report - out-orig *out* - test-out-orig *test-out*] - (binding [report (fn [x] (report-orig x) - (swap! results (partial merge-with +) - (select-keys (into {} (rest x)) [:pass :test :error :fail]))) - junit-report (fn [x] - (junit-report-orig x) - (binding [*test-out* test-out-orig - *out* out-orig] - (report-orig x)) - (swap! results (partial merge-with +) - (select-keys (into {} (rest x)) [:pass :test :error :fail])))] - (dorun (for [ns namespaces] - (if junit - (if xml-escape - (do - (with-open [writer (FileWriter. (str output-dir "/" ns ".xml")) - escaped (xml-escaping-writer writer)] - (binding [*test-out* writer *out* escaped] - (with-junit-output - (run-tests ns))))) - (do - ;;Use with-test-out to fix with-junit-output for Clojure 1.2 (See http://dev.clojure.org/jira/browse/CLJ-431) - (with-open [writer (FileWriter. (str output-dir "/" ns ".xml"))] - (binding [*test-out* writer] - (with-test-out - (with-junit-output - (run-tests ns))))))) - (run-tests ns)))) - (shutdown-agents) - (print-results @results) - (System/exit (total_errors @results)))))) + (let [results (atom {}) + report-orig report + junit-report-orig junit-report + out-orig *out* + test-out-orig *test-out*] + (binding [report (fn [x] (report-orig x) + (swap! results (partial merge-with +) + (select-keys (into {} (rest x)) [:pass :test :error :fail]))) + junit-report (fn [x] + (junit-report-orig x) + (binding [*test-out* test-out-orig + *out* out-orig] + (report-orig x)) + (swap! results (partial merge-with +) + (select-keys (into {} (rest x)) [:pass :test :error :fail])))] + (dorun (for [ns namespaces] + (if junit + (if xml-escape + (with-open [writer (FileWriter. (str output-dir "/" ns ".xml")) + escaped (xml-escaping-writer writer)] + (binding [*test-out* writer *out* escaped] + (with-junit-output + (binding [*ns* (the-ns ns)] + (run-tests ns))))) + ;;Use with-test-out to fix with-junit-output for Clojure 1.2 (See http://dev.clojure.org/jira/browse/CLJ-431) + (with-open [writer (FileWriter. (str output-dir "/" ns ".xml"))] + (binding [*test-out* writer] + (with-test-out + (with-junit-output + (binding [*ns* (the-ns ns)] + (run-tests ns))))))) + (binding [*ns* (the-ns ns)] + (run-tests ns))))) + (shutdown-agents) + (print-results @results) + (System/exit (total_errors @results)))))