From 4a1b26a6bea25e877536619b4067b21f198d34e0 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Fri, 15 Dec 2023 18:07:47 +0100 Subject: [PATCH] Fix tests --- src/babashka/main.clj | 21 +++++++++++---------- test/babashka/main_test.clj | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 99aa73f6..49bc7aad 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -718,13 +718,12 @@ Use bb run --help to show this help output. (defn parse-file-opt [options opts-map] (let [opt (first options)] - (if (and opt (fs/exists? opt)) - (let [opts (assoc opts-map - (if (str/ends-with? opt ".jar") - :jar :file) opt - :command-line-args (next options))] - opts) - opts-map))) + (if (and opt (and (fs/exists? opt) + (not (fs/directory? opt)))) + [(next options) (assoc opts-map + (if (str/ends-with? opt ".jar") + :jar :file) opt)] + [options opts-map]))) (defn parse-opts ([options] (parse-opts options nil)) @@ -744,7 +743,8 @@ Use bb run --help to show this help output. (and (not (or (:file opts-map) (:jar opts-map))) (.isFile (io/file opt))) - (parse-file-opt options opts-map) + (let [[args opts] (parse-file-opt options opts-map)] + (assoc opts :command-line-args args)) (contains? tasks opt) (assoc opts-map :run opt @@ -1144,11 +1144,12 @@ Use bb run --help to show this help output. (list* "--jar" bin-jar "--" args) args) [args opts] (parse-global-opts args) - {:keys [jar file config merge-deps] :as opts} + ;; TODO: drop jar file from opts + [args {:keys [jar file config merge-deps] :as opts}] (if-not (or (:file opts) (:jar opts)) (parse-file-opt args opts) - opts) + [args opts]) abs-path #(-> % io/file .getAbsolutePath) config (cond config (when (fs/exists? config) (abs-path config)) diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index c223225e..49177045 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -68,7 +68,7 @@ (parse-opts ["--force" "clojure" "-M" "-r"]))) (testing "file opts parsing does not mess with :command-line-args" (is (= {:prn true, :expressions ["(prn :foo)"]} - (-> (let [opts (main/parse-file-opt ["-e" "(prn :foo)"] {})] + (-> (let [[_ opts] (main/parse-file-opt ["-e" "(prn :foo)"] {})] (main/parse-opts ["-e" "(prn :foo)"] opts))))) (is (= {:file "foo", :command-line-args ["README.md"]} (main/parse-opts ["README.md"] {:file "foo"})))))