Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rads committed Jul 23, 2022
1 parent 6719349 commit d7f7623
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
2 changes: 2 additions & 0 deletions test-resources/new/my-kit/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:paths ["src"]
:deps {}}
12 changes: 12 additions & 0 deletions test-resources/new/my-kit/src/scratch.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns scratch
"FIXME: my new io.github.rads/kit project.")

(defn exec
"Invoke me with clojure -X scratch/exec"
[opts]
(println "exec with" opts))

(defn -main
"Invoke me with clojure -M -m scratch"
[& args]
(println "-main with" args))
2 changes: 2 additions & 0 deletions test-resources/new/my-scratch/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:paths ["src"]
:deps {}}
12 changes: 12 additions & 0 deletions test-resources/new/my-scratch/src/scratch.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns scratch
"FIXME: my new org.corfield.new/scratch project.")

(defn exec
"Invoke me with clojure -X scratch/exec"
[opts]
(println "exec with" opts))

(defn -main
"Invoke me with clojure -M -m scratch"
[& args]
(println "-main with" args))
31 changes: 26 additions & 5 deletions tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
(deftest dep-search-test
(is (thrown? java.lang.Exception (run-dep-subcommand "search" "someBougusLibThatDoesntExist")))
(is (not-empty (run-dep-subcommand "search" "hiccups")))
(is (some #(str/starts-with? % ":lib hiccups/hiccups" )
(is (some #(str/starts-with? % ":lib hiccups/hiccups")
(run-dep-subcommand "search" "hiccups")))
(is (some #(re-matches #":lib hiccups/hiccups :version \d+(\.\d+)+ :description .*" % )
(is (some #(re-matches #":lib hiccups/hiccups :version \d+(\.\d+)+ :description .*" %)
(run-dep-subcommand "search" "hiccups")))
(is (some #(re-matches #":lib macchiato/hiccups :version \d+(\.\d+)+ :description .*" % )
(is (some #(re-matches #":lib macchiato/hiccups :version \d+(\.\d+)+ :description .*" %)
(run-dep-subcommand "search" "hiccups")))
; tests for no NPEs/json parsing exceptions
(is (any? (run-dep-subcommand "search" "org.clojure/tools.cli")))
Expand Down Expand Up @@ -76,11 +76,32 @@
(run-license out-file "add" ":license epl-2.0")
(is (str/includes? (slurp out-file) "Eclipse Public License")))
(testing "missing license key errors"
(is (thrown-with-msg? Exception #"No license key"
(is (thrown-with-msg? Exception #"No license key"
(run-license out-file "add"))))
(testing "invalid license key errors"
(is (thrown-with-msg? Exception #"nonExistentLicense"
(is (thrown-with-msg? Exception #"nonExistentLicense"
(run-license out-file "add" "nonExistentLicense"))))))

(deftest new-scratch-test
(let [target-dir (str (fs/temp-dir) "/my-scratch")]
(spit (test-file "deps.edn") "{}")
(neil (str "new scratch my-scratch :overwrite true :target-dir " target-dir))
(is (= (slurp (fs/file "test-resources/new/my-scratch/src/scratch.clj"))
(slurp (fs/file (str target-dir "/src/scratch.clj")))))
(is (= (slurp (fs/file "test-resources/new/my-scratch/deps.edn"))
(slurp (fs/file (str target-dir "/deps.edn")))))))

(deftest new-remote-test
(let [target-dir (str (fs/temp-dir) "/my-kit")]
(spit (test-file "deps.edn") "{}")
(neil (str "new io.github.rads/kit my-kit :overwrite true :target-dir " target-dir))
(is (= (slurp (fs/file "test-resources/new/my-kit/src/scratch.clj"))
(slurp (fs/file (str target-dir "/src/scratch.clj")))))
(is (= (slurp (fs/file "test-resources/new/my-kit/deps.edn"))
(slurp (fs/file (str target-dir "/deps.edn")))))))

(when (= *file* (System/getProperty "babashka.file"))
(t/run-tests *ns*))

(comment
(clojure.test/run-tests 'tests))

0 comments on commit d7f7623

Please sign in to comment.