Skip to content

Commit 15e553d

Browse files
authored
Merge pull request #441 from ivarref/bugfix
Fix beholder watch functionality. Improve docs.
2 parents 49e98ed + 98996ba commit 15e553d

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## Fixed
66

7+
- Fix beholder watch functionality that would cause a NullPointerException earlier.
8+
79
## Changed
810

911
# 1.91.1392 (2024-05-23 / c2d7e1f)

doc/07_watch_mode.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ interface, the provided links describes how they work in detail.
3434

3535
``` clojure
3636
#kaocha/v1
37-
{:kaocha.watch/ignore ["*.tmp"]}
37+
{:kaocha.watch/ignore ["**.tmp"]}
38+
; this will match all files ending in .tmp in the current directory and
39+
; any subdirectory
3840
```
3941

4042
When running in watch mode you can press the Enter (Return) key to manually

src/kaocha/watch.clj

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
[lambdaisland.tools.namespace.track :as ctn-track]
2323
[slingshot.slingshot :refer [try+]]
2424
[nextjournal.beholder :as beholder])
25-
(:import (java.nio.file FileSystems)
25+
(:import (java.io File)
26+
(java.nio.file FileSystems Path PathMatcher)
2627
(java.util.concurrent ArrayBlockingQueue BlockingQueue)))
2728

2829
(defn make-queue []
@@ -93,9 +94,10 @@
9394
for a description of the patterns, these are similar but not the same as
9495
typical shell glob patterns."
9596
[path patterns]
97+
(assert (instance? Path path))
9698
(let [fs (FileSystems/getDefault)
9799
patterns (map #(.getPathMatcher fs (str "glob:" %)) patterns)]
98-
(some #(.matches % path) patterns)))
100+
(some #(.matches ^PathMatcher % path) patterns)))
99101

100102
(defn convert
101103
"Converts a Git-style ignore pattern into the equivalent pattern that Java PathMatcher uses."
@@ -153,7 +155,7 @@
153155
"Finds ignore files in the local directory and the system."
154156
[dir]
155157
(let [absolute-files [(io/file (str (System/getProperty "user.home") "/.config/git/ignore"))]
156-
relative-files (filter #(glob? (.toPath %) ["**.gitignore" "**.ignore"]) (file-seq (io/file dir)))]
158+
relative-files (filter #(glob? (.toPath ^File %) ["**.gitignore" "**.ignore"]) (file-seq (io/file dir)))]
157159
(into absolute-files relative-files)))
158160

159161
(defn merge-ignore-files
@@ -169,7 +171,7 @@
169171
(defn wait-and-rescan! [q tracker watch-paths ignore]
170172
(let [f (qtake q)]
171173
(cond
172-
(and (file? f) (glob? (.toPath f) ignore))
174+
(and (file? f) (glob? (.toPath ^File f) ignore))
173175
(recur q tracker watch-paths ignore)
174176

175177
(directory? f)
@@ -281,7 +283,7 @@ errors as test errors."
281283
(map io/file))
282284
(:kaocha/tests config))
283285
;; Without this, if any path doesn't exist the watching doesn't work.
284-
(filter (fn [x] (.exists ^java.io.File x)))))
286+
(filter (fn [x] (.exists ^File x)))))
285287

286288
(defmulti watch! :type)
287289

@@ -295,8 +297,9 @@ errors as test errors."
295297
(defmethod watch! :beholder [{:keys [q watch-paths]}]
296298
(apply beholder/watch
297299
(fn [{:keys [type path]}]
300+
(assert (instance? Path path))
298301
(when (contains? #{:modify :create} type)
299-
(qput q path)))
302+
(qput q (.toFile ^Path path))))
300303
(map str watch-paths)))
301304

302305
(defn run* [config finish? q]
@@ -307,7 +310,7 @@ errors as test errors."
307310
{})
308311
watch-paths (if (:kaocha.watch/use-ignore-file config)
309312
(set/union (watch-paths config)
310-
(set (map #(.getParentFile (.getCanonicalFile %)) (find-ignore-files "."))))
313+
(set (map #(.getParentFile (.getCanonicalFile ^File %)) (find-ignore-files "."))))
311314
(watch-paths config))
312315
tracker (ctn-track/tracker)
313316
;; if t.n fails due to circular dependencies, do not track-reload.

0 commit comments

Comments
 (0)