Fix #1368: -x: do not pick up on aliases in user ns

This commit is contained in:
Michiel Borkent 2022-09-22 20:04:41 +02:00
parent 848683f82d
commit 3110dde2ab
3 changed files with 26 additions and 6 deletions

View file

@ -7,6 +7,7 @@ A preview of the next release can be installed from
## Unreleased
- [#1368](https://github.com/babashka/babashka/issues/1368): `-x`: do not pick up on aliases in `user` ns
- [#1367](https://github.com/babashka/babashka/issues/1367): Fix line number in clojure.test output ([@retrogradeorbit](https://github.com/retrogradeorbit))
- [#1370](https://github.com/babashka/babashka/issues/1370): Add `core.async` `to-chan!`, `to-chan!!`, `onto-chan!` ([@cap10morgan](https://github.com/cap10morgan))
- [#1358](https://github.com/babashka/babashka/issues/1358): Expose a subset of java.lang.ref to enable hooking into the destruction/GC of objects ([@retrogradeorbit](https://github.com/retrogradeorbit))

View file

@ -12,10 +12,11 @@
([sym] (exec-fn-snippet sym nil))
([sym extra-opts]
(format "
(do
(require '[babashka.cli])
(let [extra-opts '%2$s
the-var (requiring-resolve `%1$s)
(ns exec-%s
(:require [babashka.cli :as cli]))
(let [extra-opts '%s
sym `%s
the-var (requiring-resolve sym)
the-var-meta (meta the-var)
ns (:ns (meta the-var))
ns-meta (meta ns)
@ -28,6 +29,8 @@
task-exec-args (:exec-args ct)
cli-exec-args (:exec-args cli-opts)
opts (babashka.cli/merge-opts cli-exec-args task-exec-args opts)]
(the-var opts)))"
(the-var opts))"
(random-uuid)
(pr-str extra-opts)
sym
(pr-str extra-opts))))
)))

View file

@ -0,0 +1,16 @@
(ns babashka.exec-test
(:require
[babashka.test-utils :as u]
[cheshire.core :as cheshire]
[clojure.edn :as edn]
[clojure.test :as t :refer [deftest is]]))
(defn bb [& args]
(apply u/bb nil args))
(deftest exec-test
(is (= {:foo 1} (edn/read-string (bb "-x" "prn" "--foo" "1"))))
(is (thrown? Exception (bb "-x" "json/generate-string" "--foo" "1")))
(is (= {:foo 1} (cheshire/parse-string
(edn/read-string
(bb "-x" "cheshire.core/generate-string" "--foo" "1")) true))))