[#498] Fix for invoking -f with empty file

This commit is contained in:
Michiel Borkent 2020-06-27 12:12:53 +02:00 committed by GitHub
parent ede2916c6b
commit 8a75a70bbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View file

@ -544,7 +544,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
repl [(repl/start-repl! sci-ctx) 0] repl [(repl/start-repl! sci-ctx) 0]
socket-repl [(start-socket-repl! socket-repl sci-ctx) 0] socket-repl [(start-socket-repl! socket-repl sci-ctx) 0]
nrepl [(start-nrepl! nrepl sci-ctx) 0] nrepl [(start-nrepl! nrepl sci-ctx) 0]
(not (str/blank? expression)) expressions
(try (try
(loop [] (loop []
(let [in (read-next *in*)] (let [in (read-next *in*)]

View file

View file

@ -1,4 +1,5 @@
(ns babashka.main-test (ns babashka.main-test
{:clj-kondo/config '{:linters {:unresolved-symbol {:exclude [working?]}}}}
(:require (:require
[babashka.main :as main] [babashka.main :as main]
[babashka.test-utils :as test-utils] [babashka.test-utils :as test-utils]
@ -489,6 +490,19 @@
(is (= "true\ntrue\nfalse\n" (is (= "true\ntrue\nfalse\n"
(test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "version.clj")))))) (test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "version.clj"))))))
(defmethod clojure.test/assert-expr 'working? [msg form]
(let [body (next form)]
`(do ~@body
(clojure.test/do-report {:type :pass, :message ~msg,
:expected :success, :actual :success}))))
(deftest empty-expressions-test
(testing "bb executes the empty file and doesn't start a REPL"
(is (working? (test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "empty.clj"))))))
(testing "bb executes the empty expression and doesn't start a REPL"
(is (working? (test-utils/bb nil "-e" "")))))
;;;; Scratch ;;;; Scratch
(comment (comment