From 35897bc8e89be2b6b71ce8de016ef2436bcdc71a Mon Sep 17 00:00:00 2001 From: guns Date: Fri, 28 Mar 2014 15:33:32 -0500 Subject: [PATCH] Call (shutdown-agents) in slam.hound/-main Now that swap-in-reconstructed-ns-form can be passed a simple string, we can reserve -main for command line use only. Closes #75 --- README.md | 2 +- src/slam/hound.clj | 9 +++++++-- test/slam/hound_test.clj | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a5e1e2..4b12d2e 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ You can reconstruct namespaces from a repl to avoid the slow startup time: Or to reconstruct files in place: - user=> (slam.hound/-main "src/my/namespace.clj") + user=> (slam.hound/swap-in-reconstructed-ns-form "src/my/namespace.clj") nil ;; Reload the file in your editor to pick up changes diff --git a/src/slam/hound.clj b/src/slam/hound.clj index f2f1a91..fb7a8c7 100644 --- a/src/slam/hound.clj +++ b/src/slam/hound.clj @@ -64,8 +64,11 @@ (finally (.delete tmp-file))))) +(def ^:private ^:dynamic *testing?* false) + (defn -main - "Takes a file or dir and rewrites the .clj files with reconstructed ns forms." + "Takes a file or dir and rewrites the .clj files with reconstructed ns forms. + This function is strictly intended for use from a command line." [& file-or-dirs] (with-regrow-cache (doseq [file-or-dir file-or-dirs @@ -81,7 +84,9 @@ (println "Failed to reconstruct:" file) (if (System/getenv "DEBUG") (.printStackTrace e) - (println (.getMessage e)))))))) + (println (.getMessage e))))))) + (when-not *testing?* + (shutdown-agents))) ;; See https://github.com/technomancy/nrepl-discover (defn ^{:nrepl/op {:name "slam" diff --git a/test/slam/hound_test.clj b/test/slam/hound_test.clj index 1199735..0645c95 100644 --- a/test/slam/hound_test.clj +++ b/test/slam/hound_test.clj @@ -155,6 +155,7 @@ (deftest ^:integration test-main (with-tempfile tmp (io/copy (io/reader (io/resource "test_namespace.clj")) tmp) - (-main tmp) + (binding [slam.hound/*testing?* true] + (-main tmp)) (is (= (slurp (io/resource "reconstructed_namespace.clj")) (slurp tmp)))))