From 319f2e1fcd318a865cb458857ba7c45b4eb6a798 Mon Sep 17 00:00:00 2001 From: lread Date: Fri, 25 Sep 2026 12:08:58 -0400 Subject: [PATCH] error-fn-test: make processing order clearer Docs refer to `error-fn-test` as an example of collecting all errors. This test happened to pass because `:spec` map size is small. For larger maps processing order, and therefore errors order, would be indeterminate. Add comment and explicitly sort collected errors to make it clear that order is indeterminate. Reformat expected map to make it easier to eyeball :msg values. Closes #235 --- test/babashka/cli_test.cljc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/babashka/cli_test.cljc b/test/babashka/cli_test.cljc index 07255e6..2fa126d 100644 --- a/test/babashka/cli_test.cljc +++ b/test/babashka/cli_test.cljc @@ -1616,15 +1616,19 @@ {:error-fn (fn [error] (swap! errors conj error)) :restrict true :spec spec}) - (is (= [{:spec spec, :type :org.babashka/cli, :cause :coerce, + (is (= [{:spec spec, :type :org.babashka/cli, :cause :validate, + :msg "Invalid value for option --b: 0", :validate {:b pos?}, :option :b, :flag "--b", :value 0, + :opts {:b 0, :extra "bad!"}} + {:spec spec, :type :org.babashka/cli, :cause :coerce, :msg "Invalid value for option --c: cannot transform input \"nope!\" to long", :option :c, :flag "--c", :value "nope!", :opts {:b 0}} - {:spec spec, :type :org.babashka/cli, :cause :restrict, :msg "Unknown option: --extra", :restrict #{:c :b :a}, :option :extra, :flag "--extra", :opts {:b 0, :extra "bad!"}} ;; :require has no :flag in data (never typed); the message uses the canonical --a - {:spec spec, :type :org.babashka/cli, :cause :require, :msg "Required option: --a", :require #{:a}, :option :a, :opts {:b 0, :extra "bad!"}} - {:spec spec, :type :org.babashka/cli, :cause :validate, :msg "Invalid value for option --b: 0", :validate {:b pos?}, :option :b, :flag "--b", :value 0, - :opts {:b 0, :extra "bad!"}}] - @errors)))) + {:spec spec, :type :org.babashka/cli, :cause :require, + :msg "Required option: --a", :require #{:a}, :option :a, :opts {:b 0, :extra "bad!"}} + {:spec spec, :type :org.babashka/cli, :cause :restrict, + :msg "Unknown option: --extra", :restrict #{:c :b :a}, :option :extra, :flag "--extra", :opts {:b 0, :extra "bad!"}}] + ;; processing order, and therefore collected errors order, is indeterminate + (sort-by :msg @errors))))) (deftest exec-args-replaced-test (is (= {:foo [:bar] :dude [:baz]} (cli/parse-opts ["--foo" ":bar"] {:coerce {:foo [] :dude []}