-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from connor-kilgore/master
New freshener library, and src files retain save state data.
- Loading branch information
Showing
15 changed files
with
185 additions
and
57 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 |
---|---|---|
@@ -1 +1 @@ | ||
3.4.8 | ||
3.4.9 |
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 @@ | ||
I'm a clojure file |
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 @@ | ||
I'm a clojure common file |
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 @@ | ||
I'm neither |
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 @@ | ||
I'm antiquated |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"puppeteer": "^13.5.1" | ||
"puppeteer": "^22.12.1" | ||
} | ||
} |
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,54 @@ | ||
(ns speclj.freshener-spec | ||
(:require [speclj.core :refer :all] | ||
[speclj.freshener :refer :all] | ||
[clojure.tools.namespace.repl :as repl] | ||
[clojure.tools.namespace.dir :as dir]) | ||
(:use [clojure.java.io :only (file copy make-input-stream delete-file make-parents)])) | ||
|
||
(def sample-dir (.getCanonicalFile (file "examples/sample"))) | ||
|
||
(defn sample-file [dir name] | ||
(file dir name)) | ||
|
||
(defn write-file [dir name content] | ||
(let [file (sample-file dir name)] | ||
(make-parents file) | ||
(copy (make-input-stream (.getBytes content) {}) file) | ||
file)) | ||
|
||
(defn tweak-mod-time [file tweak] | ||
(let [mod-time (+ (.lastModified file) (* 1000 tweak))] | ||
(.setLastModified file mod-time))) | ||
|
||
(describe "Freshener" | ||
|
||
(it "finds specified files by default" | ||
(write-file sample-dir "portable.cljx" "I'm antiquated") | ||
(let [files (find-files-in #".*\.cljx" sample-dir)] | ||
(should-contain "portable.cljx" (set (map #(.getName %) files))))) | ||
|
||
(it "first freshening adds files to listing" | ||
(write-file sample-dir "a.clj" "I'm a clojure file") | ||
(write-file sample-dir "b.cljc" "I'm a clojure common file") | ||
(write-file sample-dir "c.cljx" "I'm neither") | ||
(let [files (clj-files-in sample-dir)] | ||
(should-contain "a.clj" (set (map #(.getName %) files))) | ||
(should-contain "b.cljc" (set (map #(.getName %) files))) | ||
(should-not-contain "c.cljx" (set (map #(.getName %) files))))) | ||
|
||
(context "freshen" | ||
(before | ||
(repl/set-refresh-dirs sample-dir)) | ||
|
||
(it "new files are detected and added to tracker" | ||
(repl/clear) | ||
(freshen) | ||
(should= 2 (count (::dir/files repl/refresh-tracker))) | ||
(should-contain "a.clj" (set (map #(.getName %) (::dir/files repl/refresh-tracker)))) | ||
(should-contain "b.cljc" (set (map #(.getName %) (::dir/files repl/refresh-tracker))))) | ||
|
||
(it "refresh dirs are updated to nil indicating the classpath" | ||
(freshen) | ||
(should= nil repl/refresh-dirs))) | ||
|
||
(repl/clear)) |
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,56 @@ | ||
(ns speclj.freshener | ||
(:require | ||
[clojure.tools.namespace.dir :as dir] | ||
[clojure.tools.namespace.file :as file] | ||
[clojure.tools.namespace.reload :as reload] | ||
[clojure.tools.namespace.repl :as repl] | ||
[clojure.tools.namespace.track :as track] | ||
[speclj.config] | ||
[speclj.reporting]) | ||
(:use | ||
[clojure.java.io :only [file]])) | ||
|
||
(defn find-files-in | ||
"Returns a seq of all files (matching the regex) contained in the given directories." | ||
[pattern & dirs] | ||
(let [dirs (map #(.getCanonicalFile %) dirs) | ||
files (reduce #(into %1 (file-seq (file %2))) [] dirs) | ||
files (remove #(.isHidden %) files) | ||
clj-files (filter #(re-matches pattern (.getName %)) files)] | ||
clj-files)) | ||
|
||
(def clj-file-regex #".*\.clj(c)?") | ||
(defn clj-files-in | ||
"Returns a seq of all clojure source files contained in the given directories." | ||
[& dirs] (apply find-files-in clj-file-regex dirs)) | ||
|
||
(defn remove-value [val coll] | ||
(remove #(= % val) coll)) | ||
|
||
(defn remove-ignore [tracker namespace] | ||
(when-let [file (first (some #(when (= (val %) namespace) %) (::file/filemap tracker)))] | ||
(alter-var-root #'repl/refresh-tracker | ||
(constantly | ||
(assoc tracker | ||
::track/load (remove-value namespace (::track/load tracker)) | ||
::track/unload (remove-value namespace (::track/unload tracker)) | ||
::file/filemap (dissoc (::file/filemap tracker) file) | ||
::dir/files (set (remove-value file (::dir/files tracker)))))))) | ||
|
||
(defn find-key-by-value [m val] | ||
(some (fn [[k v]] (when (= v val) k)) m)) | ||
|
||
(def ignored-namespaces ['speclj.config 'speclj.run.vigilant | ||
'speclj.results 'speclj.core | ||
'speclj.reporting 'speclj.running]) | ||
|
||
(defn freshen [] | ||
(repl/scan) | ||
(doseq [namespace ignored-namespaces] | ||
(remove-ignore repl/refresh-tracker namespace)) | ||
(let [reloaded-files | ||
(for [ns (::track/load repl/refresh-tracker)] | ||
(find-key-by-value (::file/filemap repl/refresh-tracker) ns))] | ||
(alter-var-root #'repl/refresh-tracker reload/track-reload) | ||
(repl/set-refresh-dirs) | ||
reloaded-files)) |
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