Skip to content

Commit f3bea29

Browse files
authored
Merge pull request #3 from brandoncorrea/fix-scan-dirs
Update scan-dirs to no longer throw
2 parents c9a91cc + 54bfc9e commit f3bea29

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ jobs:
1414
run: |
1515
dotnet tool install --global Clojure.Main --version 1.12.0-alpha10
1616
dotnet tool install --global Clojure.Cljr --version 0.1.0-alpha5
17+
1718
- name: Run cljr tests
18-
run: cljr -X:test
19+
run: cljr -X:test
20+

src/main/clojure/clojure/tools/namespace/dir.clj

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@
2929
(mapcat #(find/find-sources-in-dir % platform))
3030
)) ;;; ditto: (map #(.getCanonicalFile ^File %))
3131

32-
(defn- milliseconds-since-epoch [^DateTime time]
33-
(long
34-
(/ (- (.-Ticks time)
35-
(.-Ticks DateTime/UnixEpoch))
36-
TimeSpan/TicksPerMillisecond)))
32+
(defn- modified-since-tracked? [tracker file]
33+
(if-let [time (::time tracker)]
34+
(DateTime/op_LessThan time (.LastWriteTimeUtc ^FileSystemInfo file))
35+
true))
3736

3837
(defn- modified-files [tracker files]
39-
(filter #(< (::time tracker 0) (milliseconds-since-epoch (.-LastWriteTimeUtc ^FileSystemInfo %))) files)) ;;; #(< (::time tracker 0) (.lastModified ^File %))
38+
(filter (partial modified-since-tracked? tracker) files)) ;;; (.lastModified ^File %)
4039

4140
(defn- deleted-files [tracker files]
4241
(set (remove #(file/some-file files %) (::files tracker #{})))) ;;; (set/difference (::files tracker #{}) (set files))
@@ -138,6 +137,3 @@
138137
(instance? DirectoryInfo x) x
139138
(string? x) (DirectoryInfo. ^String x)
140139
:default (DirectoryInfo. (str x))))
141-
142-
143-

src/test/clojure/clojure/tools/namespace/dir_test.clj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
[clojure.tools.namespace.dir :as dir])
55
#_(:import
66
(java.io File)))
7+
8+
(defmacro is-not-thrown? [& body]
9+
`(try
10+
~@body
11+
(is true "No exception thrown")
12+
(catch Exception e#
13+
(is false (str "Expected no exception, but got: " (.GetType e#) ": " (.-Message e#))))))
14+
15+
(deftest scan-dirs-does-not-throw
16+
(is-not-thrown? (dir/scan-dirs {})))
17+
718
;;; I don't know what the equivalent test would be for .Net.
819
#_(defn- make-symbolic-link
920
"Reflectively calls java.nio.file.Files/createSymbolicLink on two
@@ -35,4 +46,4 @@
3546
link (File. other-dir "link")]
3647
(make-symbolic-link link dir)
3748
(is (= (::dir/files (dir/scan-dirs {} [dir]))
38-
(::dir/files (dir/scan-dirs {} [link])))))))
49+
(::dir/files (dir/scan-dirs {} [link])))))))

0 commit comments

Comments
 (0)