Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit bf5963e

Browse files
committed
More cleanup of code
1 parent bcba734 commit bf5963e

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

src/main/clojure/org/ajoberstar/jovial/engine.clj

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
(ns org.ajoberstar.jovial.engine
22
(:refer-clojure :exclude [descriptor])
3-
(:require [clojure.set :as set]
3+
(:require [clojure.main :as main]
4+
[clojure.set :as set]
45
[clojure.string :as string])
56
(:import [org.ajoberstar.jovial ClojureNamespaceDescriptor ClojureVarDescriptor]
67
[org.junit.platform.engine
7-
DiscoverySelector EngineDiscoveryRequest ExecutionRequest
8+
DiscoverySelector EngineDiscoveryListener EngineDiscoveryRequest ExecutionRequest
89
SelectorResolutionResult TestTag UniqueId UniqueId$Segment]
910
[org.junit.platform.engine.discovery
10-
UniqueIdSelector DirectorySelector FileSelector
11+
UniqueIdSelector FileSelector
1112
ClasspathResourceSelector ClasspathRootSelector ClassSelector]
1213
[org.junit.platform.engine.support.descriptor
1314
EngineDescriptor ClasspathResourceSource ClassSource FileSource]))
@@ -65,7 +66,8 @@
6566
(let [after (reset! *all-vars* (all-vars))
6667
loaded-vars (set/difference after before)]
6768
(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))
6971
nil))))
7072

7173
(defprotocol Selector
@@ -83,8 +85,11 @@
8385
(-select [this]
8486
(let [path (str (.getPath this))
8587
source (FileSource/from (.getFile this))]
88+
(println "File selector path:" path)
89+
(println "File selector source:" source)
8690
(when (or (string/ends-with? path ".clj")
8791
(string/ends-with? path ".cljc"))
92+
(println "Loading file")
8893
(select-new-vars source (fn [] (load-file path))))))
8994

9095
ClasspathResourceSelector
@@ -105,23 +110,32 @@
105110
(when (string/ends-with? name "__init")
106111
(select-new-vars source (fn [] (require ns-sym)))))))
107112

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+
108128
(defn select [^EngineDiscoveryRequest request ^UniqueId id]
109129
(binding [*all-vars* (atom (all-vars))]
110130
(let [listener (.getDiscoveryListener request)
111131
selectors (.getSelectorsByType request DiscoverySelector)]
112132
(loop [result []
113133
head (first selectors)
114134
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)))))))
125139

126140
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127141
;; Discovery Descriptor Support

src/main/clojure/org/ajoberstar/jovial/engine/clojure_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
(:import [org.ajoberstar.jovial ClojureTestEngine ClojureNamespaceDescriptor ClojureVarDescriptor]
66
[org.opentest4j AssertionFailedError]
77
[org.junit.platform.engine
8-
ConfigurationParameters EngineDiscoveryRequest EngineExecutionListener ExecutionRequest
9-
TestDescriptor TestExecutionResult UniqueId]))
8+
ConfigurationParameters EngineExecutionListener ExecutionRequest
9+
TestDescriptor TestExecutionResult]))
1010

1111
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1212
;; Execute support

0 commit comments

Comments
 (0)