diff --git a/src/dctest/core.cljs b/src/dctest/core.cljs index d2b582c..057cf94 100644 --- a/src/dctest/core.cljs +++ b/src/dctest/core.cljs @@ -5,10 +5,10 @@ (:require [cljs-bean.core :refer [->clj]] [clojure.edn :as edn] [clojure.string :as S] - [clojure.pprint :refer [pprint]] - [dctest.util :as util :refer [fatal obj->str log]] + [dctest.util :as util :refer [obj->str log]] [promesa.core :as P] [viasat.retry :as retry] + [viasat.util :refer [fatal parse-opts write-file]] ["stream" :as stream] #_["dockerode$default" :as Docker] )) @@ -232,7 +232,7 @@ Options: (defn write-results-file [opts summary] (when-let [path (:results-file opts)] - (util/write-file path (obj->str summary)))) + (write-file path (obj->str summary)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Load Suite @@ -274,7 +274,7 @@ Options: ;; Main (defn -main [& argv] - (P/let [opts (util/parse-opts usage (or argv #js [])) + (P/let [opts (parse-opts usage (or argv #js [])) {:keys [continue-on-error quiet project test-suite]} opts suites (P/all diff --git a/src/dctest/util.cljs b/src/dctest/util.cljs index 912a70e..44fdbdf 100644 --- a/src/dctest/util.cljs +++ b/src/dctest/util.cljs @@ -7,48 +7,20 @@ [clojure.string :as S] [clojure.pprint :refer [pprint]] [promesa.core :as P] + [viasat.util :refer [Eprintln fatal read-file]] ["js-yaml" :as yaml] - ["fs" :as fs] - ["neodoc" :as neodoc] - ["util" :refer [promisify]] #_["ajv$default" :as Ajv] )) ;; TODO: use require syntax when shadow-cljs works with "*$default" (def Ajv (js/require "ajv")) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Argument processing - -(defn clean-opts [arg-map] - (reduce (fn [o [a v]] - (let [k (keyword (S/replace a #"^[-<]*([^>]*)[>]*$" "$1"))] - (assoc o k (or (get o k) v)))) - {} arg-map)) - -(defn parse-opts [usage argv] - (-> usage - (neodoc/run (clj->js {:optionsFirst true - :smartOptions true - :argv argv})) - js->clj - clean-opts)) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; General functions (defn obj->str [obj] (js/JSON.stringify (clj->js obj))) -(def Eprn #(binding [*print-fn* *print-err-fn*] (apply prn %&))) -(def Eprintln #(binding [*print-fn* *print-err-fn*] (apply println %&))) -(def Epprint #(binding [*print-fn* *print-err-fn*] (pprint %))) - -(defn fatal [code & args] - (when (seq args) - (apply Eprintln args)) - (js/process.exit code)) - (defn log [opts & args] (when-not (:quiet opts) (apply println args))) @@ -69,9 +41,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; File functions -(def read-file (promisify (.-readFile fs))) -(def write-file (promisify (.-writeFile fs))) - (defn load-yaml [path] (P/let [buffer (read-file path)] (try