-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of FileInfo in comparisions
- Loading branch information
Showing
4 changed files
with
201 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
(ns clojure.tools.namespace.file-test | ||
(:require [clojure.test :refer [deftest is]] | ||
[clojure.tools.namespace.dependency :as dep] | ||
[clojure.tools.namespace.file :as file] | ||
[clojure.tools.namespace.test-helpers :as help] | ||
[clojure.tools.namespace.track :as track]) | ||
(:import (System.IO FileInfo))) | ||
|
||
;; Tests compliments of Brandon Correa | ||
|
||
(deftest t-add-no-files | ||
(let [tracker (file/add-files (track/tracker) nil)] | ||
(is (= (dep/->MapDependencyGraph {} {}) (::track/deps tracker))) | ||
(is (= {} (::file/filemap tracker))) | ||
(is (= '() (::track/unload tracker))) | ||
(is (= '() (::track/load tracker))))) | ||
|
||
(deftest t-add-one-file | ||
(let [dir (help/create-temp-dir "t-add-one-file") | ||
one-clj (help/create-source dir 'example.one :clj) | ||
tracker (file/add-files (track/tracker) [one-clj])] | ||
(is (= (dep/->MapDependencyGraph {} {}) (::track/deps tracker))) | ||
(is (= {one-clj 'example.one} (::file/filemap tracker))) | ||
(is (= (list 'example.one) (::track/unload tracker))) | ||
(is (= (list 'example.one) (::track/load tracker))))) | ||
|
||
(deftest t-add-file-with-dependency | ||
(let [dir (help/create-temp-dir "t-add-file-with-dependency") | ||
main-clj (help/create-source dir 'example.main :clj '[example.one]) | ||
tracker (file/add-files (track/tracker) [main-clj])] | ||
(is (= {'example.main #{'example.one}} (:dependencies (::track/deps tracker)))) | ||
(is (= {'example.one #{'example.main}} (:dependents (::track/deps tracker)))) | ||
(is (= {main-clj 'example.main} (::file/filemap tracker))) | ||
(is (= (list 'example.main) (::track/unload tracker))) | ||
(is (= (list 'example.main) (::track/load tracker))))) | ||
|
||
(deftest t-add-file-that-already-exists | ||
(let [dir (help/create-temp-dir "t-add-file-that-already-exists") | ||
file-ref-1 (help/create-source dir 'example.main :clj) | ||
file-ref-2 (FileInfo. (.-FullName file-ref-1)) | ||
tracker (-> (track/tracker) | ||
(file/add-files [file-ref-1]) | ||
(file/add-files [file-ref-2]))] | ||
(is (= {} (:dependencies (::track/deps tracker)))) | ||
(is (= {} (:dependents (::track/deps tracker)))) | ||
(is (= {file-ref-2 'example.main} (::file/filemap tracker))) | ||
(is (= (list 'example.main) (::track/unload tracker))) | ||
(is (= (list 'example.main) (::track/load tracker))))) | ||
|
||
(deftest t-add-file-that-already-exists-in-the-same-call | ||
(let [dir (help/create-temp-dir "t-add-file-that-already-exists-in-the-same-call") | ||
file-ref-1 (help/create-source dir 'example.main :clj) | ||
file-ref-2 (FileInfo. (.-FullName file-ref-1)) | ||
tracker (-> (track/tracker) | ||
(file/add-files [file-ref-1 file-ref-2]))] | ||
(is (= {} (:dependencies (::track/deps tracker)))) | ||
(is (= {} (:dependents (::track/deps tracker)))) | ||
(is (= {file-ref-2 'example.main} (::file/filemap tracker))) | ||
(is (= (list 'example.main) (::track/unload tracker))) | ||
(is (= (list 'example.main) (::track/load tracker))))) | ||
|
||
(deftest t-remove-no-files-from-empty-tracker | ||
(let [tracker (file/remove-files {} nil)] | ||
(is (= (dep/->MapDependencyGraph {} {}) (::track/deps tracker))) | ||
(is (nil? (::file/filemap tracker))) | ||
(is (= '() (::track/unload tracker))) | ||
(is (= '() (::track/load tracker))))) | ||
|
||
(deftest t-remove-file-with-dependency-from-filemap | ||
(let [dir (help/create-temp-dir "t-remove-file-with-dependency-from-filemap") | ||
file-ref-1 (help/create-source dir 'example.main :clj '[example.one]) | ||
file-ref-2 (FileInfo. (.-FullName file-ref-1)) | ||
tracker (-> (track/tracker) | ||
(file/add-files [file-ref-1]) | ||
(file/remove-files [file-ref-2]))] | ||
(is (= {} (:dependencies (::track/deps tracker)))) | ||
(is (= {'example.one #{}} (:dependents (::track/deps tracker)))) | ||
(is (= {} (::file/filemap tracker))) | ||
(is (= (list 'example.main) (::track/unload tracker))) | ||
(is (= (list) (::track/load tracker))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
(ns clojure.tools.namespace.repl-test | ||
(:require [clojure.test :refer [deftest is use-fixtures]] | ||
[clojure.tools.namespace.dir :as dir] | ||
[clojure.tools.namespace.find :as find] | ||
[clojure.tools.namespace.repl :as repl] | ||
[clojure.tools.namespace.test-helpers :as help])) | ||
|
||
;; Tests contributed by Brandon Correa | ||
|
||
(defn reset-repl! [] | ||
(repl/clear) | ||
(repl/set-refresh-dirs)) | ||
|
||
(defn reset-repl-fixture [test-fn] | ||
(reset-repl!) | ||
(test-fn) | ||
(reset-repl!)) | ||
|
||
(use-fixtures :each reset-repl-fixture) | ||
|
||
(defn current-time-millis [] | ||
(long | ||
(/ (- (.-Ticks DateTime/UtcNow) | ||
(.-Ticks DateTime/UnixEpoch)) | ||
TimeSpan/TicksPerMillisecond))) | ||
|
||
(deftest t-repl-scan-time-component | ||
(let [before (current-time-millis) | ||
scan (repl/scan {:platform find/clj}) | ||
after (current-time-millis) | ||
time (::dir/time scan)] | ||
(is (<= before time after)) | ||
(is (integer? (::dir/time scan))))) | ||
|
||
(deftest t-repl-scan-twice | ||
(let [dir (help/create-temp-dir "t-repl-scan") | ||
other-dir (help/create-temp-dir "t-repl-scan-other") | ||
main-clj (help/create-source dir 'example.main :clj '[example.one]) | ||
one-cljc (help/create-source dir 'example.one :clj) | ||
_ (repl/set-refresh-dirs dir other-dir) | ||
scan-1 (repl/scan {:platform find/clj}) | ||
scan-2 (repl/scan {:platform find/clj}) | ||
paths-1 (map str (::dir/files scan-1)) | ||
paths-2 (map str (::dir/files scan-2)) | ||
paths (set paths-1)] | ||
(is (= 2 (count paths-1))) | ||
(is (= paths-1 paths-2)) | ||
(is (contains? paths (str main-clj))) | ||
(is (contains? paths (str one-cljc))))) | ||
|
||
(deftest t-repl-scan-after-file-modified | ||
(let [dir (help/create-temp-dir "t-repl-scan-after-file-modified") | ||
main-clj (help/create-source dir 'example.main :clj) | ||
_ (repl/set-refresh-dirs dir) | ||
scan-1 (repl/scan {:platform find/clj}) | ||
_ (System.IO.File/SetLastWriteTimeUtc (.-FullName main-clj) DateTime/UtcNow) | ||
scan-2 (repl/scan {:platform find/clj}) | ||
paths-1 (map str (::dir/files scan-1)) | ||
paths-2 (map str (::dir/files scan-2)) | ||
paths (set paths-1)] | ||
(is (= 1 (count paths-1))) | ||
(is (= paths-1 paths-2)) | ||
(is (contains? paths (str main-clj))))) |