|
1 | 1 | (ns org.ajoberstar.jovial.engine |
2 | 2 | (:refer-clojure :exclude [descriptor]) |
3 | | - (:require [clojure.set :as set] |
| 3 | + (:require [clojure.main :as main] |
| 4 | + [clojure.set :as set] |
4 | 5 | [clojure.string :as string]) |
5 | 6 | (:import [org.ajoberstar.jovial ClojureNamespaceDescriptor ClojureVarDescriptor] |
6 | 7 | [org.junit.platform.engine |
7 | | - DiscoverySelector EngineDiscoveryRequest ExecutionRequest |
| 8 | + DiscoverySelector EngineDiscoveryListener EngineDiscoveryRequest ExecutionRequest |
8 | 9 | SelectorResolutionResult TestTag UniqueId UniqueId$Segment] |
9 | 10 | [org.junit.platform.engine.discovery |
10 | | - UniqueIdSelector DirectorySelector FileSelector |
| 11 | + UniqueIdSelector FileSelector |
11 | 12 | ClasspathResourceSelector ClasspathRootSelector ClassSelector] |
12 | 13 | [org.junit.platform.engine.support.descriptor |
13 | 14 | EngineDescriptor ClasspathResourceSource ClassSource FileSource])) |
|
65 | 66 | (let [after (reset! *all-vars* (all-vars)) |
66 | 67 | loaded-vars (set/difference after before)] |
67 | 68 | (map #(->TestCandidate source %) loaded-vars)) |
68 | | - (catch Exception _ |
| 69 | + (catch Exception e |
| 70 | + (println "Failure loading source" source ": " (-> e Throwable->map main/ex-triage main/ex-str)) |
69 | 71 | nil)))) |
70 | 72 |
|
71 | 73 | (defprotocol Selector |
|
83 | 85 | (-select [this] |
84 | 86 | (let [path (str (.getPath this)) |
85 | 87 | source (FileSource/from (.getFile this))] |
| 88 | + (println "File selector path:" path) |
| 89 | + (println "File selector source:" source) |
86 | 90 | (when (or (string/ends-with? path ".clj") |
87 | 91 | (string/ends-with? path ".cljc")) |
| 92 | + (println "Loading file") |
88 | 93 | (select-new-vars source (fn [] (load-file path)))))) |
89 | 94 |
|
90 | 95 | ClasspathResourceSelector |
|
105 | 110 | (when (string/ends-with? name "__init") |
106 | 111 | (select-new-vars source (fn [] (require ns-sym))))))) |
107 | 112 |
|
| 113 | +(defn try-select [^EngineDiscoveryListener listener id selector] |
| 114 | + (println "Evaluating selector:" selector) |
| 115 | + (if (satisfies? Selector selector) |
| 116 | + (try |
| 117 | + (let [result (-select selector)] |
| 118 | + (println "Resolved selector:" selector) |
| 119 | + (.selectorProcessed listener id selector (SelectorResolutionResult/resolved)) |
| 120 | + result) |
| 121 | + (catch Exception e |
| 122 | + (println "Failed selector:" selector) |
| 123 | + (.selectorProcessed listener id selector (SelectorResolutionResult/failed e)))) |
| 124 | + (do |
| 125 | + (println "Unresolved selector:" selector) |
| 126 | + (.selectorProcessed listener id selector (SelectorResolutionResult/unresolved))))) |
| 127 | + |
108 | 128 | (defn select [^EngineDiscoveryRequest request ^UniqueId id] |
109 | 129 | (binding [*all-vars* (atom (all-vars))] |
110 | 130 | (let [listener (.getDiscoveryListener request) |
111 | 131 | selectors (.getSelectorsByType request DiscoverySelector)] |
112 | 132 | (loop [result [] |
113 | 133 | head (first selectors) |
114 | 134 | tail (rest selectors)] |
115 | | - (if (satisfies? Selector head) |
116 | | - (let [candidates (try |
117 | | - (-select head) |
118 | | - (.selectorProcessed listener id head (SelectorResolutionResult/resolved)) |
119 | | - (catch Exception e |
120 | | - (.selectorProcessed listener id head (SelectorResolutionResult/failed e))))] |
121 | | - (if tail |
122 | | - (recur (concat result candidates) (first tail) (rest tail)) |
123 | | - (concat result candidates))) |
124 | | - (.selectorProcessed listener id head (SelectorResolutionResult/unresolved))))))) |
| 135 | + (let [candidates (try-select listener id head)] |
| 136 | + (if tail |
| 137 | + (recur (concat result candidates) (first tail) (rest tail)) |
| 138 | + (concat result candidates))))))) |
125 | 139 |
|
126 | 140 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
127 | 141 | ;; Discovery Descriptor Support |
|
0 commit comments