From 4d15a0544e3ace67be668ca6e051802979668e54 Mon Sep 17 00:00:00 2001 From: Christophe Grand Date: Thu, 10 Oct 2024 18:10:42 +0200 Subject: [PATCH] support for :dart.test/dir ns meta to allow emitting tests to different dirs --- clj/src/cljd/compiler.cljc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/clj/src/cljd/compiler.cljc b/clj/src/cljd/compiler.cljc index 35587916..639f21f5 100644 --- a/clj/src/cljd/compiler.cljc +++ b/clj/src/cljd/compiler.cljc @@ -256,7 +256,6 @@ (def ^:dynamic *host-eval* false) (def ^:dynamic ^String *lib-path* "lib/") -(def ^:dynamic ^String *test-path* "test/") (def ^:dynamic *target-subdir* "Relative path to the lib directory (*lib-dir*) where compiled dart file will be put. @@ -3236,7 +3235,8 @@ (defn emit-ns [[_ ns-sym & ns-clauses :as ns-form] _] (when (or (not *hosted*) *host-eval*) - (let [ns-clauses (drop-while #(or (string? %) (map? %)) ns-clauses) ; drop doc and meta for now + (let [[ns-meta ns-clauses] (split-with #(or (string? %) (map? %)) ns-clauses) + ns-meta (into {} (map #(if (string? %) [:doc %] % )) ns-meta) refer-clojures (if (= 'cljd.core ns-sym) [[:refer-clojure :only []]] (or (seq (filter #(= :refer-clojure (first %)) ns-clauses)) [[:refer-clojure]])) @@ -3262,8 +3262,9 @@ spec)))) ns-lib (ns-to-lib ns-sym) ns-map (-> ns-prototype - (assoc :lib ns-lib) - (assoc-in [:imports ns-lib] {:clj-alias (name ns-sym)})) + (assoc :meta ns-meta) + (assoc :lib ns-lib) + (assoc-in [:imports ns-lib] {:clj-alias (name ns-sym)})) ns-map (reduce #(%2 %1) ns-map (for [[lib & {:keys [as refer rename]}] require-specs @@ -4519,9 +4520,10 @@ (load-input in) (let [the-ns (@nses *current-ns*) libname (:lib the-ns) - is-test-ns (->> the-ns vals (some #(-> % :meta :dart/test))) + test-dir (some->> the-ns :meta :dart.test/dir (re-matches #"(.*?)/*") second) + is-test-ns (or (some? test-dir) (->> the-ns vals (some #(-> % :meta :dart/test)))) libname' (if is-test-ns - (str *test-path* (str/replace (subs libname (count *lib-path*)) #"\.dart$" "_test.dart")) + (str (or test-dir "test") "/" (str/replace (subs libname (count *lib-path*)) #"\.dart$" "_test.dart")) libname)] (when is-test-ns (swap! nses rename-lib libname libname'))