Skip to content

Commit

Permalink
support for :dart.test/dir ns meta to allow emitting tests to differe…
Browse files Browse the repository at this point in the history
…nt dirs
  • Loading branch information
cgrand committed Oct 10, 2024
1 parent dd02ebf commit 4d15a05
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions clj/src/cljd/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]]))
Expand All @@ -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
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit 4d15a05

Please sign in to comment.