[#606] Fix System/exit in REPL

This commit is contained in:
Michiel Borkent 2020-10-05 22:11:21 +02:00
parent 5c7f8dedff
commit 864c30ef15
2 changed files with 1 additions and 14 deletions

View file

@ -398,10 +398,6 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
'org.httpkit.sni-client @(resolve 'babashka.impl.httpkit-client/sni-client-namespace))
features/httpkit-server? (assoc 'org.httpkit.server @(resolve 'babashka.impl.httpkit-server/httpkit-server-namespace))))
(def bindings
{'java.lang.System/exit exit ;; override exit, so we have more control
'System/exit exit})
(def imports
'{ArithmeticException java.lang.ArithmeticException
AssertionError java.lang.AssertionError
@ -540,7 +536,6 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
(fn [ctx & opts]
(let [opts (apply hash-map opts)]
(repl/start-repl! ctx opts)))))
:bindings bindings
:env env
:features #{:bb :clj}
:classes classes/class-map

View file

@ -121,15 +121,7 @@
(let [res (bb nil "-f" "test/babashka/scripts/System.bb")]
(is (= "bar" (second res)))
(doseq [s res]
(is (not-empty s))))
(let [out (java.io.StringWriter.)
err (java.io.StringWriter.)
exit-code (sci/with-bindings {sci/out out
sci/err err}
(binding [*out* out *err* err]
(main/main "(println \"Hello world!\") (System/exit 42)")))]
(is (= (str out) "Hello world!\n"))
(is (= 42 exit-code))))
(is (not-empty s)))))
(deftest malformed-command-line-args-test
(is (thrown-with-msg? Exception #"File does not exist: non-existing\n"