Skip to content

Commit

Permalink
Filter out overlapping dirs from classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Jun 15, 2024
1 parent ad881ab commit 1f9c23d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ tests. This means that while you are working on changes you can just run the tes
having to go back and re-eval everything.

This example makes use of [tonsky/clj-reload](https://github.com/tonsky/clj-reload) which ensures that namespaces are
reloaded in the order they depend on each other. You can adapt this example to use whatever reload mechanism you wish.
reloaded in the order they depend on each other.

```lua
require("clojure-test").setup({
Expand All @@ -96,16 +96,11 @@ require("clojure-test").setup({

local client = require("conjure.client")
local fn = require("conjure.eval")["eval-str"]

client["with-filetype"](
"clojure",
fn,
vim.tbl_extend("force", {
origin = "clojure_test.hooks.before_run",
context = "user",
code = [[ ((requiring-resolve 'clj-reload.core/reload)) ]],
}, opts)
)
client["with-filetype"]("clojure", fn, {
origin = "clojure_test.hooks.before_run",
context = "user",
code = [[ ((requiring-resolve 'clj-reload.core/reload)) ]],
})
end
}
})
Expand Down
51 changes: 38 additions & 13 deletions clojure/io/julienvincent/clojure_test/query.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,45 @@

(.startsWith child parent)))

(defn- remove-overlapping-directories
"Remove overlapping paths from a given collection of directories, keeping
the more specific path.
Example:
```clj
(remove-overlapping-directories #{\"/a\" \"/a/b\" \"/c\"})
;; =>
#{\"/a/b\" \"/c\" }
```"
[classpath]
(->> classpath
(sort-by identity (fn [left right]
(compare (count left) (count right))))
(reduce
(fn [paths path]
(let [paths (filter
(fn [existing]
(not (is-parent existing path)))
paths)]
(conj paths path)))
[])))

(defn- get-classpath []
(into #{}
(comp
(filter (fn [path]
(let [file ((requiring-resolve 'clojure.java.io/file) path)]
(and (.exists file)
(.isDirectory file)))))
(map (fn [path]
(->> (File. path)
.getAbsolutePath
str)))
(filter (fn [path]
(is-parent (System/getProperty "user.dir") path))))
(str/split (System/getProperty "java.class.path") #":")))
(remove-overlapping-directories
(into #{}
(comp
(filter (fn [path]
(let [file ((requiring-resolve 'clojure.java.io/file) path)]
(and (.exists file)
(.isDirectory file)))))
(map (fn [path]
(->> (File. path)
.getAbsolutePath
str)))
(filter (fn [path]
(is-parent (System/getProperty "user.dir") path))))
(str/split (System/getProperty "java.class.path") #":"))))

(defn- find-test-files []
(mapcat
Expand Down

0 comments on commit 1f9c23d

Please sign in to comment.