|
3 | 3 | (:require [leiningen.test :as test]
|
4 | 4 | [leiningen.core :as core]
|
5 | 5 | [clojure.java.io :as io]
|
6 |
| - [clojure.pprint :as pprint] |
| 6 | + [clojure.string :as string] |
7 | 7 | [clojure.java.shell :as sh]))
|
8 | 8 |
|
9 | 9 | (defonce project-graph (read-string (slurp (io/resource "project_graph.clj"))))
|
10 | 10 |
|
11 | 11 | (defn show [project entry]
|
12 |
| - (doseq [dependent (:dependents entry)] |
13 |
| - (println "==" dependent ":" (-> dependent |
14 |
| - project-graph |
15 |
| - :github-url)))) |
| 12 | + (doseq [dep-name (:dependents entry) |
| 13 | + :let [dep (project-graph dep-name)]] |
| 14 | + (println "==" (name dep-name)) |
| 15 | + (doseq [k [:description :homepage :github-url] |
| 16 | + :when (not (string/blank? (dep k)))] |
| 17 | + (println " " (dep k))))) |
16 | 18 |
|
17 | 19 | (defn clone [project entry]
|
18 | 20 | (.mkdirs (io/file (:root project) "dependents"))
|
19 | 21 | (doseq [dependent (:dependents entry)
|
20 | 22 | :let [url (:github-url (project-graph dependent))]
|
21 | 23 | :when url]
|
22 | 24 | (println "Cloning" dependent "...")
|
23 |
| - (let [retval (sh/sh "git" "clone" |
24 |
| - (str url ".git") |
| 25 | + (let [retval (sh/sh "git" "clone" (str url ".git") |
25 | 26 | (str "dependents/" (name dependent)))]
|
26 | 27 | (when (pos? (:exit retval))
|
27 |
| - (println "Clone failed:") |
28 |
| - (println (:out retval)) |
29 |
| - (println (:err retval)))))) |
| 28 | + (println "Clone failed:" (:out retval) (:err retval)))))) |
30 | 29 |
|
31 | 30 | (defn has-tests? [project]
|
32 | 31 | (and (not (:eval-in-leiningen project))
|
33 | 32 | (seq (filter #(.endsWith (.getName %) ".clj")
|
34 | 33 | (file-seq (io/file (:test-path project)))))))
|
35 | 34 |
|
| 35 | +;; TODO: detect other testing frameworks |
36 | 36 | (defn test-project [project summary dependent]
|
37 | 37 | (println "Running tests for" dependent)
|
38 | 38 | (let [project (core/read-project
|
|
46 | 46 | (do (println dependent "appears to have no tests.")
|
47 | 47 | summary))))
|
48 | 48 |
|
| 49 | +(defn test-print-summary [results total] |
| 50 | + (println "Test results:") |
| 51 | + (doseq [[dependent passed?] results] |
| 52 | + (println " " dependent " - "(if passed? "pass" "FAIL"))) |
| 53 | + (println (count (filter val results)) "passed out of" total)) |
| 54 | + |
49 | 55 | (defn test [project entry]
|
50 | 56 | (let [dependents (.list (io/file (:root project) "dependents"))
|
51 | 57 | results (reduce (partial test-project project) {} dependents)]
|
52 |
| - (println "Test results:") |
53 |
| - (pprint/pprint results) |
54 |
| - (println (count (filter val results)) "passed out of" (count dependents)))) |
| 58 | + (if (seq dependents) |
| 59 | + (test-print-summary results (count dependents)) |
| 60 | + (println "No dependent clones present; run \"lein melange clone\".")))) |
| 61 | + |
| 62 | +(defn melange |
| 63 | + "Operate on downstream dependents. |
55 | 64 |
|
56 |
| -(defn melange [project command & args] |
| 65 | +Commands: show, clone, test" |
| 66 | + [project command & args] |
57 | 67 | (let [name (-> project :name keyword)
|
58 | 68 | entry (project-graph name)]
|
59 | 69 | (if-let [command-fn (ns-resolve 'leiningen.melange (symbol command))]
|
|
0 commit comments