   {:boot/export-tasks true}
   (:require [boot.core :as core])
   (:import org.junit.runner.JUnitCore
+           (org.junit.internal JUnitSystem
+                               RealSystem)
            (org.reflections Reflections
                             Configuration)
            (org.reflections.scanners Scanner

                                 ConfigurationBuilder
                                 FilterBuilder)))

(defn failure->map [failure]
  {:description (.. failure (getDescription) (toString))
   :exception (.getException failure)
   :message (.getMessage failure)})

(defn result->map [result]

  [p packages PACKAGE #{sym} "The set of Java packages to run tests in."]
  (core/with-pre-wrap fileset
    (if (seq packages)
      (let [^JUnitCore core (JUnitCore.)
            ^JUnitSystem system (RealSystem.)
            result (invoke-private-method core "runMain"
                                          system
                                          (into-array String
                                                      (map (memfn getName)
                                                           (find-all-tests packages))))]
        (when (> (.getFailureCount result) 0)
          #_(throw (ex-info "There were some test failures."
                            (result->map result)))))
      (println "No packages were tested."))
    fileset))
