Start porting Windows tests (#235) (#887)

This commit is contained in:
Michiel Borkent 2021-06-16 11:01:17 +02:00 committed by GitHub
parent f519c35823
commit 90ac55d588
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 28 deletions

View file

@ -8,6 +8,7 @@ clone_folder: C:\projects\babashka
environment:
GRAALVM_HOME: C:\projects\babashka\graalvm\graalvm-ce-java11-21.1.0
JAVA_HOME: C:\projects\babashka\graalvm\graalvm-ce-java11-21.1.0
BABASHKA_XMX: "-J-Xmx5g"
cache:
@ -30,24 +31,26 @@ clone_script:
- cmd: git submodule update --init --recursive
build_script:
- cmd: >-
powershell -Command "if (Test-Path('graalvm')) { return } else { (New-Object Net.WebClient).DownloadFile('https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.1.0/graalvm-ce-java11-windows-amd64-21.1.0.zip', 'graalvm.zip') }"
powershell -Command "if (Test-Path('graalvm')) { return } else { Expand-Archive graalvm.zip graalvm }"
- cmd: >-
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein.bat', 'lein.bat')"
call lein self-install
# set CLJ_KONDO_TEST_ENV=jvm
- cmd: >-
set BABASHKA_TEST_ENV=jvm
# call script/test.bat
call script/test.bat
# see https://github.com/quarkusio/quarkus/pull/7663
- cmd: >-
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
powershell -Command "if (Test-Path('graalvm')) { return } else { (New-Object Net.WebClient).DownloadFile('https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.1.0/graalvm-ce-java11-windows-amd64-21.1.0.zip', 'graalvm.zip') }"
powershell -Command "if (Test-Path('graalvm')) { return } else { Expand-Archive graalvm.zip graalvm }"
call script/uberjar.bat
call script/compile.bat
@ -62,12 +65,9 @@ build_script:
bb release-artifact %zip%
# - cmd: >-
# lein clean
set BABASHKA_TEST_ENV=native
# set CLJ_KONDO_TEST_ENV=native
# call script/test.bat
call script/test.bat
artifacts:
- path: babashka-*-windows-amd64.zip

View file

@ -14,6 +14,7 @@
;; :java-source-paths ["sci/reflector/src-java"]
:java-source-paths ["src-java"]
:resource-paths ["resources" "sci/resources"]
:test-selectors {:windows :windows}
:dependencies [[org.clojure/clojure "1.11.0-alpha1"]
[borkdude/edamame "0.0.11"]
[borkdude/graal.locking "0.0.2"]

11
script/test.bat Executable file
View file

@ -0,0 +1,11 @@
if "%GRAALVM_HOME%"=="" (
echo Please set GRAALVM_HOME
exit /b
)
echo "BABASHKA_TEST_ENV: %BABASHKA_TEST_ENV%"
set JAVA_HOME=%GRAALVM_HOME%
set PATH=%GRAALVM_HOME%\bin;%PATH%
call lein do clean, test :windows

View file

@ -180,7 +180,7 @@
"session" session "id" (new-id!)})
(dotimes [_ 3]
(let [reply (read-reply in session @id)]
(is (= "Hello\n" (:out reply)))))))))
(is (= "Hello\n" (tu/normalize (:out reply))))))))))
(deftest nrepl-server-test
(let [proc-state (atom nil)

View file

@ -2,6 +2,7 @@
(:require
[babashka.impl.pprint :refer [pprint-namespace]]
[babashka.impl.repl :refer [start-repl!]]
[babashka.test-utils :as tu]
[clojure.string :as str]
[clojure.test :as t :refer [deftest is]]
[sci.core :as sci]
@ -20,18 +21,20 @@
:namespaces {'clojure.pprint pprint-namespace}})))
(defn assert-repl [expr expected]
(is (str/includes? (sci/with-out-str
(sci/with-in-str (str expr "\n:repl/quit")
(repl!))) expected)))
(is (str/includes? (tu/normalize
(sci/with-out-str
(sci/with-in-str (str expr "\n:repl/quit")
(repl!)))) expected)))
(defn assert-repl-error [expr expected]
(is (str/includes?
(let [sw (java.io.StringWriter.)]
(sci/binding [sci/out (java.io.StringWriter.)
sci/err sw]
(sci/with-in-str (str expr "\n:repl/quit")
(repl!)))
(str sw)) expected)))
(tu/normalize
(let [sw (java.io.StringWriter.)]
(sci/binding [sci/out (java.io.StringWriter.)
sci/err sw]
(sci/with-in-str (str expr "\n:repl/quit")
(repl!)))
(str sw))) expected)))
(deftest repl-test
(assert-repl "1" "1")

View file

@ -17,7 +17,7 @@
:eof nil}
(apply test-utils/bb (when (some? input) (str input)) (map str args))))
(deftest parse-opts-test
(deftest ^:windows parse-opts-test
(is (= "1667"
(:nrepl (main/parse-opts ["--nrepl-server"]))))
(is (= "1666"
@ -132,7 +132,7 @@
(is (not-empty s)))))
(deftest malformed-command-line-args-test
(is (thrown-with-msg? Exception #"File does not exist: non-existing\n"
(is (thrown-with-msg? Exception #"File does not exist: non-existing"
(bb nil "-f" "non-existing"))))
(deftest ssl-test
@ -178,10 +178,11 @@
name)))))
(testing "print source from file on classpath"
(is (= "(defn foo [x y]\n (+ x y))\n"
(bb nil
"-cp" dir
"-e" (format "(require '[clojure.repl :refer [source]] '[%s])" name)
"-e" (format "(with-out-str (source %s/foo))" name)))))))
(test-utils/normalize
(bb nil
"-cp" dir
"-e" (format "(require '[clojure.repl :refer [source]] '[%s])" name)
"-e" (format "(with-out-str (source %s/foo))" name))))))))
(deftest eval-test
(is (= "120\n" (test-utils/bb nil "(eval '(do (defn foo [x y] (+ x y))

View file

@ -6,12 +6,19 @@
[babashka.main :as main]
[babashka.process :as p]
[clojure.edn :as edn]
[clojure.string :as str]
[clojure.test :as test :refer [*report-counters*]]
[sci.core :as sci]
[sci.impl.vars :as vars]))
(set! *warn-on-reflection* true)
(defn normalize [s]
(if main/windows?
(str/replace s "\r\n" "\n")
s))
(def ^:dynamic *bb-edn-path* nil)
(defmethod clojure.test/report :begin-test-var [m]
@ -55,7 +62,7 @@
(with-in-str input-or-opts (apply main/main args))
(apply main/main args)))]
(if (zero? res)
(str os)
(normalize (str os))
(do
(println (str os))
(throw (ex-info (str es)