Skip to content

Commit

Permalink
Need to add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slipset committed Oct 11, 2018
1 parent 54fc334 commit 39ad1a9
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/eastwood/lint_test.clj
@@ -0,0 +1,72 @@
(ns eastwood.lint-test
(:use [clojure.test ])
(:require [eastwood.lint :refer :all]
[eastwood.copieddeps.dep11.clojure.java.classpath :as classpath]
[eastwood.util :as util]
[eastwood.copieddeps.dep9.clojure.tools.namespace.dir :as dir]
[eastwood.copieddeps.dep9.clojure.tools.namespace.track :as track]
[eastwood.reporting-callbacks :as reporting])
(:import java.io.File))


(deftest expand-ns-keywords-test
(testing ""
(is (= ["foo" "bar" "baz"] (expand-ns-keywords {:source-paths ["foo"]} [:source-paths "bar" "baz"])))))

(deftest last-options-map-adjustments-test
(let [reporter (reporting/silent-reporter default-opts)]
(testing "default-options are added"
(is (= default-opts
(dissoc (last-options-map-adjustments nil reporter)
:warning-enable-config))))
(testing "passed options are respected"
(is (= (assoc default-opts
:namespaces #{"foo"})
(dissoc (last-options-map-adjustments {:namespaces ["foo"]} reporter)
:warning-enable-config))))
(testing "all the things are sets"
(is (empty? (->>
(select-keys (last-options-map-adjustments {:namespaces []} reporter) [:debug :namespaces :source-paths :test-paths :exclude-namespaces])
(vals)
(remove set?)))))))

(deftest setup-lint-paths-test
(testing "non-empty source/test paths is respected"
(is (= {:source-paths #{"lol"}
:test-paths #{}}
(setup-lint-paths #{"lol"} nil)))
(is (= {:source-paths #{}
:test-paths #{"lol"}}
(setup-lint-paths nil #{"lol"})))
(is (= {:source-paths #{"lol"}
:test-paths #{"bar"}}
(setup-lint-paths #{"lol"} #{"bar"}))))
(testing "empty source/test paths yields classpath-directories"
(with-redefs [classpath/classpath-directories (fn [] [(File. "lol" )])]
(is (= {:source-paths #{(File. "lol")}
:test-paths #{}}
(setup-lint-paths nil nil))))))

(def eastwood-src-namespaces (::track/load (dir/scan-dirs (track/tracker) #{"src"})))
(def eastwood-test-namespaces (::track/load (dir/scan-dirs (track/tracker) #{"test"})))
(def eastwood-all-namespaces (concat eastwood-src-namespaces eastwood-test-namespaces))

(deftest nss-in-dirs-test
(let [dirs #{"src"}]
(testing "basic functionality"
(is (= {:dirs (set (map util/canonical-filename dirs))
:namespaces eastwood-src-namespaces}
(select-keys (nss-in-dirs dirs nil) [:dirs :namespaces]))))))

(deftest opts->namespaces-test
(let [source-paths #{"src"}
test-paths #{"test"}]
(testing ""
(is (= {:dirs (concat (map util/canonical-filename source-paths)
(map util/canonical-filename test-paths))
:namespaces eastwood-all-namespaces}
(select-keys (opts->namespaces {:cwd "."
:namespaces #{:source-paths :test-paths}}
{:source-paths source-paths
:test-paths test-paths})
[:dirs :namespaces]))))))

0 comments on commit 39ad1a9

Please sign in to comment.