Added dozen manual test libs and converted 2 test libs

add-libtest.clj supports manually-added and test-directories options
This commit is contained in:
Gabriel Horner 2021-12-27 15:54:01 -05:00
parent a608403f36
commit 0294923fbc
5 changed files with 95 additions and 100 deletions

View file

@ -57,45 +57,62 @@
[:aliases :lib-tests :extra-deps lib-name]
lib-coordinate)))))
(defn- default-test-dir
[lib-root-dir]
(some #(when (fs/exists? (fs/file lib-root-dir %))
(str (fs/file lib-root-dir %)))
;; Most common test dir
["test"
;; official clojure repos like https://github.com/clojure/tools.gitlibs
"src/test/clojure"]))
(defn- copy-tests
[git-url lib-name {:keys [directory branch]}]
[git-url lib-name {:keys [directory branch test-directories]}]
(let [lib-dir (if branch
(gl/procure git-url lib-name branch)
(or (gl/procure git-url lib-name "master")
(gl/procure git-url lib-name "main")))
lib-root-dir (if directory
(fs/file lib-dir directory) lib-dir)
test-dir (some #(when (fs/exists? (fs/file lib-root-dir %))
(str (fs/file lib-root-dir %)))
;; Search common test dirs
["test"
;; official clojure repos like https://github.com/clojure/tools.gitlibs
"src/test/clojure"])]
(when-not test-dir
(error "No test dir found"))
(shell "cp -R" (str test-dir fs/file-separator) "test-resources/lib_tests/")
lib-root-dir (if directory (fs/file lib-dir directory) lib-dir)
test-dirs (if test-directories
(map #(when (fs/exists? (fs/file lib-root-dir %))
(str (fs/file lib-root-dir %)))
test-directories)
(some-> (default-test-dir lib-root-dir) vector))]
(when (empty? test-dirs)
(error "No test directories found"))
(doseq [test-dir test-dirs]
(shell "cp -R" (str test-dir fs/file-separator) "test-resources/lib_tests/"))
{:lib-dir lib-dir
:test-dir test-dir}))
:test-dirs test-dirs}))
(defn- default-test-namespaces
[test-dir]
(let [relative-test-files (map #(str (fs/relativize test-dir %))
(fs/glob test-dir "**/*.{clj,cljc}"))]
(when (empty? relative-test-files)
(error (str "No test files found in " test-dir)))
(map #(-> %
(str/replace fs/file-separator ".")
(str/replace "_" "-")
(str/replace-first #"\.clj(c?)$" "")
symbol)
relative-test-files)))
(defn- add-lib-to-tested-libs
[lib-name git-url {:keys [lib-dir test-dir]} options]
(let [git-sha (fs/file-name lib-dir)
relative-test-files (map #(str (fs/relativize test-dir %))
(fs/glob test-dir "**/*.{clj,cljc}"))
_ (when (empty? relative-test-files)
(error "No test files found"))
namespaces (map #(-> %
(str/replace fs/file-separator ".")
(str/replace "_" "-")
(str/replace-first #"\.clj(c?)$" "")
symbol)
relative-test-files)
lib (merge
{:git-sha git-sha
:git-url git-url
:test-namespaces namespaces}
;; Options needed to update libs
(select-keys options [:branch :directory]))
[lib-name git-url {:keys [lib-dir test-dirs]} options]
(let [namespaces (or (get-in options [:manually-added :test-namespaces])
(mapcat default-test-namespaces test-dirs))
default-lib (merge
{:git-url git-url
:test-namespaces namespaces}
;; Options needed to update libs
(select-keys options [:branch :directory :test-directories]))
lib (if (:manually-added options)
(-> default-lib
(merge (:manually-added options))
(assoc :manually-added true))
(assoc default-lib
:git-sha (fs/file-name lib-dir)))
nodes (-> "test-resources/lib_tests/bb-tested-libs.edn" slurp r/parse-string)]
(spit "test-resources/lib_tests/bb-tested-libs.edn"
(str (r/assoc-in nodes
@ -143,8 +160,8 @@
(get-lib-map artifact-or-deps-string options)
_ (when (nil? git-url)
(error "git-url is required. Please specify with --git-url"))
_ (add-lib-to-deps lib-name lib-coordinate)
dirs (copy-tests git-url lib-name options)
_ (when-not (:manually-added options) (add-lib-to-deps lib-name lib-coordinate))
dirs (when-not (:manually-added options) (copy-tests git-url lib-name options))
namespaces (add-lib-to-tested-libs lib-name git-url dirs options)]
(println "Added lib" lib-name "which tests the following namespaces:" namespaces)
(when (:test options)
@ -163,7 +180,12 @@
["-d" "--directory DIRECTORY" "Directory where library is located"]
;; https://github.com/reifyhealth/specmonstah used this option
["-b" "--branch BRANCH" "Default branch for git url"]
["-g" "--git-url GITURL" "Git url for artifact. Defaults to homepage on clojars"]])
["-g" "--git-url GITURL" "Git url for artifact. Defaults to homepage on clojars"]
["-m" "--manually-added LIB-MAP" "Only add library to edn file with LIB-MAP merged into library entry"
:parse-fn edn/read-string :validate-fn map?]
;; https://github.com/jeaye/orchestra used this option
["-T" "--test-directories TEST-DIRECTORY" "Directories where library tests are located"
:multi true :update-fn conj]])
(when (= *file* (System/getProperty "babashka.file"))
(run-command add-libtest *command-line-args* cli-options))

View file

@ -4,8 +4,6 @@
[clojure.edn :as edn]
[clojure.test :as t]))
#_(require 'clojure.spec.alpha)
(def ns-args (set (map symbol *command-line-args*)))
(def status (atom {}))
@ -27,14 +25,6 @@
(str/lower-case)
(str/includes? "win")))
;;;; clj-http-lite
(test-namespaces 'clj-http.lite.client-test)
;;;; babashka.curl
; skip tests on Windows because of the :compressed thing
(when-not windows? (test-namespaces 'babashka.curl-test))
;;;; cprop
;; TODO: port to test-namespaces
@ -86,10 +76,6 @@
(when (test-namespace? 'doric.test.core)
(test-doric-cyclic-dep-problem))
;;;; httpkit client
(test-namespaces 'httpkit.client-test)
;;;; babashka.process
(when-not windows?
;; test built-in babashka.process
@ -99,55 +85,10 @@
(require '[babashka.process] :reload)
(test-namespaces 'babashka.process-test))
(test-namespaces 'core-match.core-tests)
(test-namespaces 'hiccup.core-test)
(test-namespaces 'hiccup2.core-test)
(test-namespaces 'test-check.smoke-test)
(test-namespaces 'rewrite-clj.parser-test
'rewrite-clj.node-test
'rewrite-clj.zip-test
'rewrite-clj.paredit-test
'rewrite-clj.zip.subedit-test
'rewrite-clj.node.coercer-test)
(test-namespaces 'helins.binf.test)
(test-namespaces 'selmer.core-test)
(test-namespaces 'selmer.our-test)
(test-namespaces 'omniconf.core-test)
(test-namespaces 'crispin.core-test)
(test-namespaces 'multigrep.core-test)
(test-namespaces
;; TODO: env tests don't work because envoy lib isn't compatible with bb
#_'vault.env-test
'vault.lease-test
'vault.client.http-test
;; TODO:
;; failing tests in the following namespaces:
#_'vault.client.mock-test
#_'vault.secrets.kvv1-test
#_'vault.secrets.kvv2-test)
;; we don't really run any tests for java-http-clj yet, but we require the
;; namespaces to see if they at least load correctly
(test-namespaces 'java-http-clj.smoke-test)
(test-namespaces 'clj-commons.digest-test)
(test-namespaces 'hato.client-test)
(test-namespaces 'orchestra.core-test 'orchestra.expound-test 'orchestra.many-fns 'orchestra.reload-test)
(let [lib-tests (edn/read-string (slurp (io/resource "bb-tested-libs.edn")))]
(doseq [{tns :test-namespaces} (vals lib-tests)]
(apply test-namespaces tns)))
(doseq [{tns :test-namespaces skip-windows :skip-windows} (vals lib-tests)]
(when-not (and skip-windows windows?)
(apply test-namespaces tns))))
;;;; final exit code

View file

@ -46,4 +46,25 @@
org.clojure/math.combinatorics {:git-sha "e555a45b5802cf5e8c43b4377628ef34a634554b", :git-url "https://github.com/clojure/math.combinatorics", :test-namespaces (clojure.math.test-combinatorics)}
doric/doric {:git-sha "8747fdce565187a5c368c575cf4ca794084b0a5c", :git-url "https://github.com/joegallo/doric", :test-namespaces (doric.test.core doric.test.readme doric.test.doctest)}
com.github.seancorfield/honeysql {:git-sha "6e4e1f6928450788353c181f32474d930d6afe84", :git-url "https://github.com/seancorfield/honeysql", :test-namespaces (honey.sql-test honey.sql.helpers-test honey.sql.postgres-test), :branch "develop"}
honeysql/honeysql {:git-sha "1137dd12350afdc30ad4976c3718279581390b36", :git-url "https://github.com/seancorfield/honeysql", :test-namespaces (honeysql.format-test honeysql.core-test), :branch "v1"}}
honeysql/honeysql {:git-sha "1137dd12350afdc30ad4976c3718279581390b36", :git-url "https://github.com/seancorfield/honeysql", :test-namespaces (honeysql.format-test honeysql.core-test), :branch "v1"}
; skip tests on Windows because of the :compressed thing
babashka/babashka.curl {:git-url "https://github.com/babashka/babashka.curl", :test-namespaces [babashka.curl-test], :skip-windows true, :manually-added true}
http-kit/http-kit {:git-url "https://github.com/http-kit/http-kit", :test-namespaces [httpkit.client-test], :manually-added true}
org.clojure/core.match {:git-url "https://github.com/clojure/core.match", :test-namespaces [core-match.core-tests], :manually-added true}
hiccup/hiccup {:git-url "http://github.com/weavejester/hiccup", :test-namespaces [hiccup.core-test hiccup2.core-test], :manually-added true}
org.clojure/test.check {:git-url "https://github.com/clojure/test.check", :test-namespaces [test-check.smoke-test], :manually-added true}
io.helins/binf {:git-url "https://github.com/helins/binf.cljc", :test-namespaces [helins.binf.test], :manually-added true}
selmer/selmer {:git-url "https://github.com/yogthos/Selmer", :test-namespaces [selmer.core-test selmer.our-test], :manually-added true}
com.grammarly/omniconf {:git-url "https://github.com/grammarly/omniconf", :test-namespaces [omniconf.core-test], :manually-added true}
crispin/crispin {:git-url "https://github.com/dunaj-project/crispin", :test-namespaces [crispin.core-test], :manually-added true}
clj-commons/multigrep {:git-url "https://github.com/clj-commons/multigrep", :test-namespaces [multigrep.core-test], :manually-added true}
org.clj-commons/digest {:git-url "https://github.com/clj-commons/clj-digest", :test-namespaces [clj-commons.digest-test], :manually-added true}
hato/hato {:git-url "https://github.com/gnarroway/hato", :test-namespaces [hato.client-test], :manually-added true}
java-http-clj/java-http-clj {:git-url "http://www.github.com/schmee/java-http-clj", :test-namespaces [java-http-clj.smoke-test], :manually-added true}
rewrite-clj/rewrite-clj {:git-url "https://github.com/clj-commons/rewrite-clj", :test-namespaces [rewrite-clj.parser-test rewrite-clj.node-test rewrite-clj.zip-test rewrite-clj.paredit-test rewrite-clj.zip.subedit-test rewrite-clj.node.coercer-test], :manually-added true}
;; TODO: env tests don't work because envoy lib isn't compatible with bb
;; TODO: failing tests in the following namespaces: vault.client.mock-test, vault.secrets.kvv1-test vault.secrets.kvv2-test
amperity/vault-clj {:git-url "https://github.com/amperity/vault-clj", :test-namespaces [vault.lease-test vault.client.http-test], :manually-added true}
orchestra/orchestra {:git-url "https://github.com/jeaye/orchestra", :test-namespaces (orchestra.make-fns orchestra.many-fns orchestra.expound-test orchestra.core-test orchestra.reload-test), :test-directories ("test/cljc" "test/clj"), :git-sha "81e5181f7b42e5e2763a2b37db17954f3be0314e"}
;; BB-TEST-PATCH: Manually removed tasks.clj
org.clj-commons/clj-http-lite {:git-url "https://github.com/clj-commons/clj-http-lite", :test-namespaces (clj-http.lite.test-runner clj-http.lite.client-test), :test-directories ("bb"), :git-sha "6b53000df55ac05c4ff8e5047a5323fc08a52e8b"}}

View file

@ -24,11 +24,12 @@
:accept :json
:throw-exceptions false})))))
(deftest insecure-test
(is (= 200 (:status (client/get "https://self-signed.badssl.com/" {:insecure? true})))))
(deftest exception-test
(try (client/get "https://site.com/broken")
(is false "should not reach here")
(catch Exception e
(is (:headers (ex-data e))))))
;; BB-TEST-PATCH: Added test
(deftest insecure-test
(is (= 200 (:status (client/get "https://self-signed.badssl.com/" {:insecure? true})))))

View file

@ -0,0 +1,10 @@
(ns clj-http.lite.test-runner
(:require [clj-http.lite.client-test]
[clojure.test :as t]))
(defn -main [& _]
(let [{:keys [fail error]} (t/run-tests 'clj-http.lite.client-test)]
(System/exit (if (or (pos? fail)
(pos? error))
1 0))))