diff --git a/src/project_checkup/core.clj b/src/project_checkup/core.clj --- a/src/project_checkup/core.clj +++ b/src/project_checkup/core.clj @@ -2,6 +2,7 @@ (ns project-checkup.core (:gen-class) (:require [clojure.java.shell :as shell] + [clojure.set :as set] [clojure.string :as string])) (defn get-extension [path] @@ -18,16 +19,13 @@ (string/split (:out (shell/sh "chg" "st" "-u" "-n")) #"\n")) (if (contains? vcs-systems ".git") (string/split (:out (shell/sh "git" "ls-files" "--others" - "--exclude-standard")) #"\n"))])) + "--exclude-standard")) #"\n"))])) (defn gather-project-info "Creates a dictionary of project information." [] (let [all-files (map str (file-seq (clojure.java.io/file "."))) files (map #(clojure.string/replace % #"./(.*)" "$1") all-files ) - ; file-set (set files) - ;note that using some here means that if both are present, hg is - ;ignored: - vcs-systems (set (vector (some #{".git" ".hg"} files))) ] + vcs-systems (set/intersection #{".git" ".hg"} (set files))] {:files files :extensions (frequencies (map get-extension files )) :path (System/getProperty "user.dir") @@ -109,7 +107,7 @@ :function check-readme-placeholders :description "No placeholders in README" :level :error - :follow-up "Address placeholders or convert them to tasks."} + :follow-up "Address placeholders or convert them to tasks."} { :name "Project has a license" :function check-license :description "Project has a LICENSE file." @@ -143,7 +141,7 @@ (let [project-info (gather-project-info)] (doseq [check checks] (println (:output (perform-check check project-info ))))) - (catch Exception ex + (catch Exception ex ; Not expecting there to be a lot of exceptions, hence the catch-all. (.printStackTrace ex) (str "caught exception: " (.getMessage ex))) (finally (shutdown-agents)))) diff --git a/test/project_checkup/core_test.clj b/test/project_checkup/core_test.clj --- a/test/project_checkup/core_test.clj +++ b/test/project_checkup/core_test.clj @@ -2,38 +2,36 @@ (:require [clojure.test :refer :all] [project-checkup.core :refer :all])) - - (deftest test-check-vcs (testing "Ensure the check works." (is (check-vcs {:files [".git"]}) ) (is (check-vcs {:files [".hg"]}) ) + (is + (check-vcs {:files [".hg" ".git"]}) )) + (testing "Ensure no false positives." (is (not (check-vcs {:files []})) ) (is ;various almost-correct entries (not (check-vcs {:files ["hg" "git" "."]})) ))) - (deftest test-check-readme (testing "Ensure READMEs are found correctly." (is (check-readme {:files ["README.md"]}))) - (testing "Ensure no false positives" - (is - (not (check-readme {:files ["readme.exe"]}))) + (testing "Ensure no false positives" + (is + (not (check-readme {:files ["readme.exe"]}))) (is (not (check-readme {:files []}))))) (deftest test-check-untracked (testing "Ensure empty returns true" - (is (check-untracked {:untracked-files []})) - ) + (is (check-untracked {:untracked-files []}))) (testing "Ensure non-empty returns false" (is (not (check-untracked {:untracked-files [".hg"]}))))) - (deftest test-check-license (testing "Ensure license is counted" (is (check-license {:files ["LICENSE.mkd"]}))