view 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 source
1 ; Copyright (c) Rich Hickey. All rights reserved.
2 ; The use and distribution terms for this software are covered by the
3 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 ; which can be found in the file epl-v10.html at the root of this distribution.
5 ; By using this software in any fashion, you are agreeing to be bound by
6 ; the terms of this license.
7 ; You must not remove this notice, or any other, from this software.
8 ;
10 ;; clojure.test-clojure
11 ;;
12 ;; Tests for the facilities provided by Clojure
13 ;;
14 ;; scgilardi (gmail)
15 ;; Created 22 October 2008
17 (ns clojure.test-clojure
18 (:require [clojure.test :as t])
19 (:gen-class))
21 (def test-names
22 [:reader
23 :printer
24 :compilation
25 :evaluation
26 :special
27 :macros
28 :metadata
29 :ns-libs
30 :logic
31 :predicates
32 :control
33 :data-structures
34 :numbers
35 :sequences
36 :for
37 :multimethods
38 :other-functions
39 :vars
40 :refs
41 :agents
42 :atoms
43 :parallel
44 :java-interop
45 :test
46 :test-fixtures
47 ;; libraries
48 :clojure-set
49 :clojure-xml
50 :clojure-zip
51 :protocols
52 :genclass
53 :main
54 :vectors
55 :annotations
56 :pprint
57 :serialization
58 :rt
59 :repl
60 :java.io
61 :string
62 :java.javadoc
63 :java.shell
64 :transients
65 :def
66 ])
68 (def test-namespaces
69 (map #(symbol (str "clojure.test-clojure." (name %)))
70 test-names))
72 (defn run
73 "Runs all defined tests"
74 []
75 (println "Loading tests...")
76 (apply require :reload-all test-namespaces)
77 (apply t/run-tests test-namespaces))
79 (defn run-ant
80 "Runs all defined tests, prints report to *err*, throw if failures. This works well for running in an ant java task."
81 []
82 (let [rpt t/report]
83 (binding [;; binding to *err* because, in ant, when the test target
84 ;; runs after compile-clojure, *out* doesn't print anything
85 *out* *err*
86 t/*test-out* *err*
87 t/report (fn report [m]
88 (if (= :summary (:type m))
89 (do (rpt m)
90 (if (or (pos? (:fail m)) (pos? (:error m)))
91 (throw (new Exception (str (:fail m) " failures, " (:error m) " errors.")))))
92 (rpt m)))]
93 (run))))
95 (defn -main
96 "Run all defined tests from the command line"
97 [& args]
98 (run)
99 (System/exit 0))