|
| 1 | +(ns clj-kondo.hook-test |
| 2 | + (:require [clojure.test :refer [deftest testing is]] |
| 3 | + [clojure.java.shell :refer [sh]] |
| 4 | + [clojure.string :as str])) |
| 5 | + |
| 6 | +(def ^:private config-dir |
| 7 | + "resources/clj-kondo.exports/clj-python/libpython-clj") |
| 8 | + |
| 9 | +(def ^:private fixtures-dir |
| 10 | + "test/clj_kondo/fixtures") |
| 11 | + |
| 12 | +(defn- run-clj-kondo [file] |
| 13 | + (sh "clj-kondo" "--lint" file "--config-dir" config-dir)) |
| 14 | + |
| 15 | +(defn- has-require-python-errors? [output] |
| 16 | + (boolean (re-find #"(Unknown require option|:bind-ns|:reload|:no-arglists)" output))) |
| 17 | + |
| 18 | +(defn- has-unresolved-refer-errors? [output] |
| 19 | + (boolean (re-find #"Unresolved symbol: (webpush|secure_filename|urlencode|urlparse)" output))) |
| 20 | + |
| 21 | +(deftest require-python-hook-test |
| 22 | + (testing "require_python_test.clj - basic require-python usage" |
| 23 | + (let [{:keys [out err]} (run-clj-kondo (str fixtures-dir "/require_python_test.clj")) |
| 24 | + output (str out err)] |
| 25 | + (is (not (has-require-python-errors? output)) |
| 26 | + (str "Found require-python errors in output:\n" output)) |
| 27 | + (is (not (has-unresolved-refer-errors? output)) |
| 28 | + (str "Found unresolved symbol errors for referred symbols:\n" output))))) |
| 29 | + |
| 30 | +(deftest require-python-edge-cases-test |
| 31 | + (testing "require_python_edge_cases.clj - edge cases and variations" |
| 32 | + (let [{:keys [out err]} (run-clj-kondo (str fixtures-dir "/require_python_edge_cases.clj")) |
| 33 | + output (str out err)] |
| 34 | + (is (not (has-require-python-errors? output)) |
| 35 | + (str "Found require-python errors in output:\n" output)) |
| 36 | + (is (not (has-unresolved-refer-errors? output)) |
| 37 | + (str "Found unresolved symbol errors for referred symbols:\n" output))))) |
0 commit comments