babashka/test-resources/lib_tests/babashka/run_all_libtests.clj
Gabriel Horner 665ae4dd97
Finish up library tests (#1120)
* Add tests for markdown-clj and tools.namespace

See comment for why only one markdown test could be run.
Closes #1069 and #1064

* Convert 10 test libs using add-libtest

Also improved add-libtest to only require maven artifact
and rely on clojars for getting git-url most of the time

* Convert 8 more test libs using add-libtest

Also updated table and added comment for newline test

* Fix doric test

* Disable tools.namespace test that fails on windows

* Added dozen manual test libs and converted 2 test libs

add-libtest.clj supports manually-added and test-directories options

* Converts last tests to test namespaces and write libraries.csv

* Add a number of library tests from projects.md

Also add more docs around adding test libs and tweak add script

* Use :sha for gitlib and older clojure cli

* Revert "Use :sha for gitlib and older clojure cli"

This reverts commit c663ab8368.

* Fix and disable failing tests

Disabled tests that fail consistently and fixed windows one
2021-12-29 16:35:14 +01:00

61 lines
1.7 KiB
Clojure

(ns babashka.run-all-libtests
(:require [clojure.java.io :as io]
[clojure.string :as str]
[clojure.edn :as edn]
[clojure.test :as t]))
(def ns-args (set (map symbol *command-line-args*)))
(def status (atom {}))
(defn test-namespace? [ns]
(or (empty? ns-args)
(contains? ns-args ns)))
(defn test-namespaces [& namespaces]
(let [namespaces (seq (filter test-namespace? namespaces))]
(when (seq namespaces)
(doseq [n namespaces]
(require n))
(let [m (apply t/run-tests namespaces)]
(swap! status (fn [status]
(merge-with + status (dissoc m :type))))))))
(def windows? (-> (System/getProperty "os.name")
(str/lower-case)
(str/includes? "win")))
;; Standard test-runner for libtests
(let [lib-tests (edn/read-string (slurp (io/resource "bb-tested-libs.edn")))]
(doseq [{tns :test-namespaces skip-windows :skip-windows} (vals lib-tests)]
(when-not (and skip-windows windows?)
(apply test-namespaces tns))))
;; Non-standard tests - These are tests with unusual setup around test-namespaces
;;;; doric
(defn test-doric-cyclic-dep-problem
[]
(require '[doric.core :as d])
((resolve 'doric.core/table) [:a :b] [{:a 1 :b 2}]))
(when (test-namespace? 'doric.test.core)
(test-doric-cyclic-dep-problem))
;;;; babashka.process
(when-not windows?
;; test built-in babashka.process
(test-namespaces 'babashka.process-test)
;; test babashka.process from source
(require '[babashka.process] :reload)
(test-namespaces 'babashka.process-test))
;;;; final exit code
(let [{:keys [:test :fail :error] :as m} @status]
(prn m)
(when-not (pos? test)
(System/exit 1))
(System/exit (+ fail error)))