From bb57d220d02fa71db26365b1de1dbb44b7fd73e3 Mon Sep 17 00:00:00 2001 From: Bob Date: Sun, 8 Aug 2021 15:23:58 -0400 Subject: [PATCH] test that var metadata matches containing ns (#967) * - change namespace on 'quick-check' to match clojure version - add test for var meta->namespace alignment * - add ns to with-transaction macro --- feature-jdbc/babashka/impl/jdbc.clj | 5 ++-- .../babashka/impl/clojure/test/check.clj | 2 +- test/babashka/namespace_test.clj | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/babashka/namespace_test.clj diff --git a/feature-jdbc/babashka/impl/jdbc.clj b/feature-jdbc/babashka/impl/jdbc.clj index 6891d3b3..2d754622 100644 --- a/feature-jdbc/babashka/impl/jdbc.clj +++ b/feature-jdbc/babashka/impl/jdbc.clj @@ -2,7 +2,7 @@ {:no-doc true} (:require [next.jdbc :as njdbc] [next.jdbc.sql :as sql] - [sci.impl.namespaces :refer [copy-var]] + [sci.impl.namespaces :refer [copy-var macrofy]] [sci.impl.vars :as vars])) (def next-ns (vars/->SciNamespace 'next.jdbc nil)) @@ -28,8 +28,7 @@ 'plan (copy-var njdbc/plan next-ns) 'prepare (copy-var njdbc/prepare next-ns) 'transact (copy-var njdbc/transact next-ns) - 'with-transaction (with-meta with-transaction - {:sci/macro true})}) + 'with-transaction (macrofy 'with-transaction with-transaction next-ns)}) (def sns (vars/->SciNamespace 'next.jdbc.sql nil)) diff --git a/feature-test-check/babashka/impl/clojure/test/check.clj b/feature-test-check/babashka/impl/clojure/test/check.clj index 6febea0c..4f293028 100644 --- a/feature-test-check/babashka/impl/clojure/test/check.clj +++ b/feature-test-check/babashka/impl/clojure/test/check.clj @@ -174,4 +174,4 @@ (println (str "'" k) (format "(sci/copy-var tc/%s p-ns)" k))) (def test-check-namespace - {'quick-check (sci/copy-var tc/quick-check p-ns)}) + {'quick-check (sci/copy-var tc/quick-check tc-ns)}) diff --git a/test/babashka/namespace_test.clj b/test/babashka/namespace_test.clj new file mode 100644 index 00000000..5408f9a2 --- /dev/null +++ b/test/babashka/namespace_test.clj @@ -0,0 +1,25 @@ +(ns babashka.namespace-test + (:require [babashka.test-utils :as tu] + [clojure.edn :as edn] + [clojure.test :refer :all])) + +(defn bb [input & args] + (edn/read-string + {:readers *data-readers* + :eof nil} + (apply tu/bb (when (some? input) (str input)) (map str args)))) + +(deftest publics-namespace-test + (testing "all namespace publics (except for those in clojure.lang and user namespaces) + have ns metadata that matches the namespace it's in" + (comment "results seq contains vars whose ns meta doesn't match the ns they're in") + (is (empty? (bb nil " +(let [excluded-namespaces #{'clojure.lang 'user}] + (for [nspace (remove #(excluded-namespaces (ns-name %)) (all-ns)) + [var-symbol ns-var] (ns-publics nspace) + :let [ns-ns-name (ns-name nspace) + var-ns-name (some-> ns-var meta :ns ns-name)] + :when (not= ns-ns-name var-ns-name)] + {:containing-ns ns-ns-name + :ns-on-var var-ns-name + :var-name var-symbol}))")))))