Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/it/test-with-junit/src/test/clojure/ns_binding_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns ns-binding-test
(:require [clojure.test :refer :all]))

(deftest atest
(is (= 'ns-binding-test (ns-name *ns*))))
71 changes: 39 additions & 32 deletions src/it/test-with-junit/verify.bsh
Original file line number Diff line number Diff line change
@@ -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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
if (!expected.equals(line)) {
throw new RuntimeException("line 1 should be " + expected + " but was:" + line);
}
line = r.readLine().trim();
if (!"<testsuites>".equals(line)) {
throw new RuntimeException("line 2 should be <testsuites> but was:" + line);
}
line = r.readLine().trim();
if (!("<testsuite name=\"" + namespace + "\">").equals(line)) {
throw new RuntimeException("line 3 should be <testsuite name=\"" + namespace + "\"> but was:" + line);
}
line = r.readLine().trim();
if (!("<testcase name=\"atest\" classname=\"" + namespace + "\">").equals(line)) {
throw new RuntimeException("line 4 should be <testcase name=\"atest\" classname=\"" + namespace + "\"> but was:" + line);
}
line = r.readLine().trim();
if (!"</testcase>".equals(line)) {
throw new RuntimeException("line 5 should be [</testcase>] but was:" + line);
}
line = r.readLine().trim();
if (!"</testsuite>".equals(line)) {
throw new RuntimeException("line 6 should be [</testsuite>] but was:" + line);
}
line = r.readLine().trim();
if (!"</testsuites>".equals(line)) {
throw new RuntimeException("line 7 should be [</testsuites>] but was:" + line);
}
r.close();
}
Reader r = new BufferedReader(new FileReader(file));
String line = r.readLine().trim();
if (!"<?xml version=\"1.0\" encoding=\"UTF-8\"?>".equals(line)) {
throw new RuntimeException("line 1 should be <?xml version=\"1.0\" encoding=\"UTF-8\"?> but was:" + line);
}
line = r.readLine().trim();
if (!"<testsuites>".equals(line)) {
throw new RuntimeException("line 2 should be <testsuites> but was:" + line);
}
line = r.readLine().trim();
if (!"<testsuite name=\"succeeding\">".equals(line)) {
throw new RuntimeException("line 3 should be <testsuite name=\"succeeding\"> but was:" + line);
}
line = r.readLine().trim();
if (!"<testcase name=\"atest\" classname=\"succeeding\">".equals(line)) {
throw new RuntimeException("line 4 should be [<testcase name=\"atest\" classname=\"succeeding\">] but was:" + line);
}
line = r.readLine().trim();
if (!"</testcase>".equals(line)) {
throw new RuntimeException("line 5 should be [</testcase>] but was:" + line);
}
line = r.readLine().trim();
if (!"</testsuite>".equals(line)) {
throw new RuntimeException("line 6 should be [</testsuite>] but was:" + line);
}
line = r.readLine().trim();
if (!"</testsuites>".equals(line)) {
throw new RuntimeException("line 7 should be [</testsuites>] but was:" + line);
}

verifyXmlFile(basedir, "succeeding");
verifyXmlFile(basedir, "ns-binding-test");
77 changes: 39 additions & 38 deletions src/main/resources/default_test_script.clj
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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)))))