Commits

Meikel Brandmeyer committed 88d2b31 Merge

Merge v1.5.8

  • Participants
  • Parent commits ff3c123, 3f78a86

Comments (0)

Files changed (9)

 ab1c08a1b455839a35353e00201e1659bd9cf381 v1.5.2
 9ad5c08355ba5c19e01ba0e5211ffaf8f340f4c5 v1.5.3
 40f259618c828be99e8c67ecd7b90d07bffac43e v1.5.4
+9db547b64ee5e40b5d73fcc5d95be2ac1701ebe9 v1.5.5
+bef1b88980563a2aaa3dee574910069c8ba01922 v1.5.6
+e53fa04c0cf57fcf7fb60e2b763dc0218ef09f6b v1.5.7
+8a20d9be8028a34591510cee58b0c01fdebf988b v1.5.8

File build.gradle

     }
 
     processResources {
+        inputs.property "version", {-> project.version}
         from(sourceSets.main.resources.srcDirs) {
             expand("version": project.version)
         }
 }
 
 project(':clojuresque-runtime') {
+    configurations {
+        clojure
+    }
+
     dependencies {
-        compile 'org.clojure:clojure:[1.2,1.5)'
+        clojure 'org.clojure:clojure:[1.2,1.6)'
+    }
+
+    sourceSets.main {
+        compileClasspath = project.files(
+            compileClasspath,
+            project.configurations.clojure
+        )
     }
 }
 

File clojuresque-runtime/src/main/java/clojuresque/Driver.java

 /*-
- * Copyright 2009,2010 © Meikel Brandmeyer.
+ * Copyright 2009-2013 © Meikel Brandmeyer.
  * All rights reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a copy
 package clojuresque;
 
 import clojure.lang.RT;
-import clojure.lang.Symbol;
+import clojure.lang.Var;
 
 public class Driver {
+    static final Var require = RT.var("clojure.core", "require");
+    static final Var apply   = RT.var("clojure.core", "apply");
+    static final Var symbol  = RT.var("clojure.core", "symbol");
+    static final Var seq     = RT.var("clojure.core", "seq");
+    static final Var next    = RT.var("clojure.core", "next");
+    static final Var sa      = RT.var("clojure.core", "shutdown-agents");
+
     public static void main(String[] args) throws Exception {
+        int exitCode = 1;
         final String command = args[0];
 
         int slash = command.indexOf("/");
         final String namespace = command.substring(0, slash);
         final String function  = command.substring(slash + 1);
 
-        RT.var("clojure.core", "require").invoke(Symbol.create(namespace));
-        RT.var("clojure.core", "apply").invoke(
-                RT.var(namespace, function).deref(),
-                RT.next(RT.seq(args))
-        );
+        try {
+            require.invoke(symbol.invoke(namespace));
+            Boolean result = (Boolean)apply.invoke(
+                    RT.var(namespace, function).deref(),
+                    next.invoke(seq.invoke(args))
+            );
+            if (result)
+                exitCode = 0;
+        } finally {
+            sa.invoke();
+        }
+
+        System.exit(exitCode);
     }
 }

File clojuresque-runtime/src/main/resources/clojuresque/tasks/compile.clj

     (binding [*warn-on-reflection* warn-on-reflection
               *compile-path*       (System/getProperty "clojure.compile.path")]
       (doseq [nspace namespaces]
-        (mode nspace)))))
+        (mode nspace))))
+  true)

File clojuresque-runtime/src/main/resources/clojuresque/tasks/doc.clj

                  :description description
                  :output-dir  destination
                  :sources     sources}]
-    (generate-docs project)))
+    (generate-docs project)
+    true))

File clojuresque-runtime/src/main/resources/clojuresque/tasks/test.clj

 
 (defn check-result
   [result]
-  (when (or (pos? (:fail result)) (pos? (:error result)))
-    (System/exit 1)))
+  (and (zero? (:fail result)) (zero? (:error result))))
 
 (deftask test-namespaces
   "Run all tests in the namespaces of the given files by virtue of clojure.test."

File clojuresque-runtime/src/main/resources/clojuresque/tasks/test_junit.clj

+(ns clojuresque.tasks.test-junit
+  (:use
+    [clojure.test :only (run-tests report successful? *test-out*) :as t]
+    [clojure.test.junit :only (junit-report with-junit-output) :as j]
+    [clojuresque.cli :only (deftask)]
+    [clojuresque.util :only (namespaces)]))
+
+
+(def escape-xml-map
+  (zipmap "'<>\"&" (map #(str \& % \;) '[apos lt gt quot amp])))
+
+(defn- escape-xml [text]
+  (apply str (map #(escape-xml-map % %) text)))
+
+(defn xml-escaping-writer
+  [writer]
+  (proxy
+    [java.io.FilterWriter] [writer]
+    (write [text]
+      (if (string? text)
+        (.write writer (escape-xml text))
+        (.write writer text)))))
+
+
+(defn add-counters [results counters]
+  (merge-with + results counters))
+
+(defn check-result
+  [result]
+  (when (or (pos? (:fail result)) (pos? (:error result)))
+    (System/exit 1)))
+
+(defn escape-file-path 
+  "Escapes the given file path so that it's safe for inclusion in a Clojure string literal."
+  [directory file]
+  (-> (java.io.File. directory file)
+    (.getPath)
+    (.replace "\\" "\\\\")))
+
+(defn test-namespace-with-junit-output
+  "Run all tests in the namespace with junit output.
+   Writes test output to a file called <namespace>.xml in <output-dir>
+   XML escapes *out* so that it's safe for inclusion in the JUnit XML report file." 
+  [namespace output-dir]
+  (with-open [writer (clojure.java.io/writer (str (escape-file-path output-dir (str namespace ".xml"))))
+              escaped (xml-escaping-writer writer)]
+    (binding [*test-out* writer *out* escaped]
+      (with-junit-output
+        (run-tests namespace)))))
+  
+(deftask test-namespaces
+  "Run all tests in the namespaces of the given files by virtue of clojure.test with additional junit output.
+   Writes test output to a file called <namespace>.xml in <output-dir>
+   XML escapes *out* so that it's safe for inclusion in the JUnit XML report file." 
+  [[output-dir o "Directory to wirite JUnit XML result files."]
+   files]
+  (.mkdir (java.io.File. output-dir))
+  (let [namespaces (namespaces files)]
+    (apply require namespaces)
+    (let [results (atom {:type :summary})
+          current-ns (atom nil)
+          failed (atom [])
+          report-orig report
+          junit-report-orig junit-report]
+      ; Change junit-report so that it also prints to System/out and records summaries for each namespace tested 
+      (binding [junit-report (fn [x] 
+                               (junit-report-orig x)
+                               (when (or (= :begin-test-ns (:type x)) (= :summary (:type x)))
+                                 (binding [*test-out* (java.io.OutputStreamWriter. System/out)]
+                                   (report-orig x)))
+                               ; Record results for each namespace for later result checking and reporting
+                               (when (= :begin-test-ns (:type x))
+                                 (reset! current-ns (ns-name (:ns x))))
+                               (when (= :summary (:type x))
+                                 (when (or (pos? (:fail x)) (pos? (:error x)))
+                                   (swap! failed conj [@current-ns x]))
+                                 (swap! results add-counters (dissoc x :type))))]
+        ; test each namespace individually to allow per ns reporting of failures at the end
+        (doseq [namespace namespaces]
+          (test-namespace-with-junit-output namespace output-dir))
+        (if (:test @results)
+          (do
+            (println "\nTotals:")
+            (report @results)
+            (println)
+            (if (successful? @results)
+              (do
+                (println "Success!!!")
+                true)
+              (do
+                (println "\n!!! There were test failures:")
+                ; Print results for each namespace which was unsuccessful
+                (doseq [[ns summary] @failed]
+                  (println ns ": " (:fail summary) "failures," (:error summary) "errors."))
+                (println)
+                false)))
+          true)))))
+

File clojuresque/src/main/groovy/clojuresque/ClojureDocTask.groovy

 /*-
- * Copyright 2011 © Meikel Brandmeyer.
+ * Copyright 2011-2013 © Meikel Brandmeyer.
  * All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
         }
 
         project.clojureexec {
-            this.jvmOptions()
+            project.configure delegate, jvmOptions
             classpath = project.files(
                 this.clojureRoots.srcDirs,
                 this.classpath

File clojuresque/src/main/groovy/clojuresque/ClojureTestTask.groovy

     def FileCollection classpath
     def SourceDirectorySet testRoots
     def Closure jvmOptions = {}
+    def boolean junit = false
+    def String junitOutputDir = "build/test-results" 
     def List<String> tests = []
 
     @InputFiles
                 this.classesDir,
                 this.classpath
             )
-            if (tests.size() == 0) {
-                main = "clojuresque.tasks.test/test-namespaces"
-                args = this.source.files
+            if (junit) {
+                main = "clojuresque.tasks.test-junit/test-namespaces"
+                args = ["-o", junitOutputDir] + this.source.files
             } else {
-                main = "clojuresque.tasks.test/test-vars"
-                args = tests
+                if (tests.size() == 0) {
+                    main = "clojuresque.tasks.test/test-namespaces"
+                    args = this.source.files
+                } else {
+                    main = "clojuresque.tasks.test/test-vars"
+                    args = tests
+                }
             }
         }
     }