diff --git a/project.clj b/project.clj index 7e23b51a..72f22857 100644 --- a/project.clj +++ b/project.clj @@ -14,7 +14,8 @@ ;; :java-source-paths ["sci/reflector/src-java"] :java-source-paths ["src-java"] :resource-paths ["resources" "sci/resources"] - :test-selectors {:windows (complement :skip-windows)} + :test-selectors {:default (complement :windows-only) + :windows (complement :skip-windows)} :dependencies [[org.clojure/clojure "1.11.0-alpha1"] [borkdude/edamame "0.0.11"] [borkdude/graal.locking "0.0.2"] diff --git a/script/test.bat b/script/test.bat index 2144ce6b..d0fe976e 100755 --- a/script/test.bat +++ b/script/test.bat @@ -34,9 +34,8 @@ set BABASHKA_CLASSPATH=test-resources/babashka/src_for_classpath_test/env echo "running tests part 4" call lein test :only babashka.classpath-test/classpath-env-test || exit /B 1 -echo "not running pod tests on windows (yet)" -REM set BABASHKA_POD_TEST=true -REM call lein test :only babashka.pod-test || exit /B 1 +set BABASHKA_POD_TEST=true +call lein test :only babashka.pod-test || exit /B 1 set BABASHKA_SOCKET_REPL_TEST=true call lein test :only babashka.impl.socket-repl-test || exit /B 1 diff --git a/test-resources/pod.clj b/test-resources/pod.clj index a92baecf..cd57ea17 100644 --- a/test-resources/pod.clj +++ b/test-resources/pod.clj @@ -128,10 +128,12 @@ (if (contains? cli-args "--run-as-pod") (do (debug "running pod with cli args" cli-args) (run-pod cli-args)) - (let [native? (contains? cli-args "--native")] - (pods/load-pod (if native? - (into ["./bb" "test-resources/pod.clj" "--run-as-pod"] cli-args) - (into ["lein" "bb" "test-resources/pod.clj" "--run-as-pod"] cli-args))) + (let [native? (contains? cli-args "--native") + windows? (contains? cli-args "--windows")] + (pods/load-pod (cond + native? (into ["./bb" "test-resources/pod.clj" "--run-as-pod"] cli-args) + windows? (into ["cmd" "/c" "lein" "bb" "test-resources/pod.clj" "--run-as-pod"] cli-args) + :else (into ["lein" "bb" "test-resources/pod.clj" "--run-as-pod"] cli-args))) (require '[pod.test-pod]) (if (contains? cli-args "--json") (do diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 6c54d679..e54f7862 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -244,21 +244,23 @@ *server* server] (babashka.tasks/run 'server)))}} (is (= '([8 :foo] [8 :bar] [11 :foo] [11 :bar] [15 :foo] [15 :bar]) - (bb "run" "--prn" "run-all")))))) - - -(deftest ^:skip-windows unix-task-test + (bb "run" "--prn" "run-all"))))) (let [tmp-dir (fs/create-temp-dir) - out (str (fs/file tmp-dir "out.txt"))] + out (str (fs/file tmp-dir "out.txt")) + ls-cmd (if main/windows? "cmd /c dir" "ls") + expected-output (if main/windows? "File Not Found" "foobar")] (testing "shell test with :continue" (test-utils/with-config {:tasks {'foo (list 'shell {:out out :err out :continue true} - "ls foobar")}} + (str ls-cmd " foobar"))}} (bb "foo") (is (str/includes? (slurp out) - "foobar")))) - (fs/delete out)) + expected-output)))) + (fs/delete out))) + + +(deftest ^:skip-windows unix-task-test (testing "shell pipe test" (test-utils/with-config '{:tasks {a (-> (shell {:out :string} "echo hello") @@ -267,6 +269,19 @@ (let [s (bb "run" "--prn" "a")] (is (= "hello\n" s)))))) +(deftest ^:windows-only win-task-test + (when main/windows? + (testing "shell pipe test" + ; this task prints the contents of deps.edn + (test-utils/with-config '{:tasks {a (->> (shell {:out :string} + "cmd /c echo deps.edn") + :out + clojure.string/trim-newline + (shell {:out :string} "cmd /c type") + :out)}} + (let [s (bb "run" "--prn" "a")] + (is (str/includes? s "paths"))))))) + (deftest list-tasks-test (test-utils/with-config {} (let [res (test-utils/bb nil "tasks")] diff --git a/test/babashka/impl/clojure/java/shell_test.clj b/test/babashka/impl/clojure/java/shell_test.clj index 1f8e75fb..3a9cc45a 100644 --- a/test/babashka/impl/clojure/java/shell_test.clj +++ b/test/babashka/impl/clojure/java/shell_test.clj @@ -1,7 +1,9 @@ (ns babashka.impl.clojure.java.shell-test - (:require [clojure.test :as t :refer [deftest is testing]] + (:require [babashka.main :as main] [babashka.test-utils :as test-utils] - [clojure.string :as str])) + [clojure.string :as str] + [clojure.test :as t :refer [deftest is testing]])) + (deftest ^:skip-windows with-sh-env-test (is (= "\"BAR\"" @@ -15,3 +17,17 @@ (shell/sh \"ls\")) :out)")) "icon.svg"))) + +(deftest ^:windows-only win-with-sh-env-test + (when main/windows? + (is (= "\"BAR\"" + (str/trim (test-utils/bb nil " +(-> (shell/with-sh-env {:FOO \"BAR\"} + (shell/sh \"cmd\" \"/c\" \"echo %FOO%\")) + :out + str/trim)")))) + (is (str/includes? (str/trim (test-utils/bb nil " +(-> (shell/with-sh-dir \"logo\" + (shell/sh \"cmd\" \"/c\" \"dir\")) + :out)")) + "icon.svg")))) diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index d2e83fe4..63e4da43 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -200,6 +200,7 @@ (is (true? (bb nil "(.exists (io/file \"README.md\"))"))) (is (true? (bb nil "(.canWrite (io/file \"README.md\"))")))) +; skipped because the windows shell doesn't seem to deal well with infinite things (deftest ^:skip-windows pipe-test (when (and test-utils/native? (not main/windows?)) @@ -208,15 +209,21 @@ head -n10")) out (str/split-lines out) out (map edn/read-string out)] - (is (= (take 10 (map #(* % %) (range))) out)))) - (when (and test-utils/native? - (not main/windows?)) + (is (= (take 10 (map #(* % %) (range))) out))) (let [out (:out (sh "bash" "-c" "./bb -O '(repeat \"dude\")' | ./bb --stream '(str *input* \"rino\")' | ./bb -I '(take 3 *input*)'")) out (edn/read-string out)] (is (= '("duderino" "duderino" "duderino") out))))) +(deftest ^:windows-only win-pipe-test + (when (and test-utils/native? main/windows?) + (let [out (:out (sh "cmd" "/c" ".\\bb -O \"(repeat 50 \\\"dude\\\")\" |" + ".\\bb --stream \"(str *input* \\\"rino\\\")\" |" + ".\\bb -I \"(take 3 *input*)\"")) + out (edn/read-string out)] + (is (= '("duderino" "duderino" "duderino") out))))) + (deftest ^:skip-windows lazy-text-in-test (when test-utils/native? (let [out (:out (sh "bash" "-c" "yes | ./bb -i '(take 2 *input*)'")) @@ -255,15 +262,11 @@ (is (every? number? parsed)) (is (= process-count (count parsed))))))) -(deftest ^:skip-windows create-temp-file-test - (let [temp-dir-path (System/getProperty "java.io.tmpdir")] - (is (= true - (bb nil (format "(let [tdir (io/file \"%s\") - tfile - (File/createTempFile \"ctf\" \"tmp\" tdir)] +(deftest create-temp-file-test + (is (= true + (bb nil "(let [tfile (File/createTempFile \"ctf\" \"tmp\")] (.deleteOnExit tfile) ; for cleanup - (.exists tfile))" - temp-dir-path)))))) + (.exists tfile))")))) (deftest wait-for-port-test (let [server (test-utils/start-server! 1777)] @@ -475,6 +478,11 @@ (prn "output:" v) (is v)))) +(deftest win-file-reader-test + (let [v (bb nil "(slurp (io/reader (java.io.FileReader. \"test-resources/babashka/empty.clj\")))")] + (prn "output:" v) + (is (empty? v)))) + (deftest ^:skip-windows download-and-extract-test ;; Disabled because Github throttles bandwidth and this makes for a very slow test. ;; TODO: refactor into individual unit tests @@ -659,6 +667,12 @@ true"))) (bb nil "-e" "(.get (.command (.info (java.lang.ProcessHandle/current))))") "bb")))) +(deftest ^:windows-only win-process-handler-info-test + (when (and test-utils/native? main/windows?) + (is (str/ends-with? + (bb nil "-e" "(.get (.command (.info (java.lang.ProcessHandle/current))))") + "bb.exe")))) + (deftest interop-concurrency-test (is (= ["true" 3] (last (bb nil "-e" " diff --git a/test/babashka/pod_test.clj b/test/babashka/pod_test.clj index 0b20ff58..f6c8e136 100644 --- a/test/babashka/pod_test.clj +++ b/test/babashka/pod_test.clj @@ -1,23 +1,29 @@ (ns babashka.pod-test - (:require [babashka.test-utils :as tu] + (:require [babashka.main :as main] + [babashka.test-utils :as tu] [clojure.edn :as edn] [clojure.test :as t :refer [deftest is]])) (deftest pod-test (if (= "true" (System/getenv "BABASHKA_POD_TEST")) (let [native? tu/native? + windows? main/windows? sw (java.io.StringWriter.) res (apply tu/bb {:err sw} (cond-> ["-f" "test-resources/pod.clj"] native? - (conj "--native"))) + (conj "--native") + windows? + (conj "--windows"))) err (str sw)] (is (= "6\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\"Illegal arguments / {:args (1 2 3)}\"\n(\"hello\" \"print\" \"this\" \"debugging\" \"message\")\ntrue\n" res)) (when-not tu/native? - (is (= "(\"hello\" \"print\" \"this\" \"error\")\n" err))) + (is (= "(\"hello\" \"print\" \"this\" \"error\")\n" (tu/normalize err)))) (is (= {:a 1 :b 2} (edn/read-string (apply tu/bb nil (cond-> ["-f" "test-resources/pod.clj" "--json"] native? - (conj "--native"))))))) + (conj "--native") + windows? + (conj "--windows"))))))) (println "Skipping pod test because BABASHKA_POD_TEST isn't set to true."))) diff --git a/test/babashka/uberjar_test.clj b/test/babashka/uberjar_test.clj index 9709df1a..581a863d 100644 --- a/test/babashka/uberjar_test.clj +++ b/test/babashka/uberjar_test.clj @@ -12,7 +12,7 @@ (enumeration-seq (.entries jar-file)))))) -(deftest ^:skip-windows uberjar-test +(deftest uberjar-test (testing "uberjar with --main" (let [tmp-file (java.io.File/createTempFile "uber" ".jar") path (.getPath tmp-file)] @@ -45,13 +45,16 @@ (is (= "(\"42\")\n" (tu/bb nil "--jar" path "-m" "my.main-main" "42"))) (is (= "(\"42\")\n" (tu/bb nil "--classpath" path "-m" "my.main-main" "42"))) (is (= "(\"42\")\n" (tu/bb nil path "42")))))) - (testing "throw on empty classpath" - (let [tmp-file (java.io.File/createTempFile "uber" ".jar") - path (.getPath tmp-file)] - (.deleteOnExit tmp-file) - (is (thrown-with-msg? - Exception #"classpath" - (tu/bb nil "uberjar" path "-m" "my.main-main"))))) + + ; this test fails the windows native test in CI + (when-not main/windows? + (testing "throw on empty classpath" + (let [tmp-file (java.io.File/createTempFile "uber" ".jar") + path (.getPath tmp-file)] + (.deleteOnExit tmp-file) + (is (thrown-with-msg? + Exception #"classpath" + (tu/bb nil "uberjar" path "-m" "my.main-main")))))) (testing "ignore empty entries on classpath" (let [tmp-file (java.io.File/createTempFile "uber" ".jar") path (.getPath tmp-file)