diff --git a/bb.edn b/bb.edn index 18684f1f..223f909a 100644 --- a/bb.edn +++ b/bb.edn @@ -1,80 +1,56 @@ -{:deps {hephaistox/automaton-build-app - {:git/sha "797da62e6cecd368b7ec4d9a8672117806606402", - :git/url "git@github.com:hephaistox/automaton-build-app.git"}}, - :paths [], +{:deps {hephaistox/automaton-build-app {:git/url "https://github.com/hephaistox/automaton-build-app.git" + :sha "db42465833ea1c5c40339fddafefcea461dc21c5"}} + :paths [] :tasks - {:enter (let [task-name (-> (babashka.tasks/current-task) - :name - str)] - (def execute-task - (partial build-task-helper/execute-task - task-name - (build-task-helper/enter-tasks task-name {})))), - :init (build-task-helper/init-tasks), - :requires [[automaton-build-app.tasks-helper :as build-task-helper]], - clean {:doc "Clean cache files for compiles, and logs", - :task (execute-task (quote automaton-build-app.tasks.clean/clean))}, - clean-hard - {:doc - "Clean all files which are not under version control (it doesn't remove untracked file or staged files if there are eligible to `git add .`)", - :task (execute-task (quote - automaton-build-app.tasks.clean-hard/clean-hard))}, - code-doc {:doc "Create the documentation of the app", - :task (execute-task (quote - automaton-build-app.tasks.code-doc/code-doc) - {:executing-pf :clj})}, - compile-to-jar - {:doc "Compile that code to a jar", - :task (execute-task - (quote automaton-build-app.tasks.compile-to-jar/compile-to-jar) - {:executing-pf :clj})}, - container-clear - {:doc "Clear all local containers", - :task (execute-task - (quote - automaton-build-app.tasks.container-clear/container-clear))}, - container-list - {:doc "List all available containers", - :task (execute-task - (quote - automaton-build-app.tasks.container-list/container-list))}, - format {:doc "Format the whole documentation", - :task (execute-task - (quote - automaton-build-app.tasks.format-files/format-files))}, - gha {:doc "Github action command - is launched automatically by github", - :task (execute-task (quote automaton-build-app.tasks.gha/gha) - {:executing-pf :clj})}, - gha-container-publish - {:doc "Update the gha container to run that app", + {:enter (do (def cust-app-task-registy {}) + (defn execute-build-app-task + [task-fn & argv] + (build-task-bb-entrypoint/execute-task (-> (current-task) + :name + str) + task-fn + argv))) + :requires [[babashka.process :as babahska-process] [automaton-build-app.tasks.launcher.bb-entrypoint :as build-task-bb-entrypoint]] + clean {:doc "Clean cache files for compiles, and logs" + :task (execute-build-app-task (quote automaton-build-app.tasks.clean/clean))} + clean-hard + {:doc + "Clean all files which are not under version control (it doesn't remove untracked file or staged files if there are eligible to `git add .`)" + :task (execute-build-app-task (quote automaton-build-app.tasks.clean-hard/clean-hard))} + code-doc {:doc "Create the documentation of the app" + :task (execute-build-app-task (quote automaton-build-app.tasks.code-doc/code-doc))} + compile-to-jar {:doc "Compile that code to a jar" + :task (execute-build-app-task (quote automaton-build-app.tasks.compile-to-jar/compile-to-jar))} + container-clear {:doc "Clear all local containers" + :task (execute-build-app-task (quote automaton-build-app.tasks.container-clear/container-clear))} + container-list {:doc "List all available containers" + :task (execute-build-app-task (quote automaton-build-app.tasks.container-list/container-list))} + format {:doc "Format the whole documentation" + :task (execute-build-app-task (quote automaton-build-app.tasks.format-files/format-files))} + gha {:doc "Github action command - launched is automatically by github" + :task (execute-build-app-task (quote automaton-build-app.tasks.gha/gha))} + gha-container-publish {:doc "Update the gha container to run that app" + :task (execute-build-app-task (quote automaton-build-app.tasks.gha-container-publish/gha-container-publish))} + gha-lconnect {:doc "Connect to a local container running this code" + :task (execute-build-app-task (quote automaton-build-app.tasks.gha-lconnect/gha-lconnect))} + ide {:doc "Quick tests to use during IDE usage" :task - (execute-task - (quote - automaton-build-app.tasks.gha-container-publish/gha-container-publish))}, - gha-lconnect - {:doc "Connect to a local container running this code", - :task (execute-task - (quote automaton-build-app.tasks.gha-lconnect/gha-lconnect))}, - ide {:doc "Quick tests to use during IDE", - :task (execute-task (quote automaton-build-app.tasks.ide/ide))}, - la {:doc "Local acceptance test", - :task (execute-task (quote automaton-build-app.tasks.la/la))}, - lconnect {:doc "Local connect - repl", - :task (execute-task - (quote automaton-build-app.tasks.lconnect/lconnect))}, - lint {:doc "linter", - :task (execute-task (quote automaton-build-app.tasks.lint/lint))}, - ltest {:doc "Local test", - :task (execute-task (quote automaton-build-app.tasks.ltest/ltest))}, - push {:doc "Push this repo", - :task (execute-task (quote automaton-build-app.tasks.push/push) - {:executing-pf :clj})}, - report {:doc "Creates the reports of code analyzis", - :task (execute-task (quote - automaton-build-app.tasks.reports/reports))}, - update-deps - {:doc - "Update the dependencies, cider-nrepl and refactor are to be updated manually", - :task (execute-task (quote - automaton-build-app.tasks.update-deps/update-deps) - {:executing-pf :clj})}}} \ No newline at end of file + (execute-build-app-task (quote automaton-build-app.tasks.workflow.composer/composer) (quote report) (quote format) (quote lint))} + la {:doc "Local acceptance test" + :task (execute-build-app-task (quote automaton-build-app.tasks.la/la))} + lconnect {:doc "Local connect - repl" + :task (execute-build-app-task (quote automaton-build-app.tasks.lconnect/lconnect))} + lint {:doc "linter" + :task (execute-build-app-task (quote automaton-build-app.tasks.lint/lint))} + ltest {:doc "Local test" + :task (execute-build-app-task (quote automaton-build-app.tasks.ltest/ltest))} + push {:doc "Push this repo" + :task (execute-build-app-task (quote automaton-build-app.tasks.push/push) {:executing-pf :clj})} + push-local-dir-to-repo {:doc "Push this repo " + :task (execute-build-app-task (quote automaton-build-app.tasks.push-local-dir-to-repo/push-local-dir-to-repo))} + report {:doc "Creates the reports of code analyzis" + :task (execute-build-app-task (quote automaton-build-app.tasks.reports/reports))} + update-deps {:doc "Update the dependencies, cider-nrepl and refactor are to be updated manually" + :task (execute-build-app-task (quote automaton-build-app.tasks.update-deps/update-deps))} + wf-6 {:doc "Push the local version - create gha docker image - push to the repo" + :task (execute-build-app-task (quote automaton-build-app.tasks.workflow.composer/composer) (quote clean) (quote clean))}}} \ No newline at end of file diff --git a/build_config.edn b/build_config.edn index ce4efafe..fd742437 100644 --- a/build_config.edn +++ b/build_config.edn @@ -1,36 +1,33 @@ -{:app-name "automaton-core", - :clean {:compile-logs-dirs [".cpcache" ".clj-kondo/.cache" "tmp"]}, +{:app-name "automaton-core" + :clean {:compile-logs-dirs [".cpcache" ".clj-kondo/.cache" "tmp"]} ;:customer-materials {:dir "customer_materials", :html-dir "tmp/html", ;:pdf-dir "tmp/pdf"}, - :doc {:archi {:dir "docs/archi/"}, + :doc {:archi {:dir "docs/archi/"} ;; :code-doc {:description "Core hephaistox app", ;; :dir "docs/code", :title "Core app automaton"}, - :code-stats {:output-file "docs/code/stats.md"}, - :dir "docs", - :reports {:forbidden-words #{"automaton-web" "landing"}, - :output-files {:alias "docs/code/alias.edn", - :comments "docs/code/comments.edn", - :css "docs/code/css.edn", - :deps "docs/code/deps.png", - :deps-ns "docs/code/deps-ns.svg", - :forbidden-words - "docs/code/forbidden-words.edn", - :ns "docs/code/ns.png"}}}, - :la {}, - :lconnect {:aliases [:common-test :env-development-repl]}, - :ltest {:aliases [:env-development-test :common-test]}, - :monorepo {:app-dir "automaton/automaton_core"}, - :publication {:as-lib hephaistox/automaton-core, - :gha-container - {:account "hephaistox", - :repo-branch "main", - :repo-url "git@github.com:hephaistox/gha_image.git", - :workflows [[".github/workflows/commit_validation.yml" - "gha-automaton-core"]]}, - :jar {:class-dir "target/classes", - :excluded-aliases #{}, - :target-filename "target/%s-%s.jar"}, - :major-version "0.0.%d", - :repo {:address "git@github.com:hephaistox/automaton-core.git", - :branch "main"}, + :code-stats {:output-file "docs/code/stats.md"} + :dir "docs" + :reports {:forbidden-words #{"automaton-web" "landing"} + :output-files {:alias "docs/code/alias.edn" + :comments "docs/code/comments.edn" + :css "docs/code/css.edn" + :deps "docs/code/deps.png" + :deps-ns "docs/code/deps-ns.svg" + :forbidden-words "docs/code/forbidden-words.edn" + :ns "docs/code/ns.png"}}} + :la {} + :lconnect {:aliases [:common-test :env-development-repl]} + :ltest {:aliases [:env-development-test :common-test]} + :monorepo {:app-dir "automaton/automaton_core"} + :publication {:as-lib hephaistox/automaton-core + :gha-container {:account "hephaistox" + :repo-branch "main" + :repo-url "git@github.com:hephaistox/gha_image.git" + :workflows [".github/workflows/commit_validation.yml"]} + :jar {:class-dir "target/classes" + :excluded-aliases #{} + :target-filename "target/%s-%s.jar"} + :major-version "0.0.%d" + :repo {:address "git@github.com:hephaistox/automaton-core.git" + :branch "main"} :shadow-cljs {:target-build nil}}} diff --git a/deps.edn b/deps.edn index 484f5155..7a62569f 100644 --- a/deps.edn +++ b/deps.edn @@ -1,60 +1,44 @@ -{:aliases - {:bb-deps {:extra-deps - {hephaistox/automaton-build-app - {:git/sha "797da62e6cecd368b7ec4d9a8672117806606402", - :git/url - "git@github.com:hephaistox/automaton-build-app.git"}}}, - :build {:extra-deps - {hephaistox/automaton-build-app - {:git/url "https://github.com/hephaistox/automaton-core.git", - :sha "797da62e6cecd368b7ec4d9a8672117806606402"}}}, - :cljs-deps {:extra-deps {binaryage/devtools {:mvn/version "1.0.7"}, - cider/cider-nrepl {:mvn/version "0.21.1"}, - thheller/shadow-cljs {:mvn/version "2.25.9"}}, - :extra-paths ["src/cljs" "src/cljc" "resources" "test/cljs" - "test/cljc"]}, - :common-test - {:exec-fn cognitect.test-runner.api/test, - :extra-deps {com.cognitect/test-runner - {:git/url "https://github.com/cognitect-labs/test-runner", - :sha "7284cda41fb9edc0f3bc6b6185cfb7138fc8a023"}, - org.clojure/tools.namespace #:mvn{:version "1.4.4"}, - org.clojure/tools.reader #:mvn{:version "1.3.6"}}, - :extra-paths ["test/clj" "test/cljc" "test/resources"], - :jvm-opts ["-Dheph-conf=env/test/config.edn" - "-Dheph-common-conf=env/common_config.edn"]}, - :env-development-repl - {:extra-deps {cider/cider-nrepl {:mvn/version "0.21.1"}, - org.clojure/core.async {:mvn/version "1.6.681"}}, - :extra-paths ["env/development/resources" "env/development/src/clj" - "env/development/src/cljc"], - :jvm-opts ["-Dheph-conf=env/development/config.edn" - "-Dheph-common-conf=env/common_config.edn"], - :main-opts ["-m" "automaton-core.repl-core"]}, - :env-development-test - {:jvm-opts - ["-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory" - "-Dhephaistox-in-test=true" - "-Dlog4j.configurationFile=resources/log_config/appenders.properties,resources/log_config/logging-tests.properties"], - :main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/clj" - "-d" "test/cljc"]}}, - :deps {babashka/fs #:mvn{:version "0.4.19"}, - babashka/process #:mvn{:version "0.5.21"}, - com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.3.0"}, - com.taoensso/encore #:mvn{:version "3.62.1"}, - com.taoensso/tempura #:mvn{:version "1.5.3"}, - danlentz/clj-uuid #:mvn{:version "0.1.9"}, - io.sentry/sentry {:mvn/version "6.32.0"}, - io.sentry/sentry-clj #:mvn{:version "6.28.200"}, - lambdaisland/uri {:mvn/version "1.16.134"}, - metosin/malli #:mvn{:version "0.13.0"}, - mount/mount #:mvn{:version "0.1.17"}, - nrepl/nrepl #:mvn{:version "1.0.0"}, - org.apache.logging.log4j/log4j-api #:mvn{:version "2.20.0"}, - org.apache.logging.log4j/log4j-core #:mvn{:version "2.20.0"}, - org.apache.logging.log4j/log4j-slf4j2-impl #:mvn{:version "2.20.0"}, - org.clojure/clojure #:mvn{:version "1.11.1"}, - org.clojure/tools.cli #:mvn{:version "1.0.219"}, - org.clojure/tools.logging #:mvn{:version "1.2.4"}, - refactor-nrepl/refactor-nrepl #:mvn{:version "3.6.0"}}, +{:aliases {:bb-deps {:extra-deps {hephaistox/automaton-build-app {:git/url "https://github.com/hephaistox/automaton-build-app.git" + :sha "db42465833ea1c5c40339fddafefcea461dc21c5"}}} + :build {:extra-deps {hephaistox/automaton-build-app {:git/url "https://github.com/hephaistox/automaton-build-app.git" + :sha "db42465833ea1c5c40339fddafefcea461dc21c5"}}} + :cljs-deps {:extra-deps {binaryage/devtools {:mvn/version "1.0.7"} + cider/cider-nrepl {:mvn/version "0.21.1"} + thheller/shadow-cljs {:mvn/version "2.25.9"}} + :extra-paths ["src/cljs" "src/cljc" "resources" "test/cljs" "test/cljc"]} + :common-test {:exec-fn cognitect.test-runner.api/test + :extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner" + :sha "7284cda41fb9edc0f3bc6b6185cfb7138fc8a023"} + org.clojure/tools.namespace #:mvn{:version "1.4.4"} + org.clojure/tools.reader #:mvn{:version "1.3.6"}} + :extra-paths ["test/clj" "test/cljc" "test/resources"] + :jvm-opts ["-Dheph-conf=env/test/config.edn" "-Dheph-common-conf=env/common_config.edn"]} + :env-development-repl {:extra-deps {cider/cider-nrepl {:mvn/version "0.21.1"} + org.clojure/core.async {:mvn/version "1.6.681"}} + :extra-paths ["env/development/resources" "env/development/src/clj" "env/development/src/cljc"] + :jvm-opts ["-Dheph-conf=env/development/config.edn" "-Dheph-common-conf=env/common_config.edn"] + :main-opts ["-m" "automaton-core.repl-core"]} + :env-development-test + {:jvm-opts ["-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory" "-Dhephaistox-in-test=true" + "-Dlog4j.configurationFile=resources/log_config/appenders.properties,resources/log_config/logging-tests.properties"] + :main-opts ["-m" "cognitect.test-runner" "-r" ".*-test.*" "-d" "test/clj" "-d" "test/cljc"]}} + :deps {babashka/fs #:mvn{:version "0.4.19"} + babashka/process #:mvn{:version "0.5.21"} + com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.3.0"} + com.taoensso/encore #:mvn{:version "3.62.1"} + com.taoensso/tempura #:mvn{:version "1.5.3"} + danlentz/clj-uuid #:mvn{:version "0.1.9"} + io.sentry/sentry {:mvn/version "6.32.0"} + io.sentry/sentry-clj #:mvn{:version "6.28.200"} + lambdaisland/uri {:mvn/version "1.16.134"} + metosin/malli #:mvn{:version "0.13.0"} + mount/mount #:mvn{:version "0.1.17"} + nrepl/nrepl #:mvn{:version "1.0.0"} + org.apache.logging.log4j/log4j-api #:mvn{:version "2.20.0"} + org.apache.logging.log4j/log4j-core #:mvn{:version "2.20.0"} + org.apache.logging.log4j/log4j-slf4j2-impl #:mvn{:version "2.20.0"} + org.clojure/clojure #:mvn{:version "1.11.1"} + org.clojure/tools.cli #:mvn{:version "1.0.219"} + org.clojure/tools.logging #:mvn{:version "1.2.4"} + refactor-nrepl/refactor-nrepl #:mvn{:version "3.6.0"}} :paths ["src/clj" "src/cljc" "resources" "src/cljs"]} diff --git a/docs/code/stats.md b/docs/code/stats.md index e0ea7395..abcd35f6 100644 --- a/docs/code/stats.md +++ b/docs/code/stats.md @@ -1,4 +1,4 @@ # That statistics counts number of line of code -* clj-test-nb-lines - 2314 -* clj-total-nb-lines - 7213 -* ratio-in-pct - 47.23 \ No newline at end of file +* clj-test-nb-lines - 1914 +* clj-total-nb-lines - 6151 +* ratio-in-pct - 45.17 \ No newline at end of file diff --git a/env/development/resources/version.edn b/env/development/resources/version.edn index 7a188105..125a29cc 100644 --- a/env/development/resources/version.edn +++ b/env/development/resources/version.edn @@ -1,3 +1,5 @@ ;; Last generated version, note a failed push consume a number Sat Oct 28 ;; 18:55:52 CEST 2023 -{:major-version "0.0.-1", :minor-version 6, :version "0.0.6"} \ No newline at end of file +{:major-version "0.0.-1" + :minor-version 6 + :version "0.0.6"} \ No newline at end of file diff --git a/env/test/config.edn b/env/test/config.edn new file mode 100644 index 00000000..de407ced --- /dev/null +++ b/env/test/config.edn @@ -0,0 +1 @@ +{:env :test} diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 6489a9c8..9b9ee270 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -1,12 +1,11 @@ -{:builds - {:browser-test {:ns-regexp "-test$", - :runner-ns shadow.test.browser, - :target :browser-test, - :test-dir "target/browser-test"}, - :ltest {:ns-regexp "-test$", :output-to "target/ltest.js", :target :karma}}, - :deps {:aliases [:cljs-deps]}, - :dev-http {8012 ["target/browser-test"]}, - :jvm-opts - ["-Xmx1G" - "-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory"], +{:builds {:browser-test {:ns-regexp "-test$" + :runner-ns shadow.test.browser + :target :browser-test + :test-dir "target/browser-test"} + :ltest {:ns-regexp "-test$" + :output-to "target/ltest.js" + :target :karma}} + :deps {:aliases [:cljs-deps]} + :dev-http {8012 ["target/browser-test"]} + :jvm-opts ["-Xmx1G" "-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory"] :nrepl {:port 8011}} diff --git a/src/clj/automaton_core/adapters/build_config.clj b/src/clj/automaton_core/adapters/build_config.clj index 22bf56e3..ba504589 100644 --- a/src/clj/automaton_core/adapters/build_config.clj +++ b/src/clj/automaton_core/adapters/build_config.clj @@ -25,14 +25,7 @@ * none Returns the list of directories with `build_config.edn` in it" ([config-path] - (->> (files/search-files config-path - (str "{" - build-config-filename - ",*/" - build-config-filename - ",*/*/" - build-config-filename - "}")) + (->> (files/search-files config-path (str "{" build-config-filename ",*/" build-config-filename ",*/*/" build-config-filename "}")) flatten (filter (comp not nil?)))) ([] (search-for-build-config ""))) @@ -44,7 +37,7 @@ (let [edn-file (edn-utils/read-edn build-filename)] (when-let [lib (get-in edn-file [:publication :as-lib])] (when (some #{lib} accepted-libs) - {:lib lib, + {:lib lib :dir (get-in edn-file [:monorepo :app-dir])})))) build-configs)] libs)) diff --git a/src/clj/automaton_core/adapters/commands.clj b/src/clj/automaton_core/adapters/commands.clj index b35e32e7..53646839 100644 --- a/src/clj/automaton_core/adapters/commands.clj +++ b/src/clj/automaton_core/adapters/commands.clj @@ -7,17 +7,14 @@ [clojure.java.io :as io] [clojure.string :as str])) -(def size-command - "Size of the command line to be managed, measured on mcbook pro" - 185) +(def size-command "Size of the command line to be managed, measured on mcbook pro" 185) -(def commands-schema - [:vector - [:or [:tuple [:vector [:string]] :map] [:tuple [:vector [:string]]]]]) +(def commands-schema [:vector [:or [:tuple [:vector [:string]] :map] [:tuple [:vector [:string]]]]]) (def glob-command-params "Command params globals" - {:in :inherit, :blocking? true}) + {:in :inherit + :blocking? true}) (defn stream-execute-command* "Command processing function, that's redirecting output to a log fn as a stream, to allow information to be viewed during operation. @@ -26,7 +23,8 @@ https://clojurians.slack.com/archives/CLX41ASCS/p1694600409401029" [command dir] (let [proc (process/process command - {:dir dir, :shutdown process/destroy-tree})] + {:dir dir + :shutdown process/destroy-tree})] (future (with-open [rdr (io/reader (:out proc))] (binding [*in* rdr] (loop [] @@ -42,12 +40,12 @@ "execute-command core function that's used to process the command." [command dir out file in blocking?] (let [proc (process/process command - {:dir dir, - :shutdown process/destroy-tree, - :out out, - :out-file file, - :err out, - :err-file file, + {:dir dir + :shutdown process/destroy-tree + :out out + :out-file file + :err out + :err-file file :in in})] (if blocking? (process/check proc) proc))) @@ -59,9 +57,9 @@ * `cmds-params` list of parmeters set once for the global command" [[command cmd-params] cmds-params] (let [merged-params (merge glob-command-params cmd-params cmds-params) - execute-command-params {:command command, - :merged-params merged-params, - :cmd-params cmd-params, + execute-command-params {:command command + :merged-params merged-params + :cmd-params cmd-params :cmds-params cmds-params} {:keys [dir out in blocking? stream?]} merged-params filename out @@ -72,29 +70,16 @@ :else :inherit) blocking? (or (= out :string) blocking?)] (files/create-dirs dir) - (log/debug-format "%s - in directory `%s`" - str-command - (files/absolutize dir)) - (when (and (not= out :string) filename) - (log/info " -> output = " filename)) - (try (if stream? - (stream-execute-command* command dir) - (execute-command* command dir out file in blocking?)) - (catch java.io.IOException e - (throw (ex-info (str "Directory does not exist") - (merge {:exception e} execute-command-params)))) + (log/debug-format "%s - in directory `%s`" str-command (files/absolutize dir)) + (when (and (not= out :string) filename) (log/info " -> output = " filename)) + (try (if stream? (stream-execute-command* command dir) (execute-command* command dir out file in blocking?)) + (catch java.io.IOException e (throw (ex-info (str "Directory does not exist") (merge {:exception e} execute-command-params)))) (catch clojure.lang.ExceptionInfo e (let [{:keys [exit type]} (ex-data e)] (if (= type :babashka.process/error) - (throw (ex-info (str "Command `" str-command - "` failed on exit code " exit) - (merge execute-command-params {:exception e}))) - (throw (ex-info (str "Command `" str-command "` failed ") - (merge execute-command-params - {:exception e})))))) - (catch Exception e - (throw (ex-info (str "Command `" str-command "` failed ") - (merge execute-command-params {:exception e}))))))) + (throw (ex-info (str "Command `" str-command "` failed on exit code " exit) (merge execute-command-params {:exception e}))) + (throw (ex-info (str "Command `" str-command "` failed ") (merge execute-command-params {:exception e})))))) + (catch Exception e (throw (ex-info (str "Command `" str-command "` failed ") (merge execute-command-params {:exception e}))))))) (defn exec-cmds "Execute commands with their default parameters @@ -106,6 +91,4 @@ ([commands] (exec-cmds commands {})) ([commands default-params] (schema/schema-valid-or-throw commands-schema commands "Malformed command") - (apply str - (doall (for [command commands] - (:out (execute-command command default-params))))))) + (apply str (doall (for [command commands] (:out (execute-command command default-params))))))) diff --git a/src/clj/automaton_core/adapters/deps_edn.clj b/src/clj/automaton_core/adapters/deps_edn.clj index 58f9cf4f..6e6f4d17 100644 --- a/src/clj/automaton_core/adapters/deps_edn.clj +++ b/src/clj/automaton_core/adapters/deps_edn.clj @@ -13,10 +13,7 @@ [app-dir] (files/create-file-path app-dir deps-edn)) -(defn load-deps - "Load the current project `deps.edn` files" - [] - (edn-utils/read-edn deps-edn)) +(defn load-deps "Load the current project `deps.edn` files" [] (edn-utils/read-edn deps-edn)) (defn load-deps-edn "Load the deps.edn file of the app, passed as a parameter, @@ -36,9 +33,7 @@ (if-let [old-commit-id (get-in deps-edn [:deps as-lib :git/sha])] (if (= commit-id old-commit-id) (do (log/trace "Skip update as it already uptodate") deps-edn) - (do - (log/trace "Change commit from `" old-commit-id "` to `" commit-id "`") - (assoc-in deps-edn [:deps as-lib :git/sha] commit-id))) + (do (log/trace "Change commit from `" old-commit-id "` to `" commit-id "`") (assoc-in deps-edn [:deps as-lib :git/sha] commit-id))) (do (log/trace "Skip as it does not use lib `%s:%s`") deps-edn))) (defn extract-paths @@ -47,13 +42,10 @@ Params: * `deps-edn` content the deps edn file to search extract path in * `excluded-aliases` is a collection of aliases to exclude" - ([{:keys [paths aliases], :as _deps-edn} excluded-aliases] + ([{:keys [paths aliases] + :as _deps-edn} excluded-aliases] (let [selected-aliases (apply dissoc aliases excluded-aliases) - alias-paths (mapcat (fn [[_alias-name paths]] - (apply concat - (vals (select-keys paths - [:extra-paths :paths])))) - selected-aliases)] + alias-paths (mapcat (fn [[_alias-name paths]] (apply concat (vals (select-keys paths [:extra-paths :paths])))) selected-aliases)] (->> alias-paths (concat paths) sort @@ -66,11 +58,11 @@ Params: * `deps-edn` is the content of the file to search dependencies in * `excluded-aliases` is a collection of aliases to exclude" - [{:keys [deps aliases], :as _deps-edn} excluded-aliases] + [{:keys [deps aliases] + :as _deps-edn} excluded-aliases] (let [selected-aliases (apply dissoc aliases excluded-aliases)] (->> selected-aliases - (map (fn [[_ alias-defs]] - (vals (select-keys alias-defs [:extra-deps :deps])))) + (map (fn [[_ alias-defs]] (vals (select-keys alias-defs [:extra-deps :deps])))) (apply concat) (into {}) (concat deps) diff --git a/src/clj/automaton_core/adapters/edn_utils.clj b/src/clj/automaton_core/adapters/edn_utils.clj index 136ea92c..6f2117ad 100644 --- a/src/clj/automaton_core/adapters/edn_utils.clj +++ b/src/clj/automaton_core/adapters/edn_utils.clj @@ -26,16 +26,16 @@ ([edn-filename loader-fn] (let [edn-filename (files/absolutize edn-filename) _ (log/trace "Load file:" edn-filename) - edn-content - (try (loader-fn edn-filename) - (catch Exception e - (throw (ex-info (format "Unable to load the file `%s`" - edn-filename) - {:caused-by e, :file-name edn-filename}))))] + edn-content (try (loader-fn edn-filename) + (catch Exception e + (throw (ex-info (format "Unable to load the file `%s`" edn-filename) + {:caused-by e + :file-name edn-filename}))))] (try (edn/read-string edn-content) (catch Exception e (throw (ex-info (format "File `%s` is not an edn" edn-filename) - {:caused-by e, :file-name edn-filename})))))) + {:caused-by e + :file-name edn-filename})))))) ([edn-filename] (read-edn edn-filename files/read-file))) (defn read-edn-or-nil @@ -43,8 +43,7 @@ * return nil if the file does not exist or is invalid * `file` could be a string representing the name of the file to load or a (io/resource) object representing the name of the file to load" - ([edn-file-name loader-fn] - (try (read-edn edn-file-name loader-fn) (catch Exception _ nil))) + ([edn-file-name loader-fn] (try (read-edn edn-file-name loader-fn) (catch Exception _ nil))) ([edn-file-name] (read-edn-or-nil edn-file-name slurp))) (defn spit-edn @@ -62,8 +61,8 @@ content (catch Exception e (throw (ex-info "Impossible to update the .edn file" - {:deps-edn-filename edn-filename, - :exception e, + {:deps-edn-filename edn-filename + :exception e :content content}))))) ([deps-edn-filename content] (spit-edn deps-edn-filename content nil))) @@ -76,23 +75,18 @@ * `header` optional is a string added at the top of the file Note: the content will be formatted thanks to `automaton.core.adapters.code-formatter` " - ([edn-filename update-fn header] - (let [bb-config (read-edn edn-filename)] - (spit-edn edn-filename (update-fn bb-config) header))) + ([edn-filename update-fn header] (let [bb-config (read-edn edn-filename)] (spit-edn edn-filename (update-fn bb-config) header))) ([edn-filename update-fn] (update-edn-content edn-filename update-fn nil))) (defn spit-edn-or-file "Spit the file as an edn if it is a clojure file, or spit it with no modification otherwise" [filename rendered-content] - (if (is-clojure-like-file filename) - (spit-edn filename rendered-content) - (files/spit-file filename rendered-content))) + (if (is-clojure-like-file filename) (spit-edn filename rendered-content) (files/spit-file filename rendered-content))) (defn create-tmp-edn "Create a temporary file directory string with edn extension" [] - (let [edn-file (files/create-file-path (conf/read-param [:log :spitted-edns]) - (str (uuid/time-based-uuid) ".edn"))] + (let [edn-file (files/create-file-path (conf/read-param [:log :spitted-edns]) (str (uuid/time-based-uuid) ".edn"))] (files/create-dirs (files/extract-path edn-file)) edn-file)) diff --git a/src/clj/automaton_core/adapters/env_variables.clj b/src/clj/automaton_core/adapters/env_variables.clj index 24aadf14..76f35e13 100644 --- a/src/clj/automaton_core/adapters/env_variables.clj +++ b/src/clj/automaton_core/adapters/env_variables.clj @@ -7,7 +7,4 @@ [var-name] (System/getenv var-name)) -(defn get-envs - "A map of all available environment variables" - [] - (into {} (System/getenv))) +(defn get-envs "A map of all available environment variables" [] (into {} (System/getenv))) diff --git a/src/clj/automaton_core/adapters/files.clj b/src/clj/automaton_core/adapters/files.clj index 0b8abc1c..cdeda144 100644 --- a/src/clj/automaton_core/adapters/files.clj +++ b/src/clj/automaton_core/adapters/files.clj @@ -7,10 +7,8 @@ [babashka.fs :as fs] [clojure.string :as str])) -(def file-separator - "Symbol to separate directories. - Is usually `/` on linux based OS And `\\` on windows based ones" - fs/file-separator) +(def file-separator "Symbol to separate directories. + Is usually `/` on linux based OS And `\\` on windows based ones" fs/file-separator) (defn absolutize "Transform a file or dir name in an absolute path" @@ -25,20 +23,14 @@ [file-list] (doseq [file file-list] (if (fs/directory? file) - (do (log/debug "Directory " (absolutize file) " is deleted") - (fs/delete-tree file)) - (do (log/debug "File " (absolutize file) " is deleted") - (fs/delete-if-exists file))))) + (do (log/debug "Directory " (absolutize file) " is deleted") (fs/delete-tree file)) + (do (log/debug "File " (absolutize file) " is deleted") (fs/delete-if-exists file))))) (defn- copy-files-or-dir-validate "Internal function to validate data aof copy files or dir" [files] - (when-not (and (sequential? files) - (every? #(or (string? %) (= java.net.URL (class %))) files)) - (throw - (ex-info - "The `files` parameter should be a sequence of string or `java.net.URL`" - {:files files})))) + (when-not (and (sequential? files) (every? #(or (string? %) (= java.net.URL (class %))) files)) + (throw (ex-info "The `files` parameter should be a sequence of string or `java.net.URL`" {:files files})))) (defn copy-files-or-dir "Copy the files, even if they are directories to the target @@ -51,61 +43,45 @@ (doseq [file files] (log/debug "Copy from " file " to " target-dir) (if (fs/directory? file) - (do (log/trace (format "Copy `%s` to `%s`" - (absolutize file) - (absolutize target-dir))) + (do (log/trace (format "Copy `%s` to `%s`" (absolutize file) (absolutize target-dir))) (fs/copy-tree file target-dir - {:replace-existing true, :copy-attributes true})) - (do (log/trace (format "Copy `%s` to `%s`" - (absolutize file) - (absolutize target-dir))) + {:replace-existing true + :copy-attributes true})) + (do (log/trace (format "Copy `%s` to `%s`" (absolutize file) (absolutize target-dir))) (fs/copy file target-dir - {:replace-existing true, :copy-attributes true})))) + {:replace-existing true + :copy-attributes true})))) (catch Exception e - (throw (ex-info - "Unexpected exception during copy" - {:exception e, :files files, :target-dir target-dir}))))) + (throw (ex-info "Unexpected exception during copy" + {:exception e + :files files + :target-dir target-dir}))))) -(defn directory-exists? - "Check directory existance" - [directory-path] - (and (fs/exists? directory-path) (fs/directory? directory-path))) +(defn directory-exists? "Check directory existance" [directory-path] (and (fs/exists? directory-path) (fs/directory? directory-path))) -(defn is-existing-file? - "Check if this the path exist and is not a directory" - [path] - (and (fs/exists? path) (not (fs/directory? path)))) +(defn is-existing-file? "Check if this the path exist and is not a directory" [path] (and (fs/exists? path) (not (fs/directory? path)))) -(defn is-existing-dir? - "Check if this the path exist and is a directory" - [path] - (and (fs/exists? path) (fs/directory? path))) +(defn is-existing-dir? "Check if this the path exist and is a directory" [path] (and (fs/exists? path) (fs/directory? path))) (defn create-dirs "Create a directory" [dir] (when (is-existing-file? dir) - (throw - (ex-info - (format - "Can't create a directory `%s` as a file already exists with that name" - (absolutize dir)) - {:dir dir}))) + (throw (ex-info (format "Can't create a directory `%s` as a file already exists with that name" (absolutize dir)) {:dir dir}))) (when-not (fs/exists? dir) (try (fs/create-dirs dir) (catch Exception e - (throw (ex-info - (format "The parameter is not a valid directory: `%s`" dir) - {:dir (absolutize dir), :exception e}))))) + (throw (ex-info (format "The parameter is not a valid directory: `%s`" dir) + {:dir (absolutize dir) + :exception e}))))) true) (defn remove-trailing-separator "If exists, remove the trailing separator in a path, remove unwanted spaces either" [path] - (let [path (str/trim path)] - (str/replace path (re-pattern (str file-separator "*$")) ""))) + (let [path (str/trim path)] (str/replace path (re-pattern (str file-separator "*$")) ""))) (defn create-file-path "Creates a path with the list of parameters. @@ -124,8 +100,7 @@ "Creates a path with the list of parameters. Removes the empty strings, add needed separators, including the trailing ones" [& dirs] - (when-let [file-path (apply create-file-path dirs)] - (str file-path file-separator))) + (when-let [file-path (apply create-file-path dirs)] (str file-path file-separator))) (defn search-files "Search files. @@ -137,13 +112,17 @@ ([root pattern options] (when-not (directory-exists? root) (throw (ex-info (str root " is expected to be a directory") - {:root root, :pattern pattern, :options options}))) + {:root root + :pattern pattern + :options options}))) (into [] (map str - (fs/glob root - pattern - (merge {:hidden true, :recursive true, :follow-links true} - options))))) + (fs/glob root + pattern + (merge {:hidden true + :recursive true + :follow-links true} + options))))) ([root pattern] (search-files root pattern {}))) (defn list-subdir @@ -152,20 +131,11 @@ (->> (fs/list-dir root fs/directory?) (map str))) -(defn file-prefix - "Adds `file:` as a prefix to the string. Usefull when java io resource type of path is needed" - [path] - (str "file:" path)) +(defn file-prefix "Adds `file:` as a prefix to the string. Usefull when java io resource type of path is needed" [path] (str "file:" path)) -(defn for-each - "Apply fn-each on each files in a directory" - [dir fn-each] - (doseq [file (fs/list-dir dir)] (fn-each (str file)))) +(defn for-each "Apply fn-each on each files in a directory" [dir fn-each] (doseq [file (fs/list-dir dir)] (fn-each (str file)))) -(defn change-extension - "Change the extension" - [file-name new-extension] - (str (fs/strip-ext file-name) new-extension)) +(defn change-extension "Change the extension" [file-name new-extension] (str (fs/strip-ext file-name) new-extension)) (defn modified-since "Return true if anchor is older than one of the file in file-set" @@ -176,10 +146,7 @@ "Use the relative-name to create in file in the same directory than source-file" [source-file relative-name] (let [source-subdirs (fs/components source-file) - subdirs (mapv str - (if (fs/directory? source-file) - source-subdirs - (butlast source-subdirs))) + subdirs (mapv str (if (fs/directory? source-file) source-subdirs (butlast source-subdirs))) new-name (conj subdirs relative-name)] (apply create-file-path new-name))) @@ -207,8 +174,8 @@ (fs/move src (fs/path dst)) (catch Exception e (throw (ex-info "Impossible to rename the file" - {:src (absolutize src), - :dst (absolutize dst), + {:src (absolutize src) + :dst (absolutize dst) :exception e}))))) (defn rename-dir @@ -218,8 +185,8 @@ (fs/move src (fs/path dst)) (catch Exception e (throw (ex-info "Impossible to rename the directory" - {:src (absolutize src), - :dst (absolutize dst), + {:src (absolutize src) + :dst (absolutize dst) :exception e}))))) (defn remove-file @@ -228,7 +195,8 @@ (try (fs/delete-if-exists filename) (catch Exception e (throw (ex-info "Impossible to remove the file" - {:filename filename, :exception e}))))) + {:filename filename + :exception e}))))) (defn read-file "Read the file `target-filename`" @@ -237,7 +205,8 @@ (try (slurp target-filename) (catch Exception e (throw (ex-info "Impossible to load the file" - {:target-filename target-filename, :exception e}))))) + {:target-filename target-filename + :exception e}))))) (defn file-ized "Transform a name, like a namespace name or application name, in a directory compatible names" @@ -247,8 +216,7 @@ (defn add-suffix "Add a suffix of the filename before the extension" [filename suffix] - (let [[_ prefix extension] (re-find #"(.*)(\..*)" filename)] - (str/join [prefix suffix extension]))) + (let [[_ prefix extension] (re-find #"(.*)(\..*)" filename)] (str/join [prefix suffix extension]))) (defn- rename-recursively-attempt "Make one attempt for file renaming. @@ -264,12 +232,8 @@ new-filename (str/replace filename pattern pattern-replacement)] (if (= new-filename filename) (recur (rest files) modification?) - (cond (is-existing-file? filename) (do (rename-file filename - new-filename) - (recur (rest files) true)) - (is-existing-dir? filename) (do (rename-dir filename - new-filename) - (recur (rest files) true)) + (cond (is-existing-file? filename) (do (rename-file filename new-filename) (recur (rest files) true)) + (is-existing-dir? filename) (do (rename-dir filename new-filename) (recur (rest files) true)) :else (recur (rest files) modification?))))))) (defn rename-recursively @@ -279,23 +243,12 @@ * `pattern` is to find content in the namespace, for instance, as seen in [java pattern](https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html), e.g. #\"foo(.*)bar\" * `pattern-replacement` is what to replace, according to the [replace specification](https://clojuredocs.org/clojure.string/replace). e.g. \"foo_$1_bar\" " [target-dir file-filter pattern pattern-replacement] - (log/debug "Rename files and directories in " - target-dir - " , from `" - pattern - "` to `" - pattern-replacement - "`") + (log/debug "Rename files and directories in " target-dir " , from `" pattern "` to `" pattern-replacement "`") (let [pattern (remove-trailing-separator (str pattern)) - pattern-replacement (remove-trailing-separator (str - pattern-replacement))] + pattern-replacement (remove-trailing-separator (str pattern-replacement))] (loop [iterations-left 30] (if (> iterations-left 0) - (when (rename-recursively-attempt target-dir - file-filter - pattern - pattern-replacement) - (recur (dec iterations-left))) + (when (rename-recursively-attempt target-dir file-filter pattern pattern-replacement) (recur (dec iterations-left))) (log/warn "Infinite loop detected during renaming"))))) (defn create-files-map @@ -307,8 +260,7 @@ (log/debug "Create files-map for " target-dir " with parameter " pattern) (->> (search-files target-dir pattern) (filter is-existing-file?) - (map (fn [filename] [(str (absolutize filename)) - (read-file (absolutize filename))])) + (map (fn [filename] [(str (absolutize filename)) (read-file (absolutize filename))])) (into {}))) (defn delete-files-starting-with @@ -320,9 +272,7 @@ (doseq [[filename file-content] files-map] (let [first-line (-> (str/split-lines file-content) first)] - (when (re-find starting-regexp first-line) - (remove-file filename) - (log/trace "File" filename " has been removed"))))) + (when (re-find starting-regexp first-line) (remove-file filename) (log/trace "File" filename " has been removed"))))) (defn spit-file "Spit the file, the directory where to store the file is created if necessary @@ -340,9 +290,7 @@ * none Returns the string of the directory path" [] - (let [tmp-dir (apply create-dir-path - [(conf/read-param [:tests :tmp-dirs] "tmp/tests") - (str (uuid/time-based-uuid))])] + (let [tmp-dir (apply create-dir-path [(conf/read-param [:tests :tmp-dirs] "tmp/tests") (str (uuid/time-based-uuid))])] (fs/create-dirs tmp-dir) tmp-dir)) @@ -352,10 +300,7 @@ * `dirs` sequence of string of directories" [dirs] (apply vector - (mapcat (fn [sub-dir] - (let [sub-dir-rpath (absolutize sub-dir)] - (when (directory-exists? sub-dir-rpath) [sub-dir-rpath]))) - dirs))) + (mapcat (fn [sub-dir] (let [sub-dir-rpath (absolutize sub-dir)] (when (directory-exists? sub-dir-rpath) [sub-dir-rpath]))) dirs))) (defn empty-path? "Is the directory empty @@ -382,10 +327,7 @@ (spit filename formatted-data) (format "See file `%s` for details" (absolutize filename)))) -(defn file-name - "Return the file name without the path" - [path] - (fs/file-name path)) +(defn file-name "Return the file name without the path" [path] (fs/file-name path)) (defn write-file "Write `content` in the file `target-file`" @@ -394,4 +336,5 @@ (try (spit target-filename content) (catch Exception e (throw (ex-info "Impossible to write the file" - {:target-filename target-filename, :exception e}))))) + {:target-filename target-filename + :exception e}))))) diff --git a/src/clj/automaton_core/adapters/java_properties.clj b/src/clj/automaton_core/adapters/java_properties.clj index f079da43..278407b8 100644 --- a/src/clj/automaton_core/adapters/java_properties.clj +++ b/src/clj/automaton_core/adapters/java_properties.clj @@ -1,12 +1,8 @@ (ns automaton-core.adapters.java-properties "Adapter to java properties") -(defn get-java-properties - "Get the java properties" - [] - (into {} (System/getProperties))) +(defn get-java-properties "Get the java properties" [] (into {} (System/getProperties))) (defn get-java-property "Get a java property named `property-name`, if not found return `default-value`" - ([property-name default-value] - (or (System/getProperty property-name) default-value)) + ([property-name default-value] (or (System/getProperty property-name) default-value)) ([property-name] (System/getProperty property-name))) diff --git a/src/clj/automaton_core/adapters/schema.clj b/src/clj/automaton_core/adapters/schema.clj index 210111bc..b91bf982 100644 --- a/src/clj/automaton_core/adapters/schema.clj +++ b/src/clj/automaton_core/adapters/schema.clj @@ -21,7 +21,7 @@ [schema data msg] (when-not (schema-valid schema data) (throw (ex-info msg - {:data data, + {:data data :reason (-> schema (malli/explain data) (malli-error/humanize))}))) diff --git a/src/clj/automaton_core/adapters/time.clj b/src/clj/automaton_core/adapters/time.clj index 6fad1004..ed0edb86 100644 --- a/src/clj/automaton_core/adapters/time.clj +++ b/src/clj/automaton_core/adapters/time.clj @@ -4,8 +4,4 @@ Like formatting the date from #inst to str and way back Will be a proxy for `clojure.instant`, `java.text.SimpleDateFormt`") -(defn now-str - "Return the time we are now" - [] - (.format (java.text.SimpleDateFormat. "EEE MMM d HH:mm:ss zzz yyyy") - (java.util.Date.))) +(defn now-str "Return the time we are now" [] (.format (java.text.SimpleDateFormat. "EEE MMM d HH:mm:ss zzz yyyy") (java.util.Date.))) diff --git a/src/clj/automaton_core/adapters/version.clj b/src/clj/automaton_core/adapters/version.clj index 2dd4cc3b..07d77e0d 100644 --- a/src/clj/automaton_core/adapters/version.clj +++ b/src/clj/automaton_core/adapters/version.clj @@ -5,9 +5,7 @@ (def release :release) -(def version-filename - "The name of the version file to be found in ready to be deployed application" - "version.edn") +(def version-filename "The name of the version file to be found in ready to be deployed application" "version.edn") (defn slurp-version "Get the version of the current application, if not found a local dev value is given" diff --git a/src/clj/automaton_core/configuration.clj b/src/clj/automaton_core/configuration.clj index 29c10612..5edf855c 100644 --- a/src/clj/automaton_core/configuration.clj +++ b/src/clj/automaton_core/configuration.clj @@ -28,9 +28,7 @@ (let [conf (simple-files/make-simple-conf)] (log/trace "Configuration component is started") conf) - (catch Throwable e - (log/fatal (ex-info "Configuration component failed" {:error e})) - (throw e)))) + (catch Throwable e (log/fatal (ex-info "Configuration component failed" {:error e})) (throw e)))) (defn stop-conf [] (log/debug "Stop configuration component")) @@ -38,18 +36,10 @@ (defn read-param ([key-path default-value] - (cond - (not (vector? key-path)) - (do (log/warn-format "Key path should be a vector. I found " key-path) - default-value) - (instance? mount.core.NotStartedState @conf-state) - (do - (log/warn-format - "Unexpected error in configuration, component configuration is not started" - @conf-state) - default-value) - :else (let [value (configuration-prot/read-conf-param @conf-state - key-path)] - (log/trace "Read key-path " key-path " = " value) - (or value default-value)))) + (cond (not (vector? key-path)) (do (log/warn-format "Key path should be a vector. I found " key-path) default-value) + (instance? mount.core.NotStartedState @conf-state) + (do (log/warn-format "Unexpected error in configuration, component configuration is not started" @conf-state) default-value) + :else (let [value (configuration-prot/read-conf-param @conf-state key-path)] + (log/trace "Read key-path " key-path " = " value) + (or value default-value)))) ([key-path] (read-param key-path nil))) diff --git a/src/clj/automaton_core/configuration/edn_read.clj b/src/clj/automaton_core/configuration/edn_read.clj index aa39adb6..10943852 100644 --- a/src/clj/automaton_core/configuration/edn_read.clj +++ b/src/clj/automaton_core/configuration/edn_read.clj @@ -17,12 +17,5 @@ [edn-filename] (let [edn-filename (when edn-filename (str (fs/absolutize edn-filename))) _ (log/trace "Load file:" edn-filename) - edn-content (try (slurp edn-filename) - (catch Exception _ - (log/warn-format "Unable to load the file `%s`" - edn-filename) - nil))] - (try (edn/read-string edn-content) - (catch Exception _ - (log/warn-format "File `%s` is not a valid edn" edn-filename) - nil)))) + edn-content (try (slurp edn-filename) (catch Exception _ (log/warn-format "Unable to load the file `%s`" edn-filename) nil))] + (try (edn/read-string edn-content) (catch Exception _ (log/warn-format "File `%s` is not a valid edn" edn-filename) nil)))) diff --git a/src/clj/automaton_core/configuration/protocol.clj b/src/clj/automaton_core/configuration/protocol.clj index 9d789e82..efa0657c 100644 --- a/src/clj/automaton_core/configuration/protocol.clj +++ b/src/clj/automaton_core/configuration/protocol.clj @@ -2,4 +2,4 @@ (defprotocol Conf (read-conf-param [this key-path] - "Read the value of key")) + "Read the value of key")) diff --git a/src/clj/automaton_core/configuration/simple_files.clj b/src/clj/automaton_core/configuration/simple_files.clj index 9d84d23e..c93dcf40 100644 --- a/src/clj/automaton_core/configuration/simple_files.clj +++ b/src/clj/automaton_core/configuration/simple_files.clj @@ -21,15 +21,8 @@ [edn-filename] (let [edn-filename (when edn-filename (str (fs/absolutize edn-filename))) _ (log/trace "Load file:" edn-filename) - edn-content (try (slurp edn-filename) - (catch Exception _ - (log/warn-format "Unable to load the file `%s`" - edn-filename) - nil))] - (try (edn/read-string edn-content) - (catch Exception _ - (log/warn-format "File `%s` is not a valid edn" edn-filename) - nil)))) + edn-content (try (slurp edn-filename) (catch Exception _ (log/warn-format "Unable to load the file `%s`" edn-filename) nil))] + (try (edn/read-string edn-content) (catch Exception _ (log/warn-format "File `%s` is not a valid edn" edn-filename) nil)))) (defrecord SimpleConf [config-map] configuration-prot/Conf diff --git a/src/clj/automaton_core/log/be_log.clj b/src/clj/automaton_core/log/be_log.clj index 10aea5dc..afa35ae2 100644 --- a/src/clj/automaton_core/log/be_log.clj +++ b/src/clj/automaton_core/log/be_log.clj @@ -8,40 +8,28 @@ (defn log-init! [{:keys [dsn env]}] - (exs/init-error-tracking! {:dsn dsn, :env env})) + (exs/init-error-tracking! {:dsn dsn + :env env})) (defn- logger-ids-to-logger-fns "Based on logger-id chooses from registered strategies which logging function to use." [logger-ids] - (reduce (fn [acc logger-id] - (conj acc - (get-in log-be-registry/strategies-registry - [logger-id :impl]))) - [] - logger-ids)) + (reduce (fn [acc logger-id] (conj acc (get-in log-be-registry/strategies-registry [logger-id :impl]))) [] logger-ids)) (defmacro log [logger-ids level & message] - (let [ns *ns* - log-fns (logger-ids-to-logger-fns logger-ids)] - `((juxt ~@log-fns) ~ns ~level ~@message))) + (let [ns *ns* log-fns (logger-ids-to-logger-fns logger-ids)] `((juxt ~@log-fns) ~ns ~level ~@message))) (defmacro log-exception [logger-ids level exception & additional-message] (when additional-message `(log ~logger-ids ~level ~@additional-message)) - (let [ns *ns* - log-fns (logger-ids-to-logger-fns logger-ids)] - `((juxt ~@log-fns) ~ns ~level ~exception))) + (let [ns *ns* log-fns (logger-ids-to-logger-fns logger-ids)] `((juxt ~@log-fns) ~ns ~level ~exception))) (defmacro log-data [logger-ids level data & additional-message] (when additional-message `(log ~logger-ids level ~@additional-message)) - (let [ns *ns* - log-fns (logger-ids-to-logger-fns logger-ids)] - `((juxt ~@log-fns) ~ns ~level ~data))) + (let [ns *ns* log-fns (logger-ids-to-logger-fns logger-ids)] `((juxt ~@log-fns) ~ns ~level ~data))) (defmacro log-format [logger-ids level fmt & data] - (let [ns *ns* - log-fns (logger-ids-to-logger-fns logger-ids)] - `((juxt ~@log-fns) ~ns ~level (format ~fmt ~@data)))) + (let [ns *ns* log-fns (logger-ids-to-logger-fns logger-ids)] `((juxt ~@log-fns) ~ns ~level (format ~fmt ~@data)))) diff --git a/src/clj/automaton_core/log/be_registry.clj b/src/clj/automaton_core/log/be_registry.clj index 686d9ea5..549c31be 100644 --- a/src/clj/automaton_core/log/be_registry.clj +++ b/src/clj/automaton_core/log/be_registry.clj @@ -12,12 +12,12 @@ "List of predefined strategies Look at clj and cljs implementations to have an understanding of that strategies implementation which may be different on both technologies. For instance, `:text-based` will be based on log4j2 on backedn and console on frontend" - {::log-registry/print {:description "Simple print", :impl simple-print}, - ::log-registry/text-based - {:description - "Basic one - sends everything to flatten text (js/console for clojurescript and log4j2 for clojure)", - :impl automaton-core.log.impl.log4j2/log-fn}, - ::log-registry/no-op {:description "Deactivate that log", :impl no-op-fn}, - ::log-registry/error-tracking - {:description "For monitoring exceptions in the application", - :impl automaton-core.log.tracking.be-error-tracking/log-fn}}) + {::log-registry/print {:description "Simple print" + :impl simple-print} + ::log-registry/text-based {:description + "Basic one - sends everything to flatten text (js/console for clojurescript and log4j2 for clojure)" + :impl automaton-core.log.impl.log4j2/log-fn} + ::log-registry/no-op {:description "Deactivate that log" + :impl no-op-fn} + ::log-registry/error-tracking {:description "For monitoring exceptions in the application" + :impl automaton-core.log.tracking.be-error-tracking/log-fn}}) diff --git a/src/clj/automaton_core/log/impl/log4j2.clj b/src/clj/automaton_core/log/impl/log4j2.clj index 45768bdf..9405adce 100644 --- a/src/clj/automaton_core/log/impl/log4j2.clj +++ b/src/clj/automaton_core/log/impl/log4j2.clj @@ -6,6 +6,4 @@ (:require [automaton-core.utils.pretty-print :as pretty-print] [clojure.tools.logging :as l])) -(defn log-fn - [ns level & message] - (l/log ns level nil (pretty-print/seq->string message))) +(defn log-fn [ns level & message] (l/log ns level nil (pretty-print/seq->string message))) diff --git a/src/clj/automaton_core/log/log4j2.clj b/src/clj/automaton_core/log/log4j2.clj index a99a4fb4..7809c39d 100644 --- a/src/clj/automaton_core/log/log4j2.clj +++ b/src/clj/automaton_core/log/log4j2.clj @@ -20,8 +20,6 @@ bas/remove-last-character) elt)) -(defn prettify - [message] - (if (seqable? message) (str/join "" (map prettify-elt message)) message)) +(defn prettify [message] (if (seqable? message) (str/join "" (map prettify-elt message)) message)) (defn log-fn [ns level & message] (l/log ns level nil (prettify message))) diff --git a/src/clj/automaton_core/log/tracking/be_error_tracking.clj b/src/clj/automaton_core/log/tracking/be_error_tracking.clj index 1edfa879..57ed69c1 100644 --- a/src/clj/automaton_core/log/tracking/be_error_tracking.clj +++ b/src/clj/automaton_core/log/tracking/be_error_tracking.clj @@ -4,14 +4,17 @@ (defn init-error-tracking! [{:keys [dsn env]}] - (sentry/init-sentry! {:dsn dsn, :env env})) + (sentry/init-sentry! {:dsn dsn + :env env})) (defn log-fn [ns level & message] - (let [context - (if (map? (first message)) (merge (first message) {:ns ns}) {:ns ns}) + (let [context (if (map? (first message)) (merge (first message) {:ns ns}) {:ns ns}) message (if (map? (first message)) (rest message) message)] (if (or (= level :error) (= level :fatal)) - (sentry/send-event! {:message message, :level level, :context context}) - (sentry/send-breadcrumb! - {:message message, :level level, :context context})))) + (sentry/send-event! {:message message + :level level + :context context}) + (sentry/send-breadcrumb! {:message message + :level level + :context context})))) diff --git a/src/clj/automaton_core/log/tracking/be_sentry.clj b/src/clj/automaton_core/log/tracking/be_sentry.clj index 1bb1ea8f..54c4620c 100644 --- a/src/clj/automaton_core/log/tracking/be_sentry.clj +++ b/src/clj/automaton_core/log/tracking/be_sentry.clj @@ -26,26 +26,22 @@ (when level (.setLevel breadcrumb (keyword->level level))) (when message (.setMessage breadcrumb message)) (when category (.setCategory breadcrumb category)) - (when data - (doseq [[k v] (utils-map/map-util-hashmappify-vals data - #(HashMap. ^Map %))] - (.setData breadcrumb k v))) + (when data (doseq [[k v] (utils-map/map-util-hashmappify-vals data #(HashMap. ^Map %))] (.setData breadcrumb k v))) breadcrumb)) (defn send-breadcrumb! "Sends breadcrumb, which will not be shown in sentry until event is sent. You can read more here: https://docs.sentry.io/platforms/java/enriching-events/breadcrumbs/" [{:keys [message level context]}] - (Sentry/addBreadcrumb (map->breadcrumb {:message (pretty-print/seq->string - message), - :level level, + (Sentry/addBreadcrumb (map->breadcrumb {:message (pretty-print/seq->string message) + :level level :data context}))) (defn send-event! "Sends an event that is registered in sentry." [{:keys [message level context]}] - (sentry/send-event {:message (pretty-print/seq->string message), - :level level, + (sentry/send-event {:message (pretty-print/seq->string message) + :level level :extra context})) (defn init-sentry! @@ -53,6 +49,5 @@ 'development' as an environment is ignored, so no event is sent from it." [{:keys [dsn env]}] (sentry/init! dsn - {:environment env, - :before-send-fn - (fn [event _] (asentry/silence-development-events event))})) + {:environment env + :before-send-fn (fn [event _] (asentry/silence-development-events event))})) diff --git a/src/clj/automaton_core/os/code_formatter.clj b/src/clj/automaton_core/os/code_formatter.clj index b90e168f..8d016249 100644 --- a/src/clj/automaton_core/os/code_formatter.clj +++ b/src/clj/automaton_core/os/code_formatter.clj @@ -13,11 +13,9 @@ * `header` (optional) is written at the top of the file" ([filename header] (let [format-content (slurp filename)] - (files/spit-file filename - (apply str - [(when-not (str/blank? header) - (print-str ";;" header (time/now-str) "\n")) - format-content])) - (cmds/exec-cmds [[["zprint" "-w" filename] {:dir ".", :out :string}]]))) + (files/spit-file filename (apply str [(when-not (str/blank? header) (print-str ";;" header (time/now-str) "\n")) format-content])) + (cmds/exec-cmds [[["zprint" "-w" filename] + {:dir "." + :out :string}]]))) ([filename] (format-file filename nil))) diff --git a/src/clj/automaton_core/repl.clj b/src/clj/automaton_core/repl.clj index 1f96706c..8adb0761 100644 --- a/src/clj/automaton_core/repl.clj +++ b/src/clj/automaton_core/repl.clj @@ -11,65 +11,45 @@ (def nrepl-port-filename "Name of the `.nrepl-port` file" ".nrepl-port") -(defn custom-nrepl-handler - "We build our own custom nrepl handler" - [nrepl-mws] - (apply default-handler nrepl-mws)) +(defn custom-nrepl-handler "We build our own custom nrepl handler" [nrepl-mws] (apply default-handler nrepl-mws)) (def repl "Store the repl instance in the atom" (atom {})) (defn get-nrepl-port-parameter [] (conf/read-param [:dev :clj-nrepl-port] 8000)) #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} -(defn get-active-nrepl-port - "Retrieve the nrepl port, available for REPL" - [] - (:nrepl-port @repl)) +(defn get-active-nrepl-port "Retrieve the nrepl port, available for REPL" [] (:nrepl-port @repl)) -(defn stop-repl - "Stop the repl" - [repl-port] - (log/info "Stop nrepl server on port" repl-port) - (stop-server (:repl @repl)) - (reset! repl {})) +(defn stop-repl "Stop the repl" [repl-port] (log/info "Stop nrepl server on port" repl-port) (stop-server (:repl @repl)) (reset! repl {})) (defn create-nrepl-files "Consider all deps.edn files as the root of a clojure project and creates a .nrepl-port file next to it" [repl-port] (let [build-configs (files/search-files "" "**build_config.edn") - nrepl-ports (map #(files/file-in-same-dir % nrepl-port-filename) - build-configs)] - (doseq [nrepl-port nrepl-ports] - (files/write-file (str repl-port) nrepl-port)))) + nrepl-ports (map #(files/file-in-same-dir % nrepl-port-filename) build-configs)] + (doseq [nrepl-port nrepl-ports] (files/write-file (str repl-port) nrepl-port)))) (defn start-repl* "Launch a new repl" [{:keys [middleware]}] (let [repl-port (get-nrepl-port-parameter)] (create-nrepl-files repl-port) - (reset! repl {:nrepl-port repl-port, + (reset! repl {:nrepl-port repl-port :repl (do (log/info "nrepl available on port " repl-port) (println "repl port is available on:" repl-port) - (start-server :port repl-port - :handler (custom-nrepl-handler - middleware)))}) - (.addShutdownHook - (Runtime/getRuntime) - (Thread. #(do (log/info "SHUTDOWN in progress, stop repl on port `" - repl-port - "`") - (-> (files/search-files "" (str "**" nrepl-port-filename)) - (files/delete-files)) - (stop-repl repl-port)))))) + (start-server :port repl-port :handler (custom-nrepl-handler middleware)))}) + (.addShutdownHook (Runtime/getRuntime) + (Thread. #(do (log/info "SHUTDOWN in progress, stop repl on port `" repl-port "`") + (-> (files/search-files "" (str "**" nrepl-port-filename)) + (files/delete-files)) + (stop-repl repl-port)))))) (defn start-repl "Start repl, setup and catch errors" [] - (try - (start-repl* {:middleware (conj nrepl-mw/cider-middleware - 'refactor-nrepl.middleware/wrap-refactor)}) - :started - (catch Exception e (log/error (ex-info "Uncaught exception" {:error e}))))) + (try (start-repl* {:middleware (conj nrepl-mw/cider-middleware 'refactor-nrepl.middleware/wrap-refactor)}) + :started + (catch Exception e (log/error (ex-info "Uncaught exception" {:error e}))))) (defn -main "Entry point for simple / emergency repl" diff --git a/src/clj/automaton_core/utils/date.clj b/src/clj/automaton_core/utils/date.clj index 09ddab57..78581701 100644 --- a/src/clj/automaton_core/utils/date.clj +++ b/src/clj/automaton_core/utils/date.clj @@ -2,6 +2,4 @@ (def year-format (java.text.SimpleDateFormat. "yyyy")) -(defn this-year - ([date] (.format year-format date)) - ([] (this-year (java.util.Date.)))) +(defn this-year ([date] (.format year-format date)) ([] (this-year (java.util.Date.)))) diff --git a/src/cljc/automaton_core/adapters/re.cljc b/src/cljc/automaton_core/adapters/re.cljc index 0b404008..fae60b21 100644 --- a/src/cljc/automaton_core/adapters/re.cljc +++ b/src/cljc/automaton_core/adapters/re.cljc @@ -45,7 +45,5 @@ assembled ""] (let [re (stringify re) assembled-re (str assembled (if optional? (str re "?") re))] - (if nexts - (recur nexts assembled-re) - (re-pattern (str prefix assembled-re suffix)))))) + (if nexts (recur nexts assembled-re) (re-pattern (str prefix assembled-re suffix)))))) ([res] (assemble-re-optional res nil nil))) diff --git a/src/cljc/automaton_core/adapters/string.cljc b/src/cljc/automaton_core/adapters/string.cljc index e325ec43..df9fc904 100644 --- a/src/cljc/automaton_core/adapters/string.cljc +++ b/src/cljc/automaton_core/adapters/string.cljc @@ -1,17 +1,11 @@ -(ns automaton-core.adapters.string - "String manipulation usable both in clj and cljs") +(ns automaton-core.adapters.string "String manipulation usable both in clj and cljs") -(defn remove-last-character - "Remove the last character of a string" - [s] - (let [s (str s)] (subs s 0 (max 0 (- (count s) 1))))) +(defn remove-last-character "Remove the last character of a string" [s] (let [s (str s)] (subs s 0 (max 0 (- (count s) 1))))) (defn remove-first-last-character "Remove the first and last character of a string" [s] - (let [s (str s) - count-s (count s)] - (if (< 2 count-s) (subs s 1 (max 0 (- (count s) 1))) ""))) + (let [s (str s) count-s (count s)] (if (< 2 count-s) (subs s 1 (max 0 (- (count s) 1))) ""))) (def ellipsis "...") @@ -27,12 +21,7 @@ (if (<= (count line) limit) line (do (on-ellipsis s) - (apply str - (concat - prefix - (take (- limit (count ellipsis) (count prefix) (count suffix)) s) - ellipsis - suffix))))))) + (apply str (concat prefix (take (- limit (count ellipsis) (count prefix) (count suffix)) s) ellipsis suffix))))))) (defn remove-trailing-character "Remove last character if it is matching char diff --git a/src/cljc/automaton_core/i18n/dict/text.cljc b/src/cljc/automaton_core/i18n/dict/text.cljc index edd45897..a5b76ccd 100644 --- a/src/cljc/automaton_core/i18n/dict/text.cljc +++ b/src/cljc/automaton_core/i18n/dict/text.cljc @@ -5,4 +5,5 @@ (def dict "Contains all translations internally needed for `automaton-core`" - {:en {}, :fr {}}) + {:en {} + :fr {}}) diff --git a/src/cljc/automaton_core/i18n/language.cljc b/src/cljc/automaton_core/i18n/language.cljc index 9b592c66..06a61be5 100644 --- a/src/cljc/automaton_core/i18n/language.cljc +++ b/src/cljc/automaton_core/i18n/language.cljc @@ -9,31 +9,34 @@ (defprotocol Languages (language [this lang-id] - "return the language\nParams:\n * `lang-id`: language id") + "return the language\nParams:\n * `lang-id`: language id") (languages [this] - "return the list of known languages") + "return the list of known languages") (languages-ids [this] - "Set of known ids (set of keywords)") + "Set of known ids (set of keywords)") (dict-languages-ids [this] - "Set of known language ids keywords")) + "Set of known language ids keywords")) (defrecord AutomatonCoreLanguages [languages] Languages (language [_ lang-id] (get languages lang-id)) (languages [_] languages) (languages-ids [_] (set (keys languages))) - (dict-languages-ids [_] - (set (map first - (filter (fn [[_ language]] (:core-dict? language)) languages))))) + (dict-languages-ids [_] (set (map first (filter (fn [[_ language]] (:core-dict? language)) languages))))) (def ^:private core-languages-dict "Defines list of known language, the keys are internal identifiers and values are defined with: * `core-dict?` tells if that language should be used in dictionary of autamaton-core. This value is a decision, it will be used to check that the dictionary contains all of them * `ui-text` the text to show in UI as an identifier of the language. * `desc` description of the language" - {:fr {:core-dict? true, :ui-text "FR", :desc "Français"}, - :en {:core-dict? true, :ui-text "EN", :desc "English"}, - :pl {:ui-text "PL", :desc "Polski"}}) + {:fr {:core-dict? true + :ui-text "FR" + :desc "Français"} + :en {:core-dict? true + :ui-text "EN" + :desc "English"} + :pl {:ui-text "PL" + :desc "Polski"}}) (defn merge-languages-map "Merge maps in the argument order, so all their data are merged and the ones on the left are lower priority @@ -43,11 +46,8 @@ Params: * sequence of languages matching a language id to the language description" [& selected-languages-seq] - (let [languages-ids (apply set/intersection - (mapv (comp set keys) selected-languages-seq)) - languages (-> (apply utils-map/deep-merge - (map #(select-keys % languages-ids) - selected-languages-seq)) + (let [languages-ids (apply set/intersection (mapv (comp set keys) selected-languages-seq)) + languages (-> (apply utils-map/deep-merge (map #(select-keys % languages-ids) selected-languages-seq)) utils-map/add-ids)] languages)) @@ -58,17 +58,10 @@ The final map consists in the languages defined in both `selected-languages` `core-lang/base-languages` The language data map are merged, see `merge-languages-map` for details" [& selected-languages-seq] - (->AutomatonCoreLanguages - (apply merge-languages-map core-languages-dict selected-languages-seq))) + (->AutomatonCoreLanguages (apply merge-languages-map core-languages-dict selected-languages-seq))) -(def core-languages - "Languages available in `automaton-core`, instance of `Languages`" - (make-automaton-core-languages)) +(def core-languages "Languages available in `automaton-core`, instance of `Languages`" (make-automaton-core-languages)) -(def get-core-languages-id - "Known language ids in `automaton-core`" - (languages-ids core-languages)) +(def get-core-languages-id "Known language ids in `automaton-core`" (languages-ids core-languages)) -(def dict-core-languages-ids - "Known languages ids in `automaton-core`'s" - (dict-languages-ids core-languages)) +(def dict-core-languages-ids "Known languages ids in `automaton-core`'s" (dict-languages-ids core-languages)) diff --git a/src/cljc/automaton_core/i18n/missing_translation_report.cljc b/src/cljc/automaton_core/i18n/missing_translation_report.cljc index 53226b87..169ae063 100644 --- a/src/cljc/automaton_core/i18n/missing_translation_report.cljc +++ b/src/cljc/automaton_core/i18n/missing_translation_report.cljc @@ -9,12 +9,9 @@ [dictionary expected-languages] (let [filtered-dictionary (select-keys dictionary expected-languages)] (apply merge-with - union - (map (fn [[language dict-map]] - (into {} - (map (fn [v] [v #{language}]) - (keys (utils-map/crush dict-map))))) - filtered-dictionary)))) + union + (map (fn [[language dict-map]] (into {} (map (fn [v] [v #{language}]) (keys (utils-map/crush dict-map))))) + filtered-dictionary)))) (defn key-with-missing-languages "Return a map with the path to a translation, with the list of existing languages @@ -22,7 +19,5 @@ `expected-languages` is the languages the report is limited to" [dictionary expected-languages key-exceptions] (let [key-set-exceptions (into #{} key-exceptions)] - (filter (fn [[k v]] - (and (not (contains? key-set-exceptions k)) - (not= v expected-languages))) - (language-report dictionary expected-languages)))) + (filter (fn [[k v]] (and (not (contains? key-set-exceptions k)) (not= v expected-languages))) + (language-report dictionary expected-languages)))) diff --git a/src/cljc/automaton_core/i18n/translator.cljc b/src/cljc/automaton_core/i18n/translator.cljc index 372eea96..779c6934 100644 --- a/src/cljc/automaton_core/i18n/translator.cljc +++ b/src/cljc/automaton_core/i18n/translator.cljc @@ -2,6 +2,6 @@ (defprotocol Translator (default-languages [this] - "sequence of ids of the default languages") + "sequence of ids of the default languages") (translate [this lang-ids tr-id resources] - "translate the `:tr-id` with the resources as parameters (first resource is %1, second is %2, ...), trying to translate with first language lang-ids, then second, ...")) + "translate the `:tr-id` with the resources as parameters (first resource is %1, second is %2, ...), trying to translate with first language lang-ids, then second, ...")) diff --git a/src/cljc/automaton_core/i18n/translator/tempura.cljc b/src/cljc/automaton_core/i18n/translator/tempura.cljc index 8ca1022e..7f88e682 100644 --- a/src/cljc/automaton_core/i18n/translator/tempura.cljc +++ b/src/cljc/automaton_core/i18n/translator/tempura.cljc @@ -11,11 +11,8 @@ (def tempura-missing-text "Necessary for tempura, a missing key is expected for all languages marked with `:core-dict?` in `automaton-core.i18n.language`" - {:en {:missing - "The text is missing! :( Please let us know at info@hephaistox.com"}, - :fr - {:missing - "Le texte est manquant! :( Veuillez nous en informer à l'adresse info@hephaistox.com"}}) + {:en {:missing "The text is missing! :( Please let us know at info@hephaistox.com"} + :fr {:missing "Le texte est manquant! :( Veuillez nous en informer à l'adresse info@hephaistox.com"}}) (defn- append-dictionaries "Appends dictionaries @@ -31,9 +28,9 @@ [& dicts] (let [debug true ;; (= :dev (conf-core/read-param [:env])) ] - {:dict (append-dictionaries dicts), - :cache-dict? (not debug), - :default-local :fr, + {:dict (append-dictionaries dicts) + :cache-dict? (not debug) + :default-local :fr :cache-locales (not debug)})) (defrecord TempuraTranslator [opts main-langs] @@ -42,13 +39,7 @@ (translate [_ langs-id tr-id resources] (let [locales (vec (concat langs-id main-langs)) translated-text (tempura/tr opts locales [tr-id] resources)] - (log/trace "Translate key `" - tr-id - "`,with locales `" - locales - "`, -> `" - translated-text - "`") + (log/trace "Translate key `" tr-id "`,with locales `" locales "`, -> `" translated-text "`") translated-text))) (defn make-translator diff --git a/src/cljc/automaton_core/log.cljc b/src/cljc/automaton_core/log.cljc index b85a7792..ea6c1e88 100644 --- a/src/cljc/automaton_core/log.cljc +++ b/src/cljc/automaton_core/log.cljc @@ -3,8 +3,7 @@ Logical order of logs is: trace -> debug -> info -> warn -> error -> fatal" - (:require [automaton-core.log.strategy.static-ns-level :as - log-static-ns-level-strategy] + (:require [automaton-core.log.strategy.static-ns-level :as log-static-ns-level-strategy] [automaton-core.log.strategy :as log-strategy] #?(:clj [automaton-core.log.be-log] :cljs [automaton-core.log.fe-log])) @@ -14,16 +13,12 @@ "Decides which strategy implementation to use for choosing the loggers." (log-static-ns-level-strategy/make-static-ns-level-strategy)) -(defn cljs-env? - "Take the &env from a macro, and tell whether we are expanding into cljs." - [env] - (boolean (:ns env))) +(defn cljs-env? "Take the &env from a macro, and tell whether we are expanding into cljs." [env] (boolean (:ns env))) (defmacro trace "Records all of the application's behaviour details. Its purpose is primarily diagnostic, and it is more granular and finer than the DEBUG log level. When you need to know what happened in your application or the third-party libraries you're using, utilise this log level. The TRACE log level can be used to query code parameters or analyse algorithm steps." [& message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :trace)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :trace)] (if (cljs-env? &env) `(automaton-core.log.fe-log/log ~logger-id# :trace ~@message) `(automaton-core.log.be-log/log ~logger-id# :trace ~@message)))) @@ -31,38 +26,23 @@ (defmacro trace-exception "Like trace, but focused on exceptions." [exception & additional-message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :trace)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :trace)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-exception ~logger-id# - :trace - ~exception - ~@additional-message) - `(automaton-core.log.be-log/log-exception ~logger-id# - :trace - ~exception - ~@additional-message)))) + `(automaton-core.log.fe-log/log-exception ~logger-id# :trace ~exception ~@additional-message) + `(automaton-core.log.be-log/log-exception ~logger-id# :trace ~exception ~@additional-message)))) (defmacro trace-data "Like trace, but first argument is expected to be a map with usefull more detailed data." [data & additional-message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :trace)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :trace)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-data ~logger-id# - :trace - ~data - ~@additional-message) - `(automaton-core.log.be-log/log-data ~logger-id# - :trace - ~data - ~@additional-message)))) + `(automaton-core.log.fe-log/log-data ~logger-id# :trace ~data ~@additional-message) + `(automaton-core.log.be-log/log-data ~logger-id# :trace ~data ~@additional-message)))) (defmacro trace-format "Like trace, but uses clojure format function, so first argument is string to translate and rest is arguments to supply it with." [fmt & args] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :trace)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :trace)] (if (cljs-env? &env) `(automaton-core.log.fe-log/log-format ~logger-id# :trace ~fmt ~@args) `(automaton-core.log.be-log/log-format ~logger-id# :trace ~fmt ~@args)))) @@ -70,8 +50,7 @@ (defmacro debug "You are providing diagnostic information in a thorough manner with DEBUG. It's long and contains more information than you'll need when using the application. The DEBUG logging level is used to retrieve data that is required to debug, troubleshoot, or test an application. This guarantees that the application runs smoothly." [& message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :debug)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :debug)] (if (cljs-env? &env) `(automaton-core.log.fe-log/log ~logger-id# :debug ~@message) `(automaton-core.log.be-log/log ~logger-id# :debug ~@message)))) @@ -79,38 +58,23 @@ (defmacro debug-exception "Like debug, but focused on exceptions." [exception & additional-message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :debug)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :debug)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-exception ~logger-id# - :debug - ~exception - ~@additional-message) - `(automaton-core.log.be-log/log-exception ~logger-id# - :debug - ~exception - ~@additional-message)))) + `(automaton-core.log.fe-log/log-exception ~logger-id# :debug ~exception ~@additional-message) + `(automaton-core.log.be-log/log-exception ~logger-id# :debug ~exception ~@additional-message)))) (defmacro debug-data "Like debug, but first argument is expected to be a map with usefull more detailed data." [data & additional-message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :debug)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :debug)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-data ~logger-id# - :debug - ~data - ~@additional-message) - `(automaton-core.log.be-log/log-data ~logger-id# - :debug - ~data - ~@additional-message)))) + `(automaton-core.log.fe-log/log-data ~logger-id# :debug ~data ~@additional-message) + `(automaton-core.log.be-log/log-data ~logger-id# :debug ~data ~@additional-message)))) (defmacro debug-format "Like debug, but uses clojure format function, so first argument is string to translate and rest is arguments to supply it with." [fmt & args] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :debug)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :debug)] (if (cljs-env? &env) `(automaton-core.log.fe-log/log-format ~logger-id# :debug ~fmt ~@args) `(automaton-core.log.be-log/log-format ~logger-id# :debug ~fmt ~@args)))) @@ -128,28 +92,16 @@ [exception & additional-message] (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :info)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-exception ~logger-id# - :info - ~exception - ~@additional-message) - `(automaton-core.log.be-log/log-exception ~logger-id# - :info - ~exception - ~@additional-message)))) + `(automaton-core.log.fe-log/log-exception ~logger-id# :info ~exception ~@additional-message) + `(automaton-core.log.be-log/log-exception ~logger-id# :info ~exception ~@additional-message)))) (defmacro info-data "Like info, but first argument is expected to be a map with usefull more detailed data." [data & additional-message] (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :info)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-data ~logger-id# - :info - ~data - ~@additional-message) - `(automaton-core.log.be-log/log-data ~logger-id# - :info - ~data - ~@additional-message)))) + `(automaton-core.log.fe-log/log-data ~logger-id# :info ~data ~@additional-message) + `(automaton-core.log.be-log/log-data ~logger-id# :info ~data ~@additional-message)))) (defmacro info-format "Like info, but uses clojure format function, so first argument is string to translate and rest is arguments to supply it with." @@ -172,28 +124,16 @@ [exception & additional-message] (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :warn)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-exception ~logger-id# - :warn - ~exception - ~@additional-message) - `(automaton-core.log.be-log/log-exception ~logger-id# - :warn - ~exception - ~@additional-message)))) + `(automaton-core.log.fe-log/log-exception ~logger-id# :warn ~exception ~@additional-message) + `(automaton-core.log.be-log/log-exception ~logger-id# :warn ~exception ~@additional-message)))) (defmacro warn-data "Like warn, but first argument is expected to be a map with usefull more detailed data." [data & additional-message] (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :warn)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-data ~logger-id# - :warn - ~data - ~@additional-message) - `(automaton-core.log.be-log/log-data ~logger-id# - :warn - ~data - ~@additional-message)))) + `(automaton-core.log.fe-log/log-data ~logger-id# :warn ~data ~@additional-message) + `(automaton-core.log.be-log/log-data ~logger-id# :warn ~data ~@additional-message)))) (defmacro warn-format "Like warn, but uses clojure format function, so first argument is string to translate and rest is arguments to supply it with." @@ -206,8 +146,7 @@ (defmacro error "This ERROR indicates that something critical in your application has failed. This log level is used when a serious issue is preventing the application's functionalities from functioning properly. The application will continue to run for the most part, but it will need to be handled at some point." [& message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :error)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :error)] (if (cljs-env? &env) `(automaton-core.log.fe-log/log ~logger-id# :error ~@message) `(automaton-core.log.be-log/log ~logger-id# :error ~@message)))) @@ -215,38 +154,23 @@ (defmacro error-exception "Like error, but focused on exceptions." [exception & additional-message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :error)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :error)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-exception ~logger-id# - :error - ~exception - ~@additional-message) - `(automaton-core.log.be-log/log-exception ~logger-id# - :error - ~exception - ~@additional-message)))) + `(automaton-core.log.fe-log/log-exception ~logger-id# :error ~exception ~@additional-message) + `(automaton-core.log.be-log/log-exception ~logger-id# :error ~exception ~@additional-message)))) (defmacro error-data "Like error, but first argument is expected to be a map with usefull more detailed data." [data & additional-message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :error)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :error)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-data ~logger-id# - :error - ~data - ~@additional-message) - `(automaton-core.log.be-log/log-data ~logger-id# - :error - ~data - ~@additional-message)))) + `(automaton-core.log.fe-log/log-data ~logger-id# :error ~data ~@additional-message) + `(automaton-core.log.be-log/log-data ~logger-id# :error ~data ~@additional-message)))) (defmacro error-format "Like error, but uses clojure format function, so first argument is string to translate and rest is arguments to supply it with." [fmt & args] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :error)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :error)] (if (cljs-env? &env) `(automaton-core.log.fe-log/log-format ~logger-id# :error ~fmt ~@args) `(automaton-core.log.be-log/log-format ~logger-id# :error ~fmt ~@args)))) @@ -254,8 +178,7 @@ (defmacro fatal "FATAL indicates that the application is about to prevent a major problem or corruption. The FATAL level of logging indicates that the application's situation is critical, such as when a critical function fails. If the application is unable to connect to the data store, for example, you can utilise the FATAL log level." [& message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :fatal)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :fatal)] (if (cljs-env? &env) `(automaton-core.log.fe-log/log ~logger-id# :fatal ~@message) `(automaton-core.log.be-log/log ~logger-id# :fatal ~@message)))) @@ -263,38 +186,23 @@ (defmacro fatal-exception "Like fatal, but focused on exceptions." [exception & additional-message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :fatal)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :fatal)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-exception ~logger-id# - :fatal - ~exception - ~@additional-message) - `(automaton-core.log.be-log/log-exception ~logger-id# - :fatal - ~exception - ~@additional-message)))) + `(automaton-core.log.fe-log/log-exception ~logger-id# :fatal ~exception ~@additional-message) + `(automaton-core.log.be-log/log-exception ~logger-id# :fatal ~exception ~@additional-message)))) (defmacro fatal-data "Like fatal, but first argument is expected to be a map with usefull more detailed data." [data & additional-message] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :fatal)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :fatal)] (if (cljs-env? &env) - `(automaton-core.log.fe-log/log-data ~logger-id# - :fatal - ~data - ~@additional-message) - `(automaton-core.log.be-log/log-data ~logger-id# - :fatal - ~data - ~@additional-message)))) + `(automaton-core.log.fe-log/log-data ~logger-id# :fatal ~data ~@additional-message) + `(automaton-core.log.be-log/log-data ~logger-id# :fatal ~data ~@additional-message)))) (defmacro fatal-format "Like fatal, but uses clojure format function, so first argument is string to translate and rest is arguments to supply it with." [fmt & args] - (let [logger-id# - (automaton-core.log.strategy/apply-strategy stgy *ns* :fatal)] + (let [logger-id# (automaton-core.log.strategy/apply-strategy stgy *ns* :fatal)] (if (cljs-env? &env) `(automaton-core.log.fe-log/log-format ~logger-id# :fatal ~fmt ~@args) `(automaton-core.log.be-log/log-format ~logger-id# :fatal ~fmt ~@args)))) diff --git a/src/cljc/automaton_core/log/log_levels.cljc b/src/cljc/automaton_core/log/log_levels.cljc index b8bb126b..f2f8f3a3 100644 --- a/src/cljc/automaton_core/log/log_levels.cljc +++ b/src/cljc/automaton_core/log/log_levels.cljc @@ -1,9 +1,13 @@ -(ns automaton-core.log.log-levels - "Defines the possible log levels and their sequence") +(ns automaton-core.log.log-levels "Defines the possible log levels and their sequence") (def levels-sequence "List error levels in our app, first is more detailed, last is least detailed" - {:trace 10, :debug 20, :info 30, :warn 40, :error 50, :fatal 60}) + {:trace 10 + :debug 20 + :info 30 + :warn 40 + :error 50 + :fatal 60}) (defn execute-level? "Returns true if we decide to apply log to that levl regarding minimimum required @@ -11,5 +15,4 @@ * `min-level-kw` - keyword of the minimum log level expected * `level-kw` - keyword of the log to test" [min-level-kw level-kw] - (when (and level-kw min-level-kw) - (apply <= (map (partial get levels-sequence) [min-level-kw level-kw])))) + (when (and level-kw min-level-kw) (apply <= (map (partial get levels-sequence) [min-level-kw level-kw])))) diff --git a/src/cljc/automaton_core/log/registry.cljc b/src/cljc/automaton_core/log/registry.cljc index 82007b5a..e3e8ab7c 100644 --- a/src/cljc/automaton_core/log/registry.cljc +++ b/src/cljc/automaton_core/log/registry.cljc @@ -3,10 +3,7 @@ (def strategies-registry "List of predefined strategies Look at be-registry and fe-registry for implementations." - {::print {:description "Simple print"}, - ::text-based - {:description - "Basic one - sends everything to flatten text (js/console for clojurescript and log4j2 for clojure)"}, - ::no-op {:description "Deactivate that log"}, - ::error-tracking {:description - "Strategy for exception monitoring logging type"}}) + {::print {:description "Simple print"} + ::text-based {:description "Basic one - sends everything to flatten text (js/console for clojurescript and log4j2 for clojure)"} + ::no-op {:description "Deactivate that log"} + ::error-tracking {:description "Strategy for exception monitoring logging type"}}) diff --git a/src/cljc/automaton_core/log/strategy.cljc b/src/cljc/automaton_core/log/strategy.cljc index da8fd86a..2ab8ea2c 100644 --- a/src/cljc/automaton_core/log/strategy.cljc +++ b/src/cljc/automaton_core/log/strategy.cljc @@ -1,8 +1,7 @@ -(ns automaton-core.log.strategy - "Strategy to choose what logger is used where and when") +(ns automaton-core.log.strategy "Strategy to choose what logger is used where and when") (defprotocol Strategy (apply-strategy [this ns level] - "Return the seq of ids of the chosen rule according to that strategy") + "Return the seq of ids of the chosen rule according to that strategy") (rule-ids [this] - "List of known rule ids in that strategy, adding the `no-op` strategy defaulting your parameters")) + "List of known rule ids in that strategy, adding the `no-op` strategy defaulting your parameters")) diff --git a/src/cljc/automaton_core/log/strategy/static_ns_level.cljc b/src/cljc/automaton_core/log/strategy/static_ns_level.cljc index c4f9327a..22827861 100644 --- a/src/cljc/automaton_core/log/strategy/static_ns_level.cljc +++ b/src/cljc/automaton_core/log/strategy/static_ns_level.cljc @@ -21,20 +21,22 @@ * `re` - is the regular expression to apply on the namespace to decide if the rule apply or not * `min-level` - is the minimum expected log level to be printed (so all greater or equal log levels are printed). Not providing that value means all levels accepted * `:logger` - seq of loggers ids to apply, loggers themselves are defined later on, in clj and cljs sides as their implementation depends on the technology most of the time" - [{:rule-id :rule2, - :re #"automaton-core.log", - :min-level :debug, + [{:rule-id :rule2 + :re #"automaton-core.log" + :min-level :debug :logger [::log-registry/print]} - {:rule-id :rule1, - :re #"automaton-core.*", - :min-level :info, + {:rule-id :rule1 + :re #"automaton-core.*" + :min-level :info :logger [::log-registry/print]}]) (defn apply-ns-rule "If `ns` match the regular expression `re` then return a vector with: * the minimum level required to display that message * a description of the rule as a second parameter (useful for tracing the decision if log are needed)" - [ns {:keys [re], :as rule}] + [ns + {:keys [re] + :as rule}] (when re (when (re-find re (str ns)) rule))) (defrecord StaticNsLevelStrategy [ns-rules] @@ -47,11 +49,7 @@ (log-levels/execute-level? level)) (:logger active-rule) [::log-registry/text-based ::log-registry/error-tracking]))) - (rule-ids [_] - (set (cons ::log-registry/no-op - (reduce (fn [acc rule] (concat acc (:logger rule))) - [] - ns-rules))))) + (rule-ids [_] (set (cons ::log-registry/no-op (reduce (fn [acc rule] (concat acc (:logger rule))) [] ns-rules))))) (defn make-static-ns-level-strategy "Build the `log-strategy/Strategy` instance applying the static ns level rule diff --git a/src/cljc/automaton_core/log/tracking/sentry.cljc b/src/cljc/automaton_core/log/tracking/sentry.cljc index 3d797769..e474df02 100644 --- a/src/cljc/automaton_core/log/tracking/sentry.cljc +++ b/src/cljc/automaton_core/log/tracking/sentry.cljc @@ -5,7 +5,4 @@ #?(:clj (. event getEnvironment) :cljs event.environment)) -(defn silence-development-events - [event] - (let [environment (event-environment event)] - (when-not (= environment "development") event))) +(defn silence-development-events [event] (let [environment (event-environment event)] (when-not (= environment "development") event))) diff --git a/src/cljc/automaton_core/url.cljc b/src/cljc/automaton_core/url.cljc index d08c01f7..63ae8440 100644 --- a/src/cljc/automaton_core/url.cljc +++ b/src/cljc/automaton_core/url.cljc @@ -26,7 +26,7 @@ "According to [RFC3986 page 12](https://www.ietf.org/rfc/rfc3986.txt): gen-delims = : / ? # [ ] @ sub-delims = ! $ & ' ( ) * + , ; =" - {:gen-delims [":" "/" "?" "#" "[" "]" "@"], + {:gen-delims [":" "/" "?" "#" "[" "]" "@"] :sub-delims ["!" "$" "&" "'" "(" ")" "*" "+" "," ";" "="]}) (defn compare-locations diff --git a/src/cljc/automaton_core/utils/fallback.cljc b/src/cljc/automaton_core/utils/fallback.cljc index 44988bd0..6b7868fe 100644 --- a/src/cljc/automaton_core/utils/fallback.cljc +++ b/src/cljc/automaton_core/utils/fallback.cljc @@ -3,10 +3,7 @@ (:require [automaton-core.log :as log]) #?(:cljs (:require-macros [automaton-core.utils.fallback]))) -(defn cljs-env? - "Take the &env from a macro, and tell whether we are expanding into cljs." - [env] - (boolean (:ns env))) +(defn cljs-env? "Take the &env from a macro, and tell whether we are expanding into cljs." [env] (boolean (:ns env))) (defmacro always-return "To be used with great caution, as this is not a good practice to ignore exceptions. This should be used only in if it's really important for some application part to always return the value and should be used as a last resort. @@ -20,8 +17,9 @@ ns (str *ns*)] `(try (~expr-fn) (catch ~catch-level# e# - (log/error-exception - (ex-info "Failed but defaulted to ret-val" - {:error e#, - :data {:ret-val ~ret-val, :expr-fn ~expr-fn, :ns ~ns}})) + (log/error-exception (ex-info "Failed but defaulted to ret-val" + {:error e# + :data {:ret-val ~ret-val + :expr-fn ~expr-fn + :ns ~ns}})) ~ret-val)))) diff --git a/src/cljc/automaton_core/utils/map.cljc b/src/cljc/automaton_core/utils/map.cljc index bc81576c..cfd81f4b 100644 --- a/src/cljc/automaton_core/utils/map.cljc +++ b/src/cljc/automaton_core/utils/map.cljc @@ -11,8 +11,7 @@ (defn idx-of-pred "Same as idx-of but with a predicate" [v pred] - (when (and pred (fn? pred)) - (ffirst (filter #(pred (second %)) (map-indexed vector v))))) + (when (and pred (fn? pred)) (ffirst (filter #(pred (second %)) (map-indexed vector v))))) (defn deep-merge "Deep merge nested maps. @@ -20,21 +19,15 @@ This code comes from this [gist](https://gist.github.com/danielpcox/c70a8aa2c36766200a95)" [& maps] - (apply merge-with - (fn [& args] - (if (every? #(or (map? %) (nil? %)) args) - (apply deep-merge args) - (last args))) - maps)) + (apply merge-with (fn [& args] (if (every? #(or (map? %) (nil? %)) args) (apply deep-merge args) (last args))) maps)) (defn prefixify-map [prefix thing] (if (map? thing) - (set/rename-keys - thing - (->> (keys thing) - (map (fn [k] [k (keyword (str (name prefix) "." (name k)))])) - (into {}))) + (set/rename-keys thing + (->> (keys thing) + (map (fn [k] [k (keyword (str (name prefix) "." (name k)))])) + (into {}))) thing)) (defn prefixify-vec @@ -43,11 +36,7 @@ (if (map? el) (seq (set/rename-keys el (->> (keys el) - (map (fn [k] [k - (keyword - (str (name prefix) - "." - (name k)))])) + (map (fn [k] [k (keyword (str (name prefix) "." (name k)))])) (into {})))) el))] (if (vector? thing) @@ -66,10 +55,8 @@ (if (map? thing) (->> thing (map (fn [[k v]] - (cond (map? v) (let [prefixed (prefixify-map k v)] - (if (map? prefixed) prefixed {k v})) - (vector? v) (let [prefixed (prefixify-vec k v)] - (if (map? prefixed) prefixed {k v})) + (cond (map? v) (let [prefixed (prefixify-map k v)] (if (map? prefixed) prefixed {k v})) + (vector? v) (let [prefixed (prefixify-vec k v)] (if (map? prefixed) prefixed {k v})) :else {k v}))) (apply merge)) thing)) @@ -92,15 +79,12 @@ (let [language (cond-> language (map? language) (assoc :id lang-id))] [lang-id language])) - m))) + m))) (defn update-kw "Update the keywords `kws` in map `m` with function `f`" [m kws f] - (reduce (fn [m k] - (if (contains? m k) (let [v (get m k)] (assoc m k (f v))) m)) - m - kws)) + (reduce (fn [m k] (if (contains? m k) (let [v (get m k)] (assoc m k (f v))) m)) m kws)) (defn apply-to-keys "Apply function `f` to each key in `ks` in the maps in `maps` @@ -116,8 +100,5 @@ values recursively translated into what modify-type-fn is returning. Based on walk/stringify-keys." [m modify-type-fn] - (let [f (fn [[k v]] - (let [k (if (keyword? k) (name k) k) - v (if (keyword? v) (name v) v)] - (if (map? v) [k (modify-type-fn v)] [k v])))] + (let [f (fn [[k v]] (let [k (if (keyword? k) (name k) k) v (if (keyword? v) (name v) v)] (if (map? v) [k (modify-type-fn v)] [k v])))] (walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m))) diff --git a/src/cljc/automaton_core/utils/sequences.cljc b/src/cljc/automaton_core/utils/sequences.cljc index 4e13c412..4fbda87d 100644 --- a/src/cljc/automaton_core/utils/sequences.cljc +++ b/src/cljc/automaton_core/utils/sequences.cljc @@ -9,7 +9,5 @@ (loop [aseq aseq i 40] ;; For security reason (when-not (pos? i) (throw (ex-info "Infinite loop detected" {}))) - (if (and (seq aseq) (nil-fn (last aseq))) - (recur (butlast aseq) (dec i)) - aseq))) + (if (and (seq aseq) (nil-fn (last aseq))) (recur (butlast aseq) (dec i)) aseq))) ([aseq] (trim-leading-nil aseq nil?))) diff --git a/src/cljs/automaton_core/log/fe_log.cljc b/src/cljs/automaton_core/log/fe_log.cljc index b2ae69c8..0a6b42e6 100644 --- a/src/cljs/automaton_core/log/fe_log.cljc +++ b/src/cljs/automaton_core/log/fe_log.cljc @@ -9,39 +9,32 @@ [logger-ids] (reduce (fn [acc logger-id] (conj acc - (get-in - #?(:cljs automaton-core.log.fe-registry/strategies-registry - :clj {}) - [logger-id :impl]))) - [] - logger-ids)) + (get-in #?(:cljs automaton-core.log.fe-registry/strategies-registry + :clj {}) + [logger-id :impl]))) + [] + logger-ids)) (defmacro log [logger-id level & message] (let [ns (str *ns*) - log-fns `(automaton-core.log.fe-log/logger-ids-to-logger-fns - ~logger-id)] + log-fns `(automaton-core.log.fe-log/logger-ids-to-logger-fns ~logger-id)] `((apply juxt ~log-fns) ~ns ~level ~@message))) (defmacro log-exception [logger-id level exception & additional-message] (when additional-message (log logger-id level additional-message)) (let [ns (str *ns*) - log-fns `(automaton-core.log.fe-log/logger-ids-to-logger-fns - ~logger-id)] + log-fns `(automaton-core.log.fe-log/logger-ids-to-logger-fns ~logger-id)] `((apply juxt ~log-fns) ~ns ~level ~exception))) (defmacro log-data [logger-id level data & additional-message] (when additional-message (log logger-id additional-message)) - (let [ns (str *ns*) - log-fns `(automaton-core.log.fe-log/logger-ids-to-logger-fns - ~logger-id)] - `((apply juxt ~log-fns) ~ns ~level ~data))) + (let [ns (str *ns*) log-fns `(automaton-core.log.fe-log/logger-ids-to-logger-fns ~logger-id)] `((apply juxt ~log-fns) ~ns ~level ~data))) (defmacro log-format [logger-id level fmt & data] (let [ns (str *ns*) - log-fns `(automaton-core.log.fe-log/logger-ids-to-logger-fns - ~logger-id)] + log-fns `(automaton-core.log.fe-log/logger-ids-to-logger-fns ~logger-id)] `((apply juxt ~log-fns) ~ns (str ~level) (format ~fmt ~@data)))) diff --git a/src/cljs/automaton_core/log/fe_registry.cljc b/src/cljs/automaton_core/log/fe_registry.cljc index 8721d716..c491ae30 100644 --- a/src/cljs/automaton_core/log/fe_registry.cljc +++ b/src/cljs/automaton_core/log/fe_registry.cljc @@ -1,8 +1,7 @@ (ns automaton-core.log.fe-registry "List of all known frontend strategies" (:require [automaton-core.log.registry :as log-registry] - #?@(:cljs [[automaton-core.log.impl.print] - [automaton-core.log.tracking.fe-error-tracking]]))) + #?@(:cljs [[automaton-core.log.impl.print] [automaton-core.log.tracking.fe-error-tracking]]))) (defn no-op-fn [& _] nil) @@ -12,12 +11,12 @@ "List of predefined strategies Look at clj and cljs implementations to have an understanding of that strategies implementation which may be different on both technologies. For instance, `:text-based` will be based on log4j2 on backedn and console on frontend" - {::log-registry/print {:description "Simple print", :impl simple-print}, - ::log-registry/text-based - {:description - "Basic one - sends everything to flatten text (js/console for clojurescript and log4j2 for clojure)", - #?@(:cljs [:impl automaton-core.log.impl.print/log-fn])}, - ::log-registry/no-op {:description "Deactivate that log", :impl no-op-fn}, - ::log-registry/error-tracking - {:description "For monitoring exceptions in the application", - #?@(:cljs [:impl automaton-core.log.tracking.fe-error-tracking/log-fn])}}) + {::log-registry/print {:description "Simple print" + :impl simple-print} + ::log-registry/text-based {:description + "Basic one - sends everything to flatten text (js/console for clojurescript and log4j2 for clojure)" + #?@(:cljs [:impl automaton-core.log.impl.print/log-fn])} + ::log-registry/no-op {:description "Deactivate that log" + :impl no-op-fn} + ::log-registry/error-tracking {:description "For monitoring exceptions in the application" + #?@(:cljs [:impl automaton-core.log.tracking.fe-error-tracking/log-fn])}}) diff --git a/src/cljs/automaton_core/log/tracking/fe_error_tracking.cljs b/src/cljs/automaton_core/log/tracking/fe_error_tracking.cljs index ec8d2382..65d4ce2e 100644 --- a/src/cljs/automaton_core/log/tracking/fe_error_tracking.cljs +++ b/src/cljs/automaton_core/log/tracking/fe_error_tracking.cljs @@ -4,11 +4,13 @@ (defn log-fn [ns level & message] - (let [context - (if (map? (first message)) (merge (first message) {:ns ns}) {:ns ns}) + (let [context (if (map? (first message)) (merge (first message) {:ns ns}) {:ns ns}) message (apply str (if (map? (first message)) (rest message) message)) level (if (= :trace level) :debug level)] (if (or (= level :error) (= level :fatal)) - (sentry/send-event! {:message message, :level level, :context context}) - (sentry/send-breadcrumb! - {:message message, :level level, :context context})))) + (sentry/send-event! {:message message + :level level + :context context}) + (sentry/send-breadcrumb! {:message message + :level level + :context context})))) diff --git a/src/cljs/automaton_core/log/tracking/fe_sentry.cljs b/src/cljs/automaton_core/log/tracking/fe_sentry.cljs index 2981748b..878bf717 100644 --- a/src/cljs/automaton_core/log/tracking/fe_sentry.cljs +++ b/src/cljs/automaton_core/log/tracking/fe_sentry.cljs @@ -8,25 +8,28 @@ You can read more here: https://docs.sentry.io/platforms/javascript/guides/react/enriching-events/breadcrumbs/" [{:keys [message level context]}] (.addBreadcrumb Sentry - (clj->js {:level level, :message message, :data context}))) + (clj->js {:level level + :message message + :data context}))) (defn send-event! "Sends an event that is registered in sentry." [{:keys [message level context]}] (.captureEvent Sentry - (clj->js {:level level, :message message, :extra context}))) + (clj->js {:level level + :message message + :extra context}))) (defn init-sentry! "Initialize sentry for react, which is recording react errors that happens inside the components and enables to send events. 'development' as an environment is ignored, so no event is sent from it." [{:keys [dsn traced-website env]}] (.init Sentry - #js {:dsn dsn, - :environment env, - :integrations #js [(new (.-BrowserTracing Sentry))], - :replaysSessionSampleRate 0, - :replaysOnErrorSampleRate 0, - :tracesSampleRate 1.0, - :tracePropagationTargets #js ["localhost" traced-website], - :beforeSend (fn [event] - (asentry/silence-development-events event))})) + #js {:dsn dsn + :environment env + :integrations #js [(new (.-BrowserTracing Sentry))] + :replaysSessionSampleRate 0 + :replaysOnErrorSampleRate 0 + :tracesSampleRate 1.0 + :tracePropagationTargets #js ["localhost" traced-website] + :beforeSend (fn [event] (asentry/silence-development-events event))})) diff --git a/test/clj/automaton_core/adapters/build_config_test.clj b/test/clj/automaton_core/adapters/build_config_test.clj index 2cde7ccb..9e72afcb 100644 --- a/test/clj/automaton_core/adapters/build_config_test.clj +++ b/test/clj/automaton_core/adapters/build_config_test.clj @@ -4,15 +4,11 @@ [automaton-core.adapters.files :as files] [clojure.test :refer [deftest is testing]])) -(deftest search-for-build-config-test - (testing "At least current project should be found" - (is (> (count (sut/search-for-build-config)) 0)))) +(deftest search-for-build-config-test (testing "At least current project should be found" (is (> (count (sut/search-for-build-config)) 0)))) (deftest spit-build-config-test (testing "Check spitted build config is found" (let [tmp-dir (files/create-temp-dir) content {:foo3 :bar3}] (sut/spit-build-config tmp-dir content ";; Hey!") - (is (= content - (edn-utils/read-edn-or-nil - (files/create-file-path tmp-dir sut/build-config-filename))))))) + (is (= content (edn-utils/read-edn-or-nil (files/create-file-path tmp-dir sut/build-config-filename))))))) diff --git a/test/clj/automaton_core/adapters/commands_test.clj b/test/clj/automaton_core/adapters/commands_test.clj index b4e11a80..1cf65587 100644 --- a/test/clj/automaton_core/adapters/commands_test.clj +++ b/test/clj/automaton_core/adapters/commands_test.clj @@ -6,47 +6,46 @@ And be able to watch bb log to check if results are as expected" [automaton-core.adapters.commands :as sut] [automaton-core.adapters.schema :as schema])) -(defn check-exit-code - "Check the process return code is 0" - [proc] - (= 0 (:exit proc))) +(defn check-exit-code "Check the process return code is 0" [proc] (= 0 (:exit proc))) (deftest execute-command-test (testing "Simple command is ok" (is (check-exit-code (sut/execute-command [["ls" "-la"] {}] - {:dir ".", :out :string})))) + {:dir "." + :out :string})))) (testing "Output is caught in :string" (is (= "-la\n" (:out (sut/execute-command [["echo" "-la"] {}] - {:out :string, :dir "."}))))) + {:out :string + :dir "."}))))) (testing "Command exits with non zero return code" (is (thrown-with-msg? clojure.lang.ExceptionInfo #"failed on exit code" (sut/execute-command [["uname" "-x"] {}] - {:out :string, :dir "."})))) + {:out :string + :dir "."})))) (testing "Directory does not exist" (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Command.*failed" (sut/execute-command [[] {}] - {:out :string, :dir "."})))) + {:out :string + :dir "."})))) (testing "Directory is already a file" - (is (thrown-with-msg? - clojure.lang.ExceptionInfo - #"Can't create a directory" - (sut/execute-command [["pwd"]] {:dir "deps.edn", :out :string}))))) + (is (thrown-with-msg? clojure.lang.ExceptionInfo + #"Can't create a directory" + (sut/execute-command [["pwd"]] + {:dir "deps.edn" + :out :string}))))) (deftest execute-test (testing "Simple version" (is (string? (sut/exec-cmds [[["pwd"]] [["pwd"]]] - {:out :string, :dir "."})))) + {:out :string + :dir "."})))) (testing "Failed command is detected" - (is (thrown-with-msg? clojure.lang.ExceptionInfo - #"" - (sut/exec-cmds [[["uname" "-x"] {:out :string}]])))) + (is (thrown-with-msg? clojure.lang.ExceptionInfo #"" (sut/exec-cmds [[["uname" "-x"] {:out :string}]])))) (testing "Commands should be a vector of command" - (is (thrown-with-msg? clojure.lang.ExceptionInfo - #"Malformed command" - (sut/exec-cmds "test"))))) + (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Malformed command" (sut/exec-cmds "test"))))) (deftest commands-schema-test (testing "Accepted example" diff --git a/test/clj/automaton_core/adapters/deps_edn_test.clj b/test/clj/automaton_core/adapters/deps_edn_test.clj index 117806fd..01687516 100644 --- a/test/clj/automaton_core/adapters/deps_edn_test.clj +++ b/test/clj/automaton_core/adapters/deps_edn_test.clj @@ -5,98 +5,79 @@ (def tmp-dir (files/create-temp-dir)) -(deftest get-deps-filename-test - (testing "Get deps is working" - (is (string? (sut/get-deps-filename tmp-dir))))) +(deftest get-deps-filename-test (testing "Get deps is working" (is (string? (sut/get-deps-filename tmp-dir))))) (deftest update-commit-id-test (testing "The commit id of a lib is updated when exists" (is (= {} (sut/update-commit-id 'foo "1234" {}))) - (is (= {:deps {'foo {:git/sha "1234"}}} - (sut/update-commit-id 'foo "1234" {:deps {'foo {:git/sha ""}}}))))) + (is (= {:deps {'foo {:git/sha "1234"}}} (sut/update-commit-id 'foo "1234" {:deps {'foo {:git/sha ""}}}))))) (deftest extract-paths-test (testing "Extract paths from a deps.edn file" (is (= ["a" "b" "c" "d" "e" "f" "g"] - (sut/extract-paths {:paths ["a" "b" "c"], - :aliases {:repl {:extra-paths ["d" "e"]}, + (sut/extract-paths {:paths ["a" "b" "c"] + :aliases {:repl {:extra-paths ["d" "e"]} :runner {:extra-paths ["f" "g"]}}} #{}))) (is (= ["a" "b" "c" "d" "e" "f" "g"] - (sut/extract-paths {:paths ["a" "b" "c"], - :aliases {:repl {:extra-paths ["d" "e"]}, + (sut/extract-paths {:paths ["a" "b" "c"] + :aliases {:repl {:extra-paths ["d" "e"]} :runner {:extra-paths ["f" "g"]}}})))) (testing "Exclusion of aliases is working" (is (= ["a" "b" "c" "d" "e"] - (sut/extract-paths {:paths ["a" "b" "c"], - :aliases {:repl {:extra-paths ["d" "e"]}, + (sut/extract-paths {:paths ["a" "b" "c"] + :aliases {:repl {:extra-paths ["d" "e"]} :runner {:extra-paths ["f" "g"]}}} #{:runner}))) (is (= ["a" "b" "c" "f" "g"] - (sut/extract-paths {:paths ["a" "b" "c"], - :aliases {:repl {:extra-paths ["d" "e"]}, + (sut/extract-paths {:paths ["a" "b" "c"] + :aliases {:repl {:extra-paths ["d" "e"]} :runner {:extra-paths ["f" "g"]}}} #{:repl})))) (testing "Dedupe works" (is (= ["a" "b" "c" "f" "g"] - (sut/extract-paths {:paths ["f" "g"], - :aliases {:repl {:extra-paths ["d" "e" "f"]}, - :runner {:extra-paths ["a" "b" "c" - "f"]}}} + (sut/extract-paths {:paths ["f" "g"] + :aliases {:repl {:extra-paths ["d" "e" "f"]} + :runner {:extra-paths ["a" "b" "c" "f"]}}} #{:repl}))))) (deftest extract-deps-test (testing "`:deps` key is extracted" (is (= [['org.clojure/clojure #:mvn{:version "1.11.1"}]] - (sut/extract-deps {:deps {'org.clojure/clojure {:mvn/version - "1.11.1"}}} - #{})))) + (sut/extract-deps {:deps {'org.clojure/clojure {:mvn/version "1.11.1"}}} #{})))) (testing "aliases are extracted" - (is - (= [['com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"}] - ['foo/bar #:mvn{:version "1.1.0"}] ['bar/foo #:mvn{:version "1.1.0"}]] - (sut/extract-deps - {:deps {'com.clojure-goes-fast/clj-memory-meter {:mvn/version - "0.2.1"}}, - :aliases {:repl {:extra-deps {'foo/bar {:mvn/version "1.1.0"}}}, - :runner {:extra-deps {'bar/foo {:mvn/version "1.1.0"}}}}} - #{})))) + (is (= [['com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"}] ['foo/bar #:mvn{:version "1.1.0"}] + ['bar/foo #:mvn{:version "1.1.0"}]] + (sut/extract-deps {:deps {'com.clojure-goes-fast/clj-memory-meter {:mvn/version "0.2.1"}} + :aliases {:repl {:extra-deps {'foo/bar {:mvn/version "1.1.0"}}} + :runner {:extra-deps {'bar/foo {:mvn/version "1.1.0"}}}}} + #{})))) (testing "aliases are excluded" - (is (= [['com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"}] - ['foo/bar #:mvn{:version "1.1.0"}]] - (sut/extract-deps - {:deps {'com.clojure-goes-fast/clj-memory-meter {:mvn/version - "0.2.1"}}, - :aliases {:repl {:extra-deps {'foo/bar {:mvn/version "1.1.0"}}}, - :runner {:extra-deps {'bar/foo {:mvn/version - "1.1.0"}}}}} - #{:runner}))))) + (is (= [['com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"}] ['foo/bar #:mvn{:version "1.1.0"}]] + (sut/extract-deps {:deps {'com.clojure-goes-fast/clj-memory-meter {:mvn/version "0.2.1"}} + :aliases {:repl {:extra-deps {'foo/bar {:mvn/version "1.1.0"}}} + :runner {:extra-deps {'bar/foo {:mvn/version "1.1.0"}}}}} + #{:runner}))))) (deftest remove-deps-test (testing "Remove one dep is working" - (is (= {:deps {'com.clojure-goes-fast/clj-memory-meter #:mvn{:version - "0.2.1"}, + (is (= {:deps {'com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"} 'bar/foo #:mvn{:version "1.1.0"}}} - (sut/remove-deps {:deps {'com.clojure-goes-fast/clj-memory-meter - #:mvn{:version "0.2.1"}, - 'foo/bar #:mvn{:version "1.1.0"}, + (sut/remove-deps {:deps {'com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"} + 'foo/bar #:mvn{:version "1.1.0"} 'bar/foo #:mvn{:version "1.1.0"}}} ['foo/bar]))) - (is (= {:deps {'com.clojure-goes-fast/clj-memory-meter #:mvn{:version - "0.2.1"}, + (is (= {:deps {'com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"} 'foo/bar #:mvn{:version "1.1.0"}}} - (sut/remove-deps {:deps {'com.clojure-goes-fast/clj-memory-meter - #:mvn{:version "0.2.1"}, - 'foo/bar #:mvn{:version "1.1.0"}, + (sut/remove-deps {:deps {'com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"} + 'foo/bar #:mvn{:version "1.1.0"} 'bar/foo #:mvn{:version "1.1.0"}}} ['bar/foo])))) (testing "Remove unexisting deps" - (is (= {:deps {'com.clojure-goes-fast/clj-memory-meter #:mvn{:version - "0.2.1"}, - 'foo/bar #:mvn{:version "1.1.0"}, + (is (= {:deps {'com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"} + 'foo/bar #:mvn{:version "1.1.0"} 'bar/foo #:mvn{:version "1.1.0"}}} - (sut/remove-deps {:deps {'com.clojure-goes-fast/clj-memory-meter - #:mvn{:version "0.2.1"}, - 'foo/bar #:mvn{:version "1.1.0"}, + (sut/remove-deps {:deps {'com.clojure-goes-fast/clj-memory-meter #:mvn{:version "0.2.1"} + 'foo/bar #:mvn{:version "1.1.0"} 'bar/foo #:mvn{:version "1.1.0"}}} ['bar/foo2]))))) diff --git a/test/clj/automaton_core/adapters/edn_utils_test.clj b/test/clj/automaton_core/adapters/edn_utils_test.clj index 5246c9d9..e0485c7d 100644 --- a/test/clj/automaton_core/adapters/edn_utils_test.clj +++ b/test/clj/automaton_core/adapters/edn_utils_test.clj @@ -17,25 +17,15 @@ (deftest read-edn-test (testing "Malformed files are detected " - (is (thrown-with-msg? clojure.lang.ExceptionInfo - #"File.*is not an edn" - (sut/read-edn "non-used-file-name" - (fn [_] "1.1.1 (+ 1 1)"))))) + (is (thrown-with-msg? clojure.lang.ExceptionInfo #"File.*is not an edn" (sut/read-edn "non-used-file-name" (fn [_] "1.1.1 (+ 1 1)"))))) (testing "Non existing files are detected " - (is (thrown-with-msg? clojure.lang.ExceptionInfo - #"Unable to load the file" - (sut/read-edn "not existing file")))) + (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Unable to load the file" (sut/read-edn "not existing file")))) (testing "Non existing files throw an exception" - (is (thrown-with-msg? clojure.lang.ExceptionInfo - #"Unable to load the file" - (sut/read-edn "non existing file" slurp)))) - (testing "Non existing files throw an exception" - (is (= "test1-content" - (sut/read-edn (io/resource "resource-test-copy-dir/test1")))))) + (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Unable to load the file" (sut/read-edn "non existing file" slurp)))) + (testing "Non existing files throw an exception" (is (= "test1-content" (sut/read-edn (io/resource "resource-test-copy-dir/test1")))))) (deftest read-edn-or-nil-test - (testing "Skip non existing files and return nil" - (is (nil? (sut/read-edn-or-nil "non existing file" slurp))))) + (testing "Skip non existing files and return nil" (is (nil? (sut/read-edn-or-nil "non existing file" slurp))))) (def tmp-file ;; => "../tmp/edns/6bfcd070-3c43-11ee-aece-d9f945498185.edn" diff --git a/test/clj/automaton_core/adapters/env_var_test.clj b/test/clj/automaton_core/adapters/env_var_test.clj index 7c0706b0..c368d5b4 100644 --- a/test/clj/automaton_core/adapters/env_var_test.clj +++ b/test/clj/automaton_core/adapters/env_var_test.clj @@ -5,8 +5,7 @@ (deftest get-env-var-test (testing "Find the shell name in environment variable. TERM is find locally, RUNNER_OS on Github, as apparently no env var is common to both environments" - (is (or (string? (sut/get-env "TERM")) - (string? (sut/get-env "RUNNER_OS")))))) + (is (or (string? (sut/get-env "TERM")) (string? (sut/get-env "RUNNER_OS")))))) (deftest get-env-vars-test (testing "Env vars are ok" diff --git a/test/clj/automaton_core/adapters/files_test.clj b/test/clj/automaton_core/adapters/files_test.clj index 09ea2c7e..8306c2be 100644 --- a/test/clj/automaton_core/adapters/files_test.clj +++ b/test/clj/automaton_core/adapters/files_test.clj @@ -7,128 +7,61 @@ (deftest copy-files-or-dir (let [tmp-dir (fs/create-temp-dir)] (testing "Directory copy" - (is (= (do (sut/copy-files-or-dir [(io/resource "resource-test-copy-dir")] - tmp-dir) - #{"test1" "test2"}) - (into #{} - (map (fn [file] (str (fs/relativize tmp-dir file))) - (fs/glob tmp-dir "**"))))))) + (is (= (do (sut/copy-files-or-dir [(io/resource "resource-test-copy-dir")] tmp-dir) #{"test1" "test2"}) + (into #{} (map (fn [file] (str (fs/relativize tmp-dir file))) (fs/glob tmp-dir "**"))))))) (testing "If files are not a vector of string" - (is (thrown-with-msg? clojure.lang.ExceptionInfo - #"parameter should be a sequence" - (sut/copy-files-or-dir {} "/tmp")))) + (is (thrown-with-msg? clojure.lang.ExceptionInfo #"parameter should be a sequence" (sut/copy-files-or-dir {} "/tmp")))) (let [tmp-dir (fs/create-temp-dir)] (testing "File copy" - (is (= (do (sut/copy-files-or-dir - [(io/resource - (str "resource-test-copy-dir" fs/file-separator "test1"))] - tmp-dir) - #{"test1"}) - (into #{} - (map (fn [file] (str (fs/relativize tmp-dir file))) - (fs/glob tmp-dir "**")))))))) + (is (= (do (sut/copy-files-or-dir [(io/resource (str "resource-test-copy-dir" fs/file-separator "test1"))] tmp-dir) #{"test1"}) + (into #{} (map (fn [file] (str (fs/relativize tmp-dir file))) (fs/glob tmp-dir "**")))))))) (deftest directory-exists? - (testing "A non existing directory is detected" - (is (not (sut/directory-exists? "non-existing-directory")))) - (testing "A non existing directory in existing directory is detected" - (is (not (sut/directory-exists? "everything/non-existing")))) - (testing "A file is detected as a non directory" - (is (not (sut/directory-exists? "deps.edn")))) - (testing "An existing directory is detected" - (is (sut/directory-exists? ".clj-kondo"))) - (testing "An existing directory inside directory is detected" - (is (sut/directory-exists? ".clj-kondo/rewrite-clj")))) + (testing "A non existing directory is detected" (is (not (sut/directory-exists? "non-existing-directory")))) + (testing "A non existing directory in existing directory is detected" (is (not (sut/directory-exists? "everything/non-existing")))) + (testing "A file is detected as a non directory" (is (not (sut/directory-exists? "deps.edn")))) + (testing "An existing directory is detected" (is (sut/directory-exists? ".clj-kondo"))) + (testing "An existing directory inside directory is detected" (is (sut/directory-exists? ".clj-kondo/rewrite-clj")))) (deftest is-existing-file? - (testing "A non existing path is accepted" - (is (not (sut/is-existing-file? "non-existing-directory")))) - (testing "An already existing path is accepted" - (is (sut/is-existing-file? "deps.edn")))) + (testing "A non existing path is accepted" (is (not (sut/is-existing-file? "non-existing-directory")))) + (testing "An already existing path is accepted" (is (sut/is-existing-file? "deps.edn")))) -(deftest create-temp-dir - (testing "A temporary directory has really been created" - (is (sut/directory-exists? (sut/create-temp-dir))))) +(deftest create-temp-dir (testing "A temporary directory has really been created" (is (sut/directory-exists? (sut/create-temp-dir))))) (deftest remove-trailing-separator (let [base-dir (str sut/file-separator "tmp" sut/file-separator "foo")] - (testing "Accept directories with no trailing separator" - (is (= base-dir (sut/remove-trailing-separator base-dir)))) + (testing "Accept directories with no trailing separator" (is (= base-dir (sut/remove-trailing-separator base-dir)))) + (testing "Remove one trailing separator" (is (= base-dir (sut/remove-trailing-separator (str base-dir sut/file-separator))))) (testing "Remove one trailing separator" - (is (= base-dir - (sut/remove-trailing-separator (str base-dir - sut/file-separator))))) - (testing "Remove one trailing separator" - (is (= base-dir - (sut/remove-trailing-separator - (str base-dir sut/file-separator sut/file-separator))))) - (testing "Remove one trailing separator" - (is (= base-dir - (sut/remove-trailing-separator - (str base-dir sut/file-separator " "))))) - (testing "Remove one trailing separator" - (is (= base-dir - (sut/remove-trailing-separator - (str " " base-dir sut/file-separator))))) - (testing "Remove one trailing separator" - (is (= base-dir - (sut/remove-trailing-separator - (str " " base-dir sut/file-separator " "))))))) + (is (= base-dir (sut/remove-trailing-separator (str base-dir sut/file-separator sut/file-separator))))) + (testing "Remove one trailing separator" (is (= base-dir (sut/remove-trailing-separator (str base-dir sut/file-separator " "))))) + (testing "Remove one trailing separator" (is (= base-dir (sut/remove-trailing-separator (str " " base-dir sut/file-separator))))) + (testing "Remove one trailing separator" (is (= base-dir (sut/remove-trailing-separator (str " " base-dir sut/file-separator " "))))))) (deftest create-dir-path - (let [expected-result (str sut/file-separator - "tmp" sut/file-separator - "foo" sut/file-separator - "bar" sut/file-separator)] - (testing "Creates a simple path" - (is (= expected-result - (sut/create-dir-path sut/file-separator "tmp" "foo" "bar")))) + (let [expected-result (str sut/file-separator "tmp" sut/file-separator "foo" sut/file-separator "bar" sut/file-separator)] + (testing "Creates a simple path" (is (= expected-result (sut/create-dir-path sut/file-separator "tmp" "foo" "bar")))) (testing "Don't add path separator if already there" - (is (= expected-result - (sut/create-dir-path (str) sut/file-separator "tmp" "foo" "bar")))) - (testing "Empty strings are filtered" - (is - (= - expected-result - (sut/create-dir-path (str) sut/file-separator "tmp" "" "foo" "bar")))) + (is (= expected-result (sut/create-dir-path (str) sut/file-separator "tmp" "foo" "bar")))) + (testing "Empty strings are filtered" (is (= expected-result (sut/create-dir-path (str) sut/file-separator "tmp" "" "foo" "bar")))) (testing "nil path returns nil" (is (= "./" (sut/create-dir-path)))) (testing "Trailing separator is not added if already there" - (is (= expected-result - (sut/create-dir-path sut/file-separator "tmp" "foo" "bar")))) + (is (= expected-result (sut/create-dir-path sut/file-separator "tmp" "foo" "bar")))) (testing "Relative path are working also" - (is (= (str "tmp" sut/file-separator - "foo" sut/file-separator - "bar" sut/file-separator) - (sut/create-dir-path "tmp" "foo" "bar")))))) + (is (= (str "tmp" sut/file-separator "foo" sut/file-separator "bar" sut/file-separator) (sut/create-dir-path "tmp" "foo" "bar")))))) (deftest create-file-path - (let [expected-result (str sut/file-separator - "tmp" - sut/file-separator - "foo" - sut/file-separator - "bar")] - (testing "Creates a simple path" - (is (= expected-result - (sut/create-file-path sut/file-separator "tmp" "foo" "bar")))) + (let [expected-result (str sut/file-separator "tmp" sut/file-separator "foo" sut/file-separator "bar")] + (testing "Creates a simple path" (is (= expected-result (sut/create-file-path sut/file-separator "tmp" "foo" "bar")))) (testing "Don't add path separator if already there" - (is (= - expected-result - (sut/create-file-path sut/file-separator (str) "tmp" "foo" "bar")))) - (testing "Empty strings are filtered" - (is (= expected-result - (sut/create-file-path sut/file-separator - (str) - "tmp" "" - "foo" "bar")))) - (testing "No parameters creates a root dir" - (is (= "." (sut/create-file-path)))) + (is (= expected-result (sut/create-file-path sut/file-separator (str) "tmp" "foo" "bar")))) + (testing "Empty strings are filtered" (is (= expected-result (sut/create-file-path sut/file-separator (str) "tmp" "" "foo" "bar")))) + (testing "No parameters creates a root dir" (is (= "." (sut/create-file-path)))) (testing "Trailing separator is not added if already there" - (is (= expected-result - (sut/create-file-path sut/file-separator "tmp" "foo" "bar")))) + (is (= expected-result (sut/create-file-path sut/file-separator "tmp" "foo" "bar")))) (testing "Relative path are working also" - (is (= (str "tmp" sut/file-separator "foo" sut/file-separator "bar") - (sut/create-file-path "tmp" "foo" "bar")))))) + (is (= (str "tmp" sut/file-separator "foo" sut/file-separator "bar") (sut/create-file-path "tmp" "foo" "bar")))))) (deftest change-extension (testing "Change the extension" @@ -138,60 +71,40 @@ (deftest create-dirs (testing "Testing an existing file" - (is (thrown-with-msg? clojure.lang.ExceptionInfo - #"Can't create a directory" - (sut/create-dirs "deps.edn")))) - (testing "Testing a possible directory" - (is (sut/create-dirs (sut/create-temp-dir))))) + (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Can't create a directory" (sut/create-dirs "deps.edn")))) + (testing "Testing a possible directory" (is (sut/create-dirs (sut/create-temp-dir))))) (deftest absolutize - (testing "Absolute don't change an absolute path" - (is (= "/foo" (sut/absolutize "/foo")))) - (testing "Absolute changes a relative path" - (is (not= "foo/bar" (sut/absolutize "foo/bar")))) + (testing "Absolute don't change an absolute path" (is (= "/foo" (sut/absolutize "/foo")))) + (testing "Absolute changes a relative path" (is (not= "foo/bar" (sut/absolutize "foo/bar")))) (testing "Nil is not failing" (is (nil? (sut/absolutize nil))))) -(deftest file-name - (testing "Extract file name" (is (= "baz" (sut/file-name "/foo/bar/baz"))))) +(deftest file-name (testing "Extract file name" (is (= "baz" (sut/file-name "/foo/bar/baz"))))) (deftest file-in-same-dir - (testing "Empty root directory is ok" - (is (= "foo" (sut/file-in-same-dir "" "foo")))) - (testing "If the source is directory, the files are stored in it" - (is (= ".clj-kondo/foo" (sut/file-in-same-dir ".clj-kondo" "foo")))) + (testing "Empty root directory is ok" (is (= "foo" (sut/file-in-same-dir "" "foo")))) + (testing "If the source is directory, the files are stored in it" (is (= ".clj-kondo/foo" (sut/file-in-same-dir ".clj-kondo" "foo")))) (testing "If the source is file, stored in the same parent" - (is (= "automaton/automaton-core/foo" - (sut/file-in-same-dir "automaton/automaton-core/deps.edn" "foo")))) + (is (= "automaton/automaton-core/foo" (sut/file-in-same-dir "automaton/automaton-core/deps.edn" "foo")))) (testing "If the source is file does not exist, store in the same parent" - (is (= "automaton/automaton-core/foo" - (sut/file-in-same-dir - "automaton/automaton-core/deps-does-not-exist.edn" - "foo"))))) + (is (= "automaton/automaton-core/foo" (sut/file-in-same-dir "automaton/automaton-core/deps-does-not-exist.edn" "foo"))))) -(deftest file-ized-test - (testing "- is replaced with _" (is (= "foo_bar" (sut/file-ized "foo-bar"))))) +(deftest file-ized-test (testing "- is replaced with _" (is (= "foo_bar" (sut/file-ized "foo-bar"))))) (deftest add-suffix-test - (testing "Add a suffix to file, between the name and the extension" - (is (= "core.mustache.clj" (sut/add-suffix "core.clj" ".mustache"))))) + (testing "Add a suffix to file, between the name and the extension" (is (= "core.mustache.clj" (sut/add-suffix "core.clj" ".mustache"))))) (deftest extract-path-test - (testing "A relative file returns nil" - (is (= "./" (sut/extract-path "README.md")))) - (testing "An absolute file returns nil" - (is (= "/usr/bin/" (sut/extract-path "/usr/bin/ls")))) + (testing "A relative file returns nil" (is (= "./" (sut/extract-path "README.md")))) + (testing "An absolute file returns nil" (is (= "/usr/bin/" (sut/extract-path "/usr/bin/ls")))) (testing "Extract a path from a file" (is (= "/foo/" (sut/extract-path "/foo/bar"))) (is (= "/foo/bar/foo2/" (sut/extract-path "/foo/bar/foo2/bar2"))))) (deftest filter-existing-dir-test - (testing "Only existing dir are filtered" - (is (= 1 - (count (sut/filter-existing-dir [".clj-kondo" - "non-existing-dir-filtered"])))))) + (testing "Only existing dir are filtered" (is (= 1 (count (sut/filter-existing-dir [".clj-kondo" "non-existing-dir-filtered"])))))) -(deftest empty-path? - (testing "Empty path" (is (sut/empty-path? (sut/create-temp-dir))))) +(deftest empty-path? (testing "Empty path" (is (sut/empty-path? (sut/create-temp-dir))))) (comment (keys (sut/create-files-map "foobar" "**{.clj,.cljs,.cljc,.edn}")) diff --git a/test/clj/automaton_core/adapters/schema_test.clj b/test/clj/automaton_core/adapters/schema_test.clj index dcf18217..89f411c6 100644 --- a/test/clj/automaton_core/adapters/schema_test.clj +++ b/test/clj/automaton_core/adapters/schema_test.clj @@ -3,20 +3,12 @@ [automaton-core.adapters.schema :as sut])) (deftest schema - (testing "Valid schema" - (is (sut/schema-valid [:tuple :string :int] ["hey" 12]))) - (testing "Invalid schema, throws an exception" - (is (not (sut/schema-valid [:tuple :string :int] [12 12]))))) + (testing "Valid schema" (is (sut/schema-valid [:tuple :string :int] ["hey" 12]))) + (testing "Invalid schema, throws an exception" (is (not (sut/schema-valid [:tuple :string :int] [12 12]))))) (deftest schema-valid-or-throw - (testing "Valid schema" - (is (sut/schema-valid-or-throw [:tuple :string :int] - ["hey" 12] - "Tuple shouldn't raise an exception"))) + (testing "Valid schema" (is (sut/schema-valid-or-throw [:tuple :string :int] ["hey" 12] "Tuple shouldn't raise an exception"))) (testing "Invalid schema, throws an exception" (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Tuple raises an exception" - (sut/schema-valid-or-throw - [:tuple :string :int] - [12 12] - "Tuple raises an exception"))))) + (sut/schema-valid-or-throw [:tuple :string :int] [12 12] "Tuple raises an exception"))))) diff --git a/test/clj/automaton_core/configuration/edn_read_test.clj b/test/clj/automaton_core/configuration/edn_read_test.clj index 28e3ce22..8bac30b8 100644 --- a/test/clj/automaton_core/configuration/edn_read_test.clj +++ b/test/clj/automaton_core/configuration/edn_read_test.clj @@ -5,5 +5,6 @@ (deftest read-edn-test (testing "Find the test configuration stub" - (is (= {:foo "bar", :bar 10} + (is (= {:foo "bar" + :bar 10} (sut/read-edn (io/resource "configuration/stub.edn")))))) diff --git a/test/clj/automaton_core/configuration/simple_files_test.clj b/test/clj/automaton_core/configuration/simple_files_test.clj index bc49fd3b..34105dd6 100644 --- a/test/clj/automaton_core/configuration/simple_files_test.clj +++ b/test/clj/automaton_core/configuration/simple_files_test.clj @@ -5,5 +5,6 @@ (deftest read-edn-test (testing "Find the test configuration stub" - (is (= {:foo "bar", :bar 10} + (is (= {:foo "bar" + :bar 10} (sut/read-edn (io/resource "configuration/stub.edn")))))) diff --git a/test/clj/automaton_core/log/be_log_test.clj b/test/clj/automaton_core/log/be_log_test.clj index 7e7ff461..9f67eeeb 100644 --- a/test/clj/automaton_core/log/be_log_test.clj +++ b/test/clj/automaton_core/log/be_log_test.clj @@ -9,57 +9,28 @@ [automaton-core.log.impl.log4j2])) (deftest log-test - (testing - "Log expand to text-based log4j2. Meaning the strategy applied at compile time, and as expected" + (testing "Log expand to text-based log4j2. Meaning the strategy applied at compile time, and as expected" (is (= (macroexpand `(l/trace "Hey")) - (macroexpand `(sut/log [:automaton-core.log.registry/text-based - :automaton-core.log.registry/error-tracking] - :trace - "Hey")))) - (is - (= `((juxt ~automaton-core.log.be-registry/no-op-fn) - ~*ns* - :trace - "Hey" - "Ho") - (macroexpand - `(sut/log [:automaton-core.log.registry/no-op] :trace "Hey" "Ho"))))) - (testing - "Fatal expand to print. Meaning the strategy applied at compile time, and as expected" - (is (= `((juxt ~automaton-core.log.impl.log4j2/log-fn - ~automaton-core.log.tracking.be-error-tracking/log-fn) - ~*ns* - :fatal - "Hey") + (macroexpand `(sut/log [:automaton-core.log.registry/text-based :automaton-core.log.registry/error-tracking] :trace "Hey")))) + (is (= `((juxt ~automaton-core.log.be-registry/no-op-fn) ~*ns* :trace "Hey" "Ho") + (macroexpand `(sut/log [:automaton-core.log.registry/no-op] :trace "Hey" "Ho"))))) + (testing "Fatal expand to print. Meaning the strategy applied at compile time, and as expected" + (is (= `((juxt ~automaton-core.log.impl.log4j2/log-fn ~automaton-core.log.tracking.be-error-tracking/log-fn) ~*ns* :fatal "Hey") (macroexpand `(l/fatal "Hey"))))) (testing "Fatal is happening and printing the expected string" - (is (= "Hey\n" - (with-out-str - (sut/log [:automaton-core.log.registry/print] :fatal "Hey"))))) + (is (= "Hey\n" (with-out-str (sut/log [:automaton-core.log.registry/print] :fatal "Hey"))))) (testing "Trace is happening and printing the expected string" - (is (= "Hey\n" - (with-out-str - (sut/log [:automaton-core.log.registry/print] :trace "Hey")))))) + (is (= "Hey\n" (with-out-str (sut/log [:automaton-core.log.registry/print] :trace "Hey")))))) (deftest fatal-exception-test (testing "Printed strategy applies to exception when fatal level is caught\n" - (is (str/starts-with? (with-out-str (sut/log-exception - [:automaton-core.log.registry/print] - :fatal - (ex-info "msg" {:data :foo}))) + (is (str/starts-with? (with-out-str (sut/log-exception [:automaton-core.log.registry/print] :fatal (ex-info "msg" {:data :foo}))) "#error {\n :cause msg")))) (deftest fatal-format-test (testing "Expansion" - (is (= `((juxt ~automaton-core.log.be-registry/simple-print) - ~*ns* - :fatal - (format "Hello %s and %s" "mati" "anthony")) - (macroexpand `(sut/log-format [:automaton-core.log.registry/print] - :fatal "Hello %s and %s" - "mati" "anthony"))))) + (is (= `((juxt ~automaton-core.log.be-registry/simple-print) ~*ns* :fatal (format "Hello %s and %s" "mati" "anthony")) + (macroexpand `(sut/log-format [:automaton-core.log.registry/print] :fatal "Hello %s and %s" "mati" "anthony"))))) (testing "Printed strategy applies to exception when fatal level is caught" (is (= "Hello mati and anthony\n" - (with-out-str (sut/log-format [:automaton-core.log.registry/print] - :fatal "Hello %s and %s" - "mati" "anthony")))))) + (with-out-str (sut/log-format [:automaton-core.log.registry/print] :fatal "Hello %s and %s" "mati" "anthony")))))) diff --git a/test/clj/automaton_core/utils/uuid_gen_test.clj b/test/clj/automaton_core/utils/uuid_gen_test.clj index 2c5af67c..37ad4733 100644 --- a/test/clj/automaton_core/utils/uuid_gen_test.clj +++ b/test/clj/automaton_core/utils/uuid_gen_test.clj @@ -4,11 +4,7 @@ (deftest time-based-uuid (testing "uuid and chonological orders are the same" - (let [vecs (map (fn [_n] (sut/time-based-uuid)) (range 10))] - (is (= (sort (map str vecs)) (map str vecs))))) + (let [vecs (map (fn [_n] (sut/time-based-uuid)) (range 10))] (is (= (sort (map str vecs)) (map str vecs))))) (testing "Is a uuid" (is (uuid? (sut/time-based-uuid)))) (testing "Timed based uuid are in the right order" - (dotimes [_ 10] - (let [uuid1 (sut/time-based-uuid) - uuid2 (sut/time-based-uuid)] - (is (compare (str uuid1) (str uuid2))))))) + (dotimes [_ 10] (let [uuid1 (sut/time-based-uuid) uuid2 (sut/time-based-uuid)] (is (compare (str uuid1) (str uuid2))))))) diff --git a/test/cljc/automaton_core/adapters/re_test.cljc b/test/cljc/automaton_core/adapters/re_test.cljc index 298a68ac..768a2947 100644 --- a/test/cljc/automaton_core/adapters/re_test.cljc +++ b/test/cljc/automaton_core/adapters/re_test.cljc @@ -1,30 +1,19 @@ (ns automaton-core.adapters.re-test (:require [automaton-core.adapters.re :as sut] #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]))) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]))) (deftest assemble-re-test - (testing "Test assembly of strings" - (is (= "abc" (sut/stringify (sut/assemble-re ["a" "b" "c"]))))) - (testing "Test assembly of re" - (is (= "abc" (sut/stringify (sut/assemble-re [#"a" #"b" #"c"]))))) - (testing "Test assembly of mixed" - (is (= "abc" (sut/stringify (sut/assemble-re [#"a" "b" #"c"])))))) + (testing "Test assembly of strings" (is (= "abc" (sut/stringify (sut/assemble-re ["a" "b" "c"]))))) + (testing "Test assembly of re" (is (= "abc" (sut/stringify (sut/assemble-re [#"a" #"b" #"c"]))))) + (testing "Test assembly of mixed" (is (= "abc" (sut/stringify (sut/assemble-re [#"a" "b" #"c"])))))) (deftest full-sentence-re-test (testing "Check terminators are working for clj and cljs" - (let [res (sut/stringify (sut/full-sentence-re #"foo"))] - (is (or (= res "\\Afoo\\z") (= res "^foo$")))))) + (let [res (sut/stringify (sut/full-sentence-re #"foo"))] (is (or (= res "\\Afoo\\z") (= res "^foo$")))))) (deftest assemble-re-optional-test (testing "Check optionality is added" - (is (= "foo?barfoo2" - (sut/stringify (sut/assemble-re-optional [#"foo" true "bar" false - "foo2" false]))))) + (is (= "foo?barfoo2" (sut/stringify (sut/assemble-re-optional [#"foo" true "bar" false "foo2" false]))))) (testing "Test prefix and suffix" - (is (= "afoo?barfoo2b" - (sut/stringify (sut/assemble-re-optional [#"foo" true "bar" false - "foo2" false] - "a" - "b")))))) + (is (= "afoo?barfoo2b" (sut/stringify (sut/assemble-re-optional [#"foo" true "bar" false "foo2" false] "a" "b")))))) diff --git a/test/cljc/automaton_core/adapters/string_test.cljc b/test/cljc/automaton_core/adapters/string_test.cljc index c4a9eea3..c12fbc90 100644 --- a/test/cljc/automaton_core/adapters/string_test.cljc +++ b/test/cljc/automaton_core/adapters/string_test.cljc @@ -1,24 +1,16 @@ (ns automaton-core.adapters.string-test (:require #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]) [automaton-core.adapters.string :as sut] [clojure.string :as str])) (deftest remove-last-character - (testing "Remove a character" - (is (= "This" (sut/remove-last-character "Thiss"))) - (is (= "This" (sut/remove-last-character "Thisù")))) - (testing "One character is removed" - (is (= "" (sut/remove-last-character "T"))) - (is (= "" (sut/remove-last-character "ù")))) - (testing "Empty string is ok" - (is (= "" (sut/remove-last-character ""))) - (is (= "" (sut/remove-last-character nil))))) + (testing "Remove a character" (is (= "This" (sut/remove-last-character "Thiss"))) (is (= "This" (sut/remove-last-character "Thisù")))) + (testing "One character is removed" (is (= "" (sut/remove-last-character "T"))) (is (= "" (sut/remove-last-character "ù")))) + (testing "Empty string is ok" (is (= "" (sut/remove-last-character ""))) (is (= "" (sut/remove-last-character nil))))) (deftest remove-first-last-character-test - (testing "Remove first and last character" - (is (= "bb" (sut/remove-first-last-character "abba")))) + (testing "Remove first and last character" (is (= "bb" (sut/remove-first-last-character "abba")))) (testing "Remove first and last character on small or empty string is ok" (is (= "" (sut/remove-first-last-character "aa") @@ -27,27 +19,18 @@ (sut/remove-first-last-character nil))))) (deftest limit-length-test - (testing "Ellipsis is limited to " - (is (= "f..." (sut/limit-length "foobar" 4))) - (is (= "fo..." (sut/limit-length "foobar" 5)))) + (testing "Ellipsis is limited to " (is (= "f..." (sut/limit-length "foobar" 4))) (is (= "fo..." (sut/limit-length "foobar" 5)))) (testing "Ellipsis doesn't change short enough string" (is (= "foobar" (sut/limit-length "foobar" 100))) (is (= "foobar" (sut/limit-length "foobar" 6)))) (testing "Prefix and suffix are taken into account" - (is (= "aafoobarbb" - (sut/limit-length "foobar" 10 "aa" "bb" (constantly nil)))) - (is (= "aafoobarbb" - (sut/limit-length "foobar" 1000 "aa" "bb" (constantly nil)))) - (is (= "aafo...bb" - (sut/limit-length "foobar" 9 "aa" "bb" (constantly nil)))))) + (is (= "aafoobarbb" (sut/limit-length "foobar" 10 "aa" "bb" (constantly nil)))) + (is (= "aafoobarbb" (sut/limit-length "foobar" 1000 "aa" "bb" (constantly nil)))) + (is (= "aafo...bb" (sut/limit-length "foobar" 9 "aa" "bb" (constantly nil)))))) (deftest remove-trailing-character-test (testing "Remove trailing character if needed" - (is (= "foo" - (sut/remove-trailing-character "foo/" \/) - (sut/remove-trailing-character "foo" \/)))) + (is (= "foo" (sut/remove-trailing-character "foo/" \/) (sut/remove-trailing-character "foo" \/)))) (testing "Empty strings are ok" (is (every? str/blank? - [(sut/remove-trailing-character "" \/) - (sut/remove-trailing-character nil \/) - (sut/remove-trailing-character "/" \/)])))) + [(sut/remove-trailing-character "" \/) (sut/remove-trailing-character nil \/) (sut/remove-trailing-character "/" \/)])))) diff --git a/test/cljc/automaton_core/i18n/dict/text_test.cljc b/test/cljc/automaton_core/i18n/dict/text_test.cljc index 60dab069..be6246fc 100644 --- a/test/cljc/automaton_core/i18n/dict/text_test.cljc +++ b/test/cljc/automaton_core/i18n/dict/text_test.cljc @@ -1,7 +1,6 @@ (ns automaton-core.i18n.dict.text-test (:require #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]) [automaton-core.i18n.dict.text :as sut] [automaton-core.i18n.language :as core-lang] [automaton-core.i18n.missing-translation-report :as b-language] @@ -9,15 +8,8 @@ [clojure.string :as str])) (deftest dict-test - (testing - (apply str - "Dictionary is matching all expected languages. List of languages to expect: " - (str/join " " core-lang/dict-core-languages-ids)) - (is (= [] - (b-language/key-with-missing-languages - sut/dict - core-lang/dict-core-languages-ids - #{:tongue/missing-key})))) - (testing "All languages are known languages" - (is (empty? (set/difference (set (keys sut/dict)) - core-lang/get-core-languages-id))))) + (testing (apply str + "Dictionary is matching all expected languages. List of languages to expect: " + (str/join " " core-lang/dict-core-languages-ids)) + (is (= [] (b-language/key-with-missing-languages sut/dict core-lang/dict-core-languages-ids #{:tongue/missing-key})))) + (testing "All languages are known languages" (is (empty? (set/difference (set (keys sut/dict)) core-lang/get-core-languages-id))))) diff --git a/test/cljc/automaton_core/i18n/language_test.cljc b/test/cljc/automaton_core/i18n/language_test.cljc index 043ac206..7fcdb401 100644 --- a/test/cljc/automaton_core/i18n/language_test.cljc +++ b/test/cljc/automaton_core/i18n/language_test.cljc @@ -1,24 +1,34 @@ (ns automaton-core.i18n.language-test (:require [automaton-core.i18n.language :as sut] #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]))) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]))) (deftest merge-languages-map-test (testing "Non selected languages are removed" (is (= {:fr {:id :fr}} - (sut/merge-languages-map {:fr {}, :en {}} {:fr {}})))) + (sut/merge-languages-map {:fr {} + :en {}} + {:fr {}})))) (testing "Supplementary key values are copied" - (is (= {:fr {:lvl 2, :id :fr, :lvl2 3}} - (sut/merge-languages-map {:fr {:lvl 1}, :en {:lvl 1}} - {:fr {:lvl 2, :lvl2 3}})))) + (is (= {:fr {:lvl 2 + :id :fr + :lvl2 3}} + (sut/merge-languages-map {:fr {:lvl 1} + :en {:lvl 1}} + {:fr {:lvl 2 + :lvl2 3}})))) (testing "Non existing languages in previous steps are removed" (is (= {} - (sut/merge-languages-map {:fr {:lvl 1}, :en {:lvl 1}} {:pl {}}))))) + (sut/merge-languages-map {:fr {:lvl 1} + :en {:lvl 1}} + {:pl {}}))))) (deftest selected-languages-test (testing "All language data are retrieved" - (is (= {:fr {:core-dict? true, :ui-text "FR", :desc "Français", :id :fr}} + (is (= {:fr {:core-dict? true + :ui-text "FR" + :desc "Français" + :id :fr}} (:languages (sut/make-automaton-core-languages {:fr {}}))))) (testing "Keys specified are found" (is (= :bar @@ -27,12 +37,15 @@ :fr :foo)))) (testing "Multiple maps arguments are merged " - (is (= {:fr {:lvl 2, :id :fr}} - (sut/merge-languages-map {:fr {:lvl 1}, :en {:lvl 1}} + (is (= {:fr {:lvl 2 + :id :fr}} + (sut/merge-languages-map {:fr {:lvl 1} + :en {:lvl 1}} {:fr {:lvl 2}}))))) (deftest get-lang-test (testing "Returning a language" - (let [lang (sut/make-automaton-core-languages {:fr {:lvl 1}, :en {:lvl 1}} + (let [lang (sut/make-automaton-core-languages {:fr {:lvl 1} + :en {:lvl 1}} {:fr {:lvl 2}})] (is (map? (sut/language lang :fr)))))) diff --git a/test/cljc/automaton_core/i18n/missing_translation_report_test.cljc b/test/cljc/automaton_core/i18n/missing_translation_report_test.cljc index 716e7ef2..74b448ac 100644 --- a/test/cljc/automaton_core/i18n/missing_translation_report_test.cljc +++ b/test/cljc/automaton_core/i18n/missing_translation_report_test.cljc @@ -1,47 +1,40 @@ (ns automaton-core.i18n.missing-translation-report-test (:require #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]) [automaton-core.i18n.missing-translation-report :as sut])) (def dic-sample "Dictionary sample" - {:en {:bar "anthony", :nested {:one "hey", :two "ho"}, :en-only "yep"}, - :esperanto {:bar "mati", :esp-only "yeah"}}) + {:en {:bar "anthony" + :nested {:one "hey" + :two "ho"} + :en-only "yep"} + :esperanto {:bar "mati" + :esp-only "yeah"}}) (deftest language-report (testing "List keys and their set languages" - (is (= {:bar #{:esperanto :en}, - :nested.one #{:en}, - :nested.two #{:en}, - :en-only #{:en}, + (is (= {:bar #{:esperanto :en} + :nested.one #{:en} + :nested.two #{:en} + :en-only #{:en} :esp-only #{:esperanto}} (sut/language-report dic-sample #{:en :esperanto})))) (testing "Language report contains only expected ones" - (is (= - {:bar #{:en}, :nested.one #{:en}, :nested.two #{:en}, :en-only #{:en}} - (sut/language-report dic-sample #{:en}))))) + (is (= {:bar #{:en} + :nested.one #{:en} + :nested.two #{:en} + :en-only #{:en}} + (sut/language-report dic-sample #{:en}))))) (deftest key-with-missing-languages (testing "Return keys with missing languages" - (is (= [[:esp-only #{:esperanto}] [:nested.one #{:en}] [:nested.two #{:en}] - [:en-only #{:en}]] + (is (= [[:esp-only #{:esperanto}] [:nested.one #{:en}] [:nested.two #{:en}] [:en-only #{:en}]] (sut/key-with-missing-languages dic-sample #{:en :esperanto} [])))) (testing "Keys could be excluded" (is (= [[:esp-only #{:esperanto}] [:nested.two #{:en}] [:en-only #{:en}]] - (sut/key-with-missing-languages dic-sample - #{:en :esperanto} - [:nested.one]))) + (sut/key-with-missing-languages dic-sample #{:en :esperanto} [:nested.one]))) (is (= [[:esp-only #{:esperanto}] [:nested.two #{:en}]] - (sut/key-with-missing-languages dic-sample - #{:en :esperanto} - [:nested.one :en-only]))) - (is (= [[:esp-only #{:esperanto}]] - (sut/key-with-missing-languages dic-sample - #{:en :esperanto} - [:nested.one :en-only :nested.two]))) - (is (= [] - (sut/key-with-missing-languages dic-sample - #{:en :esperanto} - [:nested.one :en-only :nested.two - :esp-only]))))) + (sut/key-with-missing-languages dic-sample #{:en :esperanto} [:nested.one :en-only]))) + (is (= [[:esp-only #{:esperanto}]] (sut/key-with-missing-languages dic-sample #{:en :esperanto} [:nested.one :en-only :nested.two]))) + (is (= [] (sut/key-with-missing-languages dic-sample #{:en :esperanto} [:nested.one :en-only :nested.two :esp-only]))))) diff --git a/test/cljc/automaton_core/i18n/translator/tempura_test.cljc b/test/cljc/automaton_core/i18n/translator/tempura_test.cljc index 000acf22..e2a8e1e9 100644 --- a/test/cljc/automaton_core/i18n/translator/tempura_test.cljc +++ b/test/cljc/automaton_core/i18n/translator/tempura_test.cljc @@ -1,17 +1,17 @@ (ns automaton-core.i18n.translator.tempura-test (:require #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]) [automaton-core.i18n.language :as core-lang] [automaton-core.i18n.translator :as core-translator] [automaton-core.i18n.translator.tempura :as sut])) -(def dict-stub {:en {:foo "bar-en"}, :fr {:foo "bar-fr"}}) +(def dict-stub + {:en {:foo "bar-en"} + :fr {:foo "bar-fr"}}) (deftest tempura-missing-text-test (testing "All languages in the dictionary have a missing key" - (is (= core-lang/dict-core-languages-ids - (set (keys sut/tempura-missing-text)))) + (is (= core-lang/dict-core-languages-ids (set (keys sut/tempura-missing-text)))) (is (= core-lang/dict-core-languages-ids (->> (filter (fn [[_k v]] (:missing v)) sut/tempura-missing-text) (map first) @@ -20,30 +20,20 @@ (deftest TempuraTranslator-test (testing "Is the specified language working" (is (= (get-in sut/tempura-missing-text [:en :missing]) - (let [test-translator (sut/make-translator [:fr] - sut/tempura-missing-text - dict-stub)] + (let [test-translator (sut/make-translator [:fr] sut/tempura-missing-text dict-stub)] (core-translator/translate test-translator [:en] :missing [])))) (is (= (get-in sut/tempura-missing-text [:fr :missing]) - (let [test-translator (sut/make-translator [:en] - sut/tempura-missing-text - dict-stub)] + (let [test-translator (sut/make-translator [:en] sut/tempura-missing-text dict-stub)] (core-translator/translate test-translator [:fr] :missing []))))) - (testing - "If no language is specified during translation, is the default language used?" + (testing "If no language is specified during translation, is the default language used?" (is (= (get-in sut/tempura-missing-text [:fr :missing]) - (let [test-translator (sut/make-translator [:fr] - sut/tempura-missing-text - dict-stub)] + (let [test-translator (sut/make-translator [:fr] sut/tempura-missing-text dict-stub)] (core-translator/translate test-translator [] :missing [])))) (is (= (get-in sut/tempura-missing-text [:en :missing]) - (let [test-translator (sut/make-translator [:en] - sut/tempura-missing-text - dict-stub)] + (let [test-translator (sut/make-translator [:en] sut/tempura-missing-text dict-stub)] (core-translator/translate test-translator [] :missing []))))) (testing "Are the dictionaries found" - (let [translator - (sut/make-translator [:en] sut/tempura-missing-text dict-stub)] + (let [translator (sut/make-translator [:en] sut/tempura-missing-text dict-stub)] (is (= "bar-en" (-> translator (core-translator/translate [] :foo [])) diff --git a/test/cljc/automaton_core/log/log_levels_test.cljc b/test/cljc/automaton_core/log/log_levels_test.cljc index 87babff0..1caacf8f 100644 --- a/test/cljc/automaton_core/log/log_levels_test.cljc +++ b/test/cljc/automaton_core/log/log_levels_test.cljc @@ -1,13 +1,10 @@ (ns automaton-core.log.log-levels-test (:require [automaton-core.log.log-levels :as sut] #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]))) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]))) (deftest execute-level? - (testing "Logs of same or higher level are accepted" - (is (sut/execute-level? :trace :trace)) - (is (sut/execute-level? :fatal :fatal))) + (testing "Logs of same or higher level are accepted" (is (sut/execute-level? :trace :trace)) (is (sut/execute-level? :fatal :fatal))) (testing "Logs of strictly lower level are rejected" (is (not (sut/execute-level? nil :trace))) (is (not (sut/execute-level? :debug :trace))) diff --git a/test/cljc/automaton_core/log/strategy/static_ns_level_test.cljc b/test/cljc/automaton_core/log/strategy/static_ns_level_test.cljc index fcc85e4d..5370499f 100644 --- a/test/cljc/automaton_core/log/strategy/static_ns_level_test.cljc +++ b/test/cljc/automaton_core/log/strategy/static_ns_level_test.cljc @@ -1,7 +1,6 @@ (ns automaton-core.log.strategy.static-ns-level-test (:require #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]) [automaton-core.log.strategy :as log-strategy] [automaton-core.log.registry :as log-registry] [automaton-core.log.strategy.static-ns-level :as sut])) @@ -9,18 +8,17 @@ (deftest ns-rules-test (let [ns-chooser-stub (sut/make-static-ns-level-strategy sut/ns-rules) ns-rules-map-stub (into {} - (map (fn [{:keys [rule-id], :as rule}] [rule-id - rule]) - (:ns-rules ns-chooser-stub))) + (map (fn [{:keys [rule-id] + :as rule}] + [rule-id rule]) + (:ns-rules ns-chooser-stub))) test-ns (fn [rule-id test-ns] (some-> rule-id (ns-rules-map-stub) :re (re-find test-ns)))] - (testing - "Check all used strategies are known strategies in `automaton-core.log.strategy/registry`" - (is (every? (set (keys log-registry/strategies-registry)) - (log-strategy/rule-ids ns-chooser-stub)))) + (testing "Check all used strategies are known strategies in `automaton-core.log.strategy/registry`" + (is (every? (set (keys log-registry/strategies-registry)) (log-strategy/rule-ids ns-chooser-stub)))) (testing "List of rule application we want to enforce through tests" (is (test-ns :rule1 "automaton-core")) (is (test-ns :rule1 "automaton-core.log")) @@ -29,32 +27,27 @@ (deftest apply-ns-rule-test (let [ns-chooser-stub (sut/make-static-ns-level-strategy sut/ns-rules) ns-rules-map-stub (into {} - (map (fn [{:keys [rule-id], :as rule}] [rule-id - rule]) - (:ns-rules ns-chooser-stub))) + (map (fn [{:keys [rule-id] + :as rule}] + [rule-id rule]) + (:ns-rules ns-chooser-stub))) get-stubbed-rule (fn [rule-id] (rule-id ns-rules-map-stub))] (testing "ns outside the scope are rejected" (is (nil? (sut/apply-ns-rule "other ns" (get-stubbed-rule :rule1)))) - (is (nil? (sut/apply-ns-rule "automaton-core" - (get-stubbed-rule :rule2))))) + (is (nil? (sut/apply-ns-rule "automaton-core" (get-stubbed-rule :rule2))))) (testing "ns matching the scope are accepted" (is (map? (sut/apply-ns-rule "automaton-core" (get-stubbed-rule :rule1)))) - (is (map? (sut/apply-ns-rule "automaton-core.log" - (get-stubbed-rule :rule2)))) - (is (map? (sut/apply-ns-rule "automaton-core.log" - (get-stubbed-rule :rule1))))))) + (is (map? (sut/apply-ns-rule "automaton-core.log" (get-stubbed-rule :rule2)))) + (is (map? (sut/apply-ns-rule "automaton-core.log" (get-stubbed-rule :rule1))))))) (deftest choose-logger-test (let [ns-chooser-stub (sut/make-static-ns-level-strategy sut/ns-rules) apply-strategy* (partial log-strategy/apply-strategy ns-chooser-stub)] (testing "One matching is returning the expected match" - (is (= [:automaton-core.log.registry/print] - (apply-strategy* "automaton-core" :fatal)))) + (is (= [:automaton-core.log.registry/print] (apply-strategy* "automaton-core" :fatal)))) (testing "Among many matches the first one is returned" - (is (= [:automaton-core.log.registry/print] - (apply-strategy* "automaton-core.log" :fatal)))) + (is (= [:automaton-core.log.registry/print] (apply-strategy* "automaton-core.log" :fatal)))) (testing "Default logger is text-based and error-tracking" - (is (= [:automaton-core.log.registry/text-based - :automaton-core.log.registry/error-tracking] + (is (= [:automaton-core.log.registry/text-based :automaton-core.log.registry/error-tracking] (apply-strategy* "non-existing-namespace" :fatal)))))) diff --git a/test/cljc/automaton_core/url_test.cljc b/test/cljc/automaton_core/url_test.cljc index dead66b3..38cb4bc7 100644 --- a/test/cljc/automaton_core/url_test.cljc +++ b/test/cljc/automaton_core/url_test.cljc @@ -1,7 +1,6 @@ (ns automaton-core.url-test (:require #?@(:clj [[clojure.test :refer [deftest is testing]]] - :cljs [[cljs.test :refer [deftest is testing] :include-macros - true]]) + :cljs [[cljs.test :refer [deftest is testing] :include-macros true]]) [automaton-core.url :as sut])) (deftest extract-tld-from-host-test @@ -14,39 +13,31 @@ (is (= "com" (sut/extract-tld-from-host "http://hephaistox.com:3000"))) (is (= "uk" (sut/extract-tld-from-host "hephaistox.co.uk"))) (is (= "fr" (sut/extract-tld-from-host "http://hephaistox.fr")))) - (testing "Compatible with multiple domaines" - (is (= "fr" - (sut/extract-tld-from-host "http://www.subdomain.hephaistox.fr")))) + (testing "Compatible with multiple domaines" (is (= "fr" (sut/extract-tld-from-host "http://www.subdomain.hephaistox.fr")))) (testing "Localhost are compatible" (is (nil? (sut/extract-tld-from-host "localhost"))) (is (nil? (sut/extract-tld-from-host "192.168.0.01"))))) (deftest compare-locations-test (testing "Exact same are accepted" - (is (sut/compare-locations "http://www.hephaistox.com/foo'bar?lang=en" - "http://www.hephaistox.com/foo'bar?lang=en")) + (is (sut/compare-locations "http://www.hephaistox.com/foo'bar?lang=en" "http://www.hephaistox.com/foo'bar?lang=en")) (is (sut/compare-locations "http://www.hephaistox.com/foo'bar?lang=en" "http://www.hephaistox.com/foo'bar?lang=en" "http://www.hephaistox.com/foo'bar?lang=en"))) (testing "Exact same are discarded" - (is (not (sut/compare-locations - "http://www.hephaistox.com/foo'bar?lang=en" - "http://www.hephaistox.com/foo'bar?lang=fr" - "http://www.hephaistox.com/foo'bar?lang=en")))) - (testing "Compare relative and fullpath" - (is (sut/compare-locations "http://www.hephaistox.com/foo'bar?lang=en" - "/foo'bar?lang=en")))) + (is (not (sut/compare-locations "http://www.hephaistox.com/foo'bar?lang=en" + "http://www.hephaistox.com/foo'bar?lang=fr" + "http://www.hephaistox.com/foo'bar?lang=en")))) + (testing "Compare relative and fullpath" (is (sut/compare-locations "http://www.hephaistox.com/foo'bar?lang=en" "/foo'bar?lang=en")))) (deftest parse-queries-test (testing "Simple params" - (is (= {:par "foo", :bar "barfoo"} + (is (= {:par "foo" + :bar "barfoo"} (sut/parse-queries "?par=foo&bar=barfoo"))) (is (= {:par ""} (sut/parse-queries "?par=")))) - (testing "No params" - (is (nil? (sut/parse-queries "?"))) - (is (nil? (sut/parse-queries ""))) - (is (nil? (sut/parse-queries nil)))) + (testing "No params" (is (nil? (sut/parse-queries "?"))) (is (nil? (sut/parse-queries ""))) (is (nil? (sut/parse-queries nil)))) (testing "Complete url analysis" - (is (= {:par "foo", :bar "barfoo"} - (sut/parse-queries - "http://hephaistox.com:3000?par=foo&bar=barfoo#foobar"))))) + (is (= {:par "foo" + :bar "barfoo"} + (sut/parse-queries "http://hephaistox.com:3000?par=foo&bar=barfoo#foobar"))))) diff --git a/test/cljc/automaton_core/utils/fallback_test.cljc b/test/cljc/automaton_core/utils/fallback_test.cljc index 892ae1e6..89ee75d9 100644 --- a/test/cljc/automaton_core/utils/fallback_test.cljc +++ b/test/cljc/automaton_core/utils/fallback_test.cljc @@ -1,9 +1,7 @@ (ns automaton-core.utils.fallback-test (:require [automaton-core.utils.fallback :as sut] #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]))) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]))) (deftest always-return-test - (testing "When there is no exception function value is returned." - (is (= (sut/always-return (fn [] 34) 15) 34)))) + (testing "When there is no exception function value is returned." (is (= (sut/always-return (fn [] 34) 15) 34)))) diff --git a/test/cljc/automaton_core/utils/map_test.cljc b/test/cljc/automaton_core/utils/map_test.cljc index 7ceb90c3..3c348a5e 100644 --- a/test/cljc/automaton_core/utils/map_test.cljc +++ b/test/cljc/automaton_core/utils/map_test.cljc @@ -1,91 +1,133 @@ (ns automaton-core.utils.map-test (:require [automaton-core.utils.map :as sut] #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]))) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]))) (def v ["a" "b" "c"]) (filter #(= "b" (second %)) (map-indexed vector v)) (deftest idx-of-test - (testing "Basic case" - (is (= 0 (sut/idx-of v "a"))) - (is (= 1 (sut/idx-of v "b"))) - (is (= 2 (sut/idx-of v "c")))) + (testing "Basic case" (is (= 0 (sut/idx-of v "a"))) (is (= 1 (sut/idx-of v "b"))) (is (= 2 (sut/idx-of v "c")))) (testing "not found values return nil" (is (nil? (sut/idx-of v "z")))) - (testing "nil values are ok" - (is (nil? (sut/idx-of v nil))) - (is (nil? (sut/idx-of nil "v"))))) + (testing "nil values are ok" (is (nil? (sut/idx-of v nil))) (is (nil? (sut/idx-of nil "v"))))) (def v2 [{:foo :bar} {:foo :bar2}]) (deftest idx-of-pred-test (testing "Basic case" (is (= 0 (sut/idx-of-pred v2 #(= :bar (:foo %)))))) - (testing "not found values return nil" - (is (nil? (sut/idx-of-pred v #(= :not-existing (:foo %)))))) - (testing "nil values are ok" - (is (nil? (sut/idx-of-pred v nil))) - (is (nil? (sut/idx-of-pred nil "v"))))) + (testing "not found values return nil" (is (nil? (sut/idx-of-pred v #(= :not-existing (:foo %)))))) + (testing "nil values are ok" (is (nil? (sut/idx-of-pred v nil))) (is (nil? (sut/idx-of-pred nil "v"))))) (deftest crush-test (testing "Crush function contract" - (is (= {:foo.bar.go "???", - :foo2.bar2.go2 "!!!", - :foo2.bar2.go3 ")))", + (is (= {:foo.bar.go "???" + :foo2.bar2.go2 "!!!" + :foo2.bar2.go3 ")))" :foo2.bar3 "foo"} - (sut/crush {:foo {:bar {:go "???"}}, - :foo2 {:bar2 {:go2 "!!!", :go3 ")))"}, :bar3 "foo"}}))))) + (sut/crush {:foo {:bar {:go "???"}} + :foo2 {:bar2 {:go2 "!!!" + :go3 ")))"} + :bar3 "foo"}}))))) (deftest deep-merge-test (testing "last map has higher priority" - (is (= {:one 1, :two {}} - (sut/deep-merge {:one 1, :two 2} {:one 1, :two {}})))) + (is (= {:one 1 + :two {}} + (sut/deep-merge {:one 1 + :two 2} + {:one 1 + :two {}})))) (testing "Two level of nest" - (is (= {:one 1, :two {:three {:test true}, :four {:five 5}}} - (sut/deep-merge {:one 1, :two {:three 3, :four {:five 5}}} + (is (= {:one 1 + :two {:three {:test true} + :four {:five 5}}} + (sut/deep-merge {:one 1 + :two {:three 3 + :four {:five 5}}} {:two {:three {:test true}}})))) (testing "Two level of nest" - (is (= {:one {:two {:three "three", :nine 9}, :seven 7}, - :four {:five 5, :eight 8}, + (is (= {:one {:two {:three "three" + :nine 9} + :seven 7} + :four {:five 5 + :eight 8} :ten 10} - (sut/deep-merge {:one {:two {:three 3}}, :four {:five {:six 6}}} - {:one {:seven 7, :two {:three "three", :nine 9}}, - :four {:eight 8, :five 5}, + (sut/deep-merge {:one {:two {:three 3}} + :four {:five {:six 6}}} + {:one {:seven 7 + :two {:three "three" + :nine 9}} + :four {:eight 8 + :five 5} :ten 10})))) (testing "Non conflicting keys are merged" - (is (= {:one {:two 2, :three 3, :four 4, :five 5}} - (sut/deep-merge {:one {:two 2, :three 3}} - {:one {:four 4, :five 5}})))) + (is (= {:one {:two 2 + :three 3 + :four 4 + :five 5}} + (sut/deep-merge {:one {:two 2 + :three 3}} + {:one {:four 4 + :five 5}})))) (testing "Nil is working as an empty map" - (is (= {:one 1, :two {:three 3}} - (sut/deep-merge {:one 1, :two {:three 3}} nil)))) + (is (= {:one 1 + :two {:three 3}} + (sut/deep-merge {:one 1 + :two {:three 3}} + nil)))) (testing "Nil is working as an empty map in complex list" - (is (= {:one 1, :two {:three 3, :fourth 4, :fifth 5}} - (sut/deep-merge {:one 1, :two {:three 3}} + (is (= {:one 1 + :two {:three 3 + :fourth 4 + :fifth 5}} + (sut/deep-merge {:one 1 + :two {:three 3}} nil - {:one 1, :two {:fourth 4}} + {:one 1 + :two {:fourth 4}} nil nil - {:one 1, :two {:fifth 5}})))) + {:one 1 + :two {:fifth 5}})))) (testing "Multiple maps are manager, last one is higher priority" - (is (= {:one 4, :two {:three 6}} - (sut/deep-merge {:one 1, :two {:three 3}} - {:one 2, :two {:three 4}} - {:one 3, :two {:three 5}} - {:one 4, :two {:three 6}}))))) + (is (= {:one 4 + :two {:three 6}} + (sut/deep-merge {:one 1 + :two {:three 3}} + {:one 2 + :two {:three 4}} + {:one 3 + :two {:three 5}} + {:one 4 + :two {:three 6}}))))) (deftest add-ids-test (testing "Simple maps" - (is (= {:foo {:bar "bar", :id :foo}, :bar {:foo "foo", :id :bar}} - (sut/add-ids {:foo {:bar "bar"}, :bar {:foo "foo"}})))) + (is (= {:foo {:bar "bar" + :id :foo} + :bar {:foo "foo" + :id :bar}} + (sut/add-ids {:foo {:bar "bar"} + :bar {:foo "foo"}})))) (testing "Non map values are unchanged" - (is (= {:foo "bar", :bar "foo"} (sut/add-ids {:foo "bar", :bar "foo"})))) + (is (= {:foo "bar" + :bar "foo"} + (sut/add-ids {:foo "bar" + :bar "foo"})))) (testing "Empty maps are ok" (is (= {} (sut/add-ids {}))))) (deftest update-kw-test (testing "Update is ok, non selected keys are excluded" - (is (= {:foo "arg", :foo2 :bar2} - (sut/update-kw {:foo :bar, :foo2 :bar2} [:foo] (fn [_] "arg"))))) + (is (= {:foo "arg" + :foo2 :bar2} + (sut/update-kw {:foo :bar + :foo2 :bar2} + [:foo] + (fn [_] "arg"))))) (testing "No keyword doesn't modify the map" - (is (= {:foo :bar, :foo2 :bar2} - (sut/update-kw {:foo :bar, :foo2 :bar2} [] (fn [_] "arg")))))) + (is (= {:foo :bar + :foo2 :bar2} + (sut/update-kw {:foo :bar + :foo2 :bar2} + [] + (fn [_] "arg")))))) diff --git a/test/cljc/automaton_core/utils/sequences_test.cljc b/test/cljc/automaton_core/utils/sequences_test.cljc index 309e8630..3d809703 100644 --- a/test/cljc/automaton_core/utils/sequences_test.cljc +++ b/test/cljc/automaton_core/utils/sequences_test.cljc @@ -1,8 +1,7 @@ (ns automaton-core.utils.sequences-test (:require [automaton-core.utils.sequences :as sut] #?(:clj [clojure.test :refer [deftest is testing]] - :cljs [cljs.test :refer [deftest is testing] :include-macros - true]) + :cljs [cljs.test :refer [deftest is testing] :include-macros true]) [clojure.string :as str])) (deftest trim-leading-nil-test @@ -10,8 +9,7 @@ (is (= ["a" "b"] (sut/trim-leading-nil ["a" "b"]))) (is (= ["a" "b"] (sut/trim-leading-nil ["a" "b" nil]))) (is (= ["a" "b"] (sut/trim-leading-nil ["a" "b" nil nil nil nil]))) - (is (= [nil "a" nil nil "b"] - (sut/trim-leading-nil [nil "a" nil nil "b" nil nil nil nil])))) + (is (= [nil "a" nil nil "b"] (sut/trim-leading-nil [nil "a" nil nil "b" nil nil nil nil])))) (testing "edge cases" (is (empty? (sut/trim-leading-nil [nil nil nil nil nil]))) (is (empty? (sut/trim-leading-nil []))) @@ -19,5 +17,4 @@ (testing "Test other fn usage" (is (= ["a" "b"] (sut/trim-leading-nil ["a" "b" nil nil nil nil] nil?))) (is (empty? (sut/trim-leading-nil ["a" "b"] string?))) - (is (= ["a" "b"] - (sut/trim-leading-nil ["a" "b" nil nil "" ""] str/blank?))))) + (is (= ["a" "b"] (sut/trim-leading-nil ["a" "b" nil nil "" ""] str/blank?))))) diff --git a/test/cljc/automaton_core/utils/uuid_gen_test.cljc b/test/cljc/automaton_core/utils/uuid_gen_test.cljc index 81236f94..db6f1cb7 100644 --- a/test/cljc/automaton_core/utils/uuid_gen_test.cljc +++ b/test/cljc/automaton_core/utils/uuid_gen_test.cljc @@ -2,6 +2,4 @@ (:require [automaton-core.utils.uuid-gen :as sut] [clojure.test :refer [testing deftest is]])) -(deftest unguessable - (testing "check that generates proper uuid" - (is (every? uuid? (repeatedly 10 #(sut/unguessable)))))) +(deftest unguessable (testing "check that generates proper uuid" (is (every? uuid? (repeatedly 10 #(sut/unguessable)))))) diff --git a/test/cljs/automaton_core/log/fe_log_test.cljs b/test/cljs/automaton_core/log/fe_log_test.cljs index da6f2e66..c9562578 100644 --- a/test/cljs/automaton_core/log/fe_log_test.cljs +++ b/test/cljs/automaton_core/log/fe_log_test.cljs @@ -4,31 +4,16 @@ (deftest fatal-test (testing "Fatal is always printing something" - (is - (= "foo bar" - (with-out-str - (sut/log [:automaton-core.log.registry/print] :fatal "foo" "bar"))))) + (is (= "foo bar" (with-out-str (sut/log [:automaton-core.log.registry/print] :fatal "foo" "bar"))))) (testing "Macroexpansion is resolving until the key of the chosen method" (is - (= - '((clojure.core/apply - clojure.core/juxt - (automaton-core.log.fe-log/logger-ids-to-logger-fns - [:automaton-core.log.registry/print])) + (= '((clojure.core/apply clojure.core/juxt (automaton-core.log.fe-log/logger-ids-to-logger-fns [:automaton-core.log.registry/print])) "automaton-core.log.fe-log-test" :fatal "foo" "bar") - (macroexpand '(sut/log - [:automaton-core.log.registry/print] - :fatal - "foo" - "bar")))))) + (macroexpand '(sut/log [:automaton-core.log.registry/print] :fatal "foo" "bar")))))) (deftest trace-test (testing "Trace is not accepted in log namespace test rule" - (is (= "" - (with-out-str (sut/log [:automaton-core.log.registry/no-op] - :trace - "foo" - "bar")))))) + (is (= "" (with-out-str (sut/log [:automaton-core.log.registry/no-op] :trace "foo" "bar")))))) diff --git a/test/resources/configuration/stub.edn b/test/resources/configuration/stub.edn index 25f53855..660061b6 100644 --- a/test/resources/configuration/stub.edn +++ b/test/resources/configuration/stub.edn @@ -1 +1,2 @@ -{:bar 10, :foo "bar"} +{:bar 10 + :foo "bar"} diff --git a/version.edn b/version.edn index 55ea7afc..98e8a888 100644 --- a/version.edn +++ b/version.edn @@ -1,3 +1,4 @@ -;; Last generated version, note a failed push consume a number Mon Oct 30 -;; 21:14:16 CET 2023 -{:major-version "0.0.-1", :minor-version 0, :version "0.0.0"} \ No newline at end of file +;; Last generated version, note a failed push consume a number Wed Nov 8 12:52:22 CET 2023 +{:major-version "0.0.-1" + :minor-version 2 + :version "0.0.2"} \ No newline at end of file