Skip to content

Commit

Permalink
Added fact.main with main method
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Mar 7, 2009
1 parent 952b858 commit fb72302
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
7 changes: 4 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
<path location="${clojure.jar}"/>
</classpath>
<sysproperty key="clojure.compile.path" value="${build.dir}"/>
<arg value="fact"/>
<arg value="fact.utils.random"/>
<arg value="fact.utils.stub"/>
<arg value="fact.core"/>
<arg value="fact.main"/>
<arg value="fact.random-utils"/>
<arg value="fact.stub"/>
<arg value="fact.output.verbose"/>
</java>
</target>
Expand Down
4 changes: 2 additions & 2 deletions src/fact/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
(let [pairs (partition 2 data-map)
params (map first pairs)
data (map second pairs)]
`(def ~(gensym "fact")
`(def ~(gensym "fact-")
(struct-map fact-info
:doc ~doc
:test (fn [~@params] ~@expr)
Expand Down Expand Up @@ -143,7 +143,7 @@
(defn- get-facts
"Get all the functions beginning with 'fact' from a namespace."
[ns]
(for [[sym var] (ns-publics ns) :when (.startsWith (name sym) "fact")]
(for [[sym var] (ns-publics ns) :when (.startsWith (name sym) "fact-")]
(var-get var)))

(defn verify-facts
Expand Down
42 changes: 42 additions & 0 deletions src/fact/main.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;; Copyright (c) James Reeves. All rights reserved.
;; The use and distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which
;; can be found in the file epl-v10.html at the root of this distribution. By
;; using this software in any fashion, you are agreeing to be bound by the
;; terms of this license. You must not remove this notice, or any other, from
;; this software.

;; fact.main
;;
;; Main method to finds and verify all facts in a directory.

(ns fact.main
(:gen-class)
(:use fact.core)
(:use fact.output.verbose)
(:import java.io.File))

(defn resource-name
"Returns the resource name of the Clojure file, or nil if the file does not
have the .clj extension."
[file]
(second (re-matches #"(.*)\.clj" file)))

(defn namespace-from-path
"Given a path to a resource, return a symbol of the expected namespace."
[file]
(symbol
(.. (resource-name file)
(replace File/separator ".")
(replace "_" "-"))))

(defn -main [& files]
(doseq [file files]
(println file)
(load-file file)
(let [ns (namespace-from-path file)
facts (verify-facts ns)]
(when-not (empty? facts)
(println ns)
(print-results facts)
(println)))))

0 comments on commit fb72302

Please sign in to comment.