babashka/test/babashka/deps_test.clj
Bob 35e2cd9d05
make tests run on windows as the default (#235) (#898)
* make tests run on windows as the default

- change from selecting tests to run to selecting tests to skip (remove all :windows tags, add
  :skip-windows tag to tests that don't currently work on windows)
- handfuls of calls to `normalize` and `escape-file-paths` to handle platform differences
- split `task-test` to make most of the tests run on windows, and exclude just a couple of Unix-y tests

* make a binding name clearer

* skip nrepl-server-test on Windows

- test fails on CI, so disabling it for now

* unset bb environment vars after running tests

* unset bb environment var after running release-artifact

BABASHKA_EDN being set can interfere with some tests, so unset it before running the
native tests

* skip uberjar test on Windows

uberjar-test's 'throw on empty classpath' test failing on Windows native
 (but passes on JVM) - skip it for now
2021-06-20 09:23:58 +02:00

59 lines
1.6 KiB
Clojure

(ns babashka.deps-test
(:require
[babashka.test-utils :as test-utils]
[clojure.edn :as edn]
[clojure.test :as test :refer [deftest is testing]]))
(defn bb [& args]
(edn/read-string
{:readers *data-readers*
:eof nil}
(apply test-utils/bb nil (map str args))))
(deftest dependency-test (is (= #{:a :c :b} (bb "
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {com.stuartsierra/dependency {:mvn/version \"1.0.0\"}}})
(require '[com.stuartsierra.dependency :as dep])
(def g1 (-> (dep/graph)
(dep/depend :b :a)
(dep/depend :c :b)
(dep/depend :c :a)
(dep/depend :d :c)))
(dep/transitive-dependencies g1 :d)
"))))
(deftest clojure-test
(testing "-Stree prints to *out*"
(is (true? (bb "
(require '[babashka.deps :as deps])
(require '[clojure.string :as str])
(str/includes?
(with-out-str (babashka.deps/clojure [\"-Stree\"]))
\"org.clojure/clojure\")
"))))
(testing "-P does not exit babashka script"
(is (true? (bb "
(require '[babashka.deps :as deps])
(require '[clojure.string :as str])
(babashka.deps/clojure [\"-P\"])
true
"))))
(is (= "6\n" (test-utils/normalize (bb "
(require '[babashka.deps :as deps])
(require '[babashka.process :as p])
(-> (babashka.deps/clojure [\"-M\" \"-e\" \"(+ 1 2 3)\"] {:out :string})
(p/check)
:out)
"))))
(when-not test-utils/native?
(is (thrown-with-msg? Exception #"Option changed" (bb "
(require '[babashka.deps :as deps])
(babashka.deps/clojure [\"-Sresolve-tags\"])
"))))
(is (true? (bb "
(= 5 (:exit @(babashka.deps/clojure [] {:in \"(System/exit 5)\" :out :string})))"))))