diff src/clojure/test_clojure.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/test_clojure.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,99 @@
     1.4 +;   Copyright (c) Rich Hickey. All rights reserved.
     1.5 +;   The use and distribution terms for this software are covered by the
     1.6 +;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
     1.7 +;   which can be found in the file epl-v10.html at the root of this distribution.
     1.8 +;   By using this software in any fashion, you are agreeing to be bound by
     1.9 +;   the terms of this license.
    1.10 +;   You must not remove this notice, or any other, from this software.
    1.11 +;
    1.12 +
    1.13 +;;  clojure.test-clojure
    1.14 +;;
    1.15 +;;  Tests for the facilities provided by Clojure
    1.16 +;;
    1.17 +;;  scgilardi (gmail)
    1.18 +;;  Created 22 October 2008
    1.19 +
    1.20 +(ns clojure.test-clojure
    1.21 +  (:require [clojure.test :as t])
    1.22 +  (:gen-class))
    1.23 +
    1.24 +(def test-names
    1.25 +     [:reader
    1.26 +      :printer
    1.27 +      :compilation
    1.28 +      :evaluation
    1.29 +      :special
    1.30 +      :macros
    1.31 +      :metadata
    1.32 +      :ns-libs
    1.33 +      :logic
    1.34 +      :predicates
    1.35 +      :control
    1.36 +      :data-structures
    1.37 +      :numbers
    1.38 +      :sequences
    1.39 +      :for
    1.40 +      :multimethods
    1.41 +      :other-functions
    1.42 +      :vars
    1.43 +      :refs
    1.44 +      :agents
    1.45 +      :atoms
    1.46 +      :parallel
    1.47 +      :java-interop
    1.48 +      :test
    1.49 +      :test-fixtures
    1.50 +      ;; libraries
    1.51 +      :clojure-set
    1.52 +      :clojure-xml
    1.53 +      :clojure-zip
    1.54 +      :protocols
    1.55 +      :genclass
    1.56 +      :main
    1.57 +      :vectors
    1.58 +      :annotations
    1.59 +      :pprint
    1.60 +      :serialization
    1.61 +      :rt
    1.62 +      :repl
    1.63 +      :java.io
    1.64 +      :string
    1.65 +      :java.javadoc
    1.66 +      :java.shell
    1.67 +      :transients
    1.68 +      :def
    1.69 +      ])
    1.70 +
    1.71 +(def test-namespaces
    1.72 +     (map #(symbol (str "clojure.test-clojure." (name %)))
    1.73 +          test-names))
    1.74 +
    1.75 +(defn run
    1.76 +  "Runs all defined tests"
    1.77 +  []
    1.78 +  (println "Loading tests...")
    1.79 +  (apply require :reload-all test-namespaces)
    1.80 +  (apply t/run-tests test-namespaces))
    1.81 +
    1.82 +(defn run-ant
    1.83 +  "Runs all defined tests, prints report to *err*, throw if failures. This works well for running in an ant java task."
    1.84 +  []
    1.85 +  (let [rpt t/report]
    1.86 +    (binding [;; binding to *err* because, in ant, when the test target
    1.87 +              ;; runs after compile-clojure, *out* doesn't print anything
    1.88 +              *out* *err*
    1.89 +              t/*test-out* *err*
    1.90 +              t/report (fn report [m]
    1.91 +                         (if (= :summary (:type m))
    1.92 +                           (do (rpt m)
    1.93 +                               (if (or (pos? (:fail m)) (pos? (:error m)))
    1.94 +                                 (throw (new Exception (str (:fail m) " failures, " (:error m) " errors.")))))
    1.95 +                           (rpt m)))]
    1.96 +      (run))))
    1.97 +
    1.98 +(defn -main
    1.99 +  "Run all defined tests from the command line"
   1.100 +  [& args]
   1.101 +  (run)
   1.102 +  (System/exit 0))