diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2218a71..f87c0c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,74 +7,38 @@ on: branches: [main] workflow_dispatch: # Supports manual triggering -jobs: - clojure: - strategy: - matrix: - # Uncomment to enable all of them - # os: [ubuntu-latest, macOS-latest, windows-latest] - os: [ubuntu-latest] - - runs-on: ${{ matrix.os }} +env: + # increment to "clear" the cache + CACHE_VERSION: "v1" +jobs: + test: + runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - # It is important to install java before installing clojure tools which needs java - # exclusions: babashka, clj-kondo and cljstyle - name: Prepare java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: - distribution: "zulu" - java-version: "17" + distribution: "temurin" + java-version: "21" - name: Install clojure tools - uses: DeLaGuardo/setup-clojure@12.5 + uses: DeLaGuardo/setup-clojure@13.2 with: - # Install just one or all simultaneously - # The value must indicate a particular version of the tool, or use 'latest' - # to always provision the latest version - cli: 1.10.1.693 # Clojure CLI based on tools.deps - lein: 2.11.2 # Leiningen + cli: 1.12.0.1530 + lein: 2.11.2 - # Optional step: - name: Cache clojure dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.m2/repository ~/.gitlibs ~/.deps.clj # List all files containing dependencies: - key: cljdeps-${{ hashFiles('project.clj') }} - # key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }} - # key: cljdeps-${{ hashFiles('project.clj') }} - # key: cljdeps-${{ hashFiles('build.boot') }} - restore-keys: cljdeps- - - - name: Run Tests - run: lein test - clojurescript: - strategy: - matrix: - # Uncomment to enable all of them - # os: [ubuntu-latest, macOS-latest, windows-latest] - os: [ubuntu-latest] - - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout - uses: actions/checkout@v3 - - # It is important to install java before installing clojure tools which needs java - # exclusions: babashka, clj-kondo and cljstyle - - name: Prepare java - uses: actions/setup-java@v3 - with: - distribution: "zulu" - java-version: "17" + key: cljdeps-${{ env.CACHE_VERSION }}-${{ hashFiles('project.clj') }}-${{ hashFiles('deps.edn') }}-${{ hashFiles('bb.edn') }} + restore-keys: cljdeps-${{ env.CACHE_VERSION }}- - name: Prepare node uses: actions/setup-node@v4 @@ -87,8 +51,11 @@ jobs: - name: Install Node Dependencies run: npm ci - - name: Compile Tests + - name: Compile ClojureScript Tests run: npm run build - - name: Run Tests + - name: Run ClojureScript Tests run: npm test + + - name: Run Clojure tests + run: lein test diff --git a/README.md b/README.md index 0177976..034af7e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ yet, so we're just focusing on building out the test cases for now. ## How to contribute Anyone with Clojure knowledge can help out! -Check out the latest progress and the steps for helping out here: https://github.com/jank-lang/clojure.core-test/issues/1 +Check out the latest progress and the steps for helping out here: https://github.com/jank-lang/clojure-test-suite/issues/1 ## Running the tests @@ -83,8 +83,8 @@ The following tasks are available: test-jvm Runs JVM tests test-cljs Runs CLJS tests -new-test Creates new test for the Clojure symbols named by - +new-test Creates new test for the Clojure symbols named by . Unqualified symbols assume clojure.core +nrepl Starts an nrepl server on port 1339 using an .nrepl-port file ``` Currently, there are tasks to run the Clojure JVM and Clojurescript test suites. @@ -95,6 +95,8 @@ wanted to test a function named `clojure.core/foo`, for instance, you would type: ```bash +bb new-test clojure.core/foo +;; or bb new-test foo ``` diff --git a/bb.edn b/bb.edn index ffc15d6..d2967e0 100644 --- a/bb.edn +++ b/bb.edn @@ -5,6 +5,16 @@ :task (shell "lein test")} test-cljs {:doc "Runs CLJS tests" :task (shell "npx shadow-cljs compile test")} - new-test {:doc "Creates new test for the Clojure symbols named by " + new-test {:doc "Creates new test for the Clojure symbols named by . Unqualified symbols assume clojure.core" :requires ([new-test]) - :task (new-test/new-test *command-line-args*)}}} + :task (new-test/new-test *command-line-args*)} + nrepl {:doc "Starts an nrepl server on port 1339 using an .nrepl-port file" + :requires ([babashka.fs :as fs] + [babashka.nrepl.server :as srv]) + :task (do (srv/start-server! {:host "localhost" + :port 1339}) + (spit ".nrepl-port" "1339") + (-> (Runtime/getRuntime) + (.addShutdownHook + (Thread. (fn [] (fs/delete ".nrepl-port"))))) + (deref (promise)))}}} diff --git a/bb/new_test.clj b/bb/new_test.clj index d0dbb62..32c9a18 100644 --- a/bb/new_test.clj +++ b/bb/new_test.clj @@ -6,8 +6,8 @@ [selmer.util :as util])) ;;; *, +, !, -, _, ', ?, <, > and = -(defn sym-name->ns-name - "Replace special characters in symbol name to make an ns-name." +(defn sym-name->ns-suffix + "Replace special characters in symbol name to make the final component of the ns name." [sym] (let [n (name sym) ns-sym (-> (if (str/starts-with? n "-") @@ -26,31 +26,39 @@ (subs ns-sym 1) ns-sym))) -(defn ns-name->file-name +(defn ns-suffix->file-name "Replace hyphens with underscores to create the file name." [ns-name] (str/replace ns-name "-" "_")) +(defn ns->resource [nsym] + (-> nsym namespace-munge (str/replace "." "/"))) + (defn new-test "Create a new test file for the symbol which is the first command line argument." [args] (if (zero? (count args)) (println "Please supply one or more Clojure symbols corresponding to the new tests.") - (loop [[sym-name & args] args] - (when sym-name - (let [ns-name (sym-name->ns-name sym-name) - file-name (ns-name->file-name ns-name) - dest-file-name (str "test/clojure/core_test/" file-name ".cljc")] + (loop [[sym & args] (map symbol args)] + (when sym + (let [sym-name (if (namespace sym) + (-> sym name symbol) + sym) + base-ns (or (some-> sym namespace symbol) + 'clojure.core) + ns-suffix (sym-name->ns-suffix sym-name) + file-name (namespace-munge ns-suffix) + dest-dir (format "test/%s_test" (ns->resource base-ns)) + dest-file-name (format "%s/%s.cljc" dest-dir file-name)] (if (fs/exists? dest-file-name) (println dest-file-name "already exists. No action taken.") (do (println "Creating" dest-file-name) + (fs/create-dirs dest-dir) (let [template (slurp "templates/test-template.cljc")] (spit dest-file-name (util/without-escaping - (s/render template {:sym-name sym-name - :ns-name ns-name + (s/render template {:base-ns base-ns + :sym-name sym-name + :ns-suffix ns-suffix :file-name file-name}))))))) (recur args))))) - - - diff --git a/package.json b/package.json index 25d8535..68b6bf5 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "clojure.core-test", + "name": "io.github.jank-lang/clojure-test-suite", "version": "1.0.0", "description": "Node config for compiling tests to js", - "repository": "https://github.com/jank-lang/clojure.core-test", + "repository": "https://github.com/jank-lang/clojure-test-suite", "directories": { "test": "test" }, diff --git a/project.clj b/project.clj index 4a5331d..d8e3724 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,6 @@ -(defproject clojure.core-test "0.1.0-SNAPSHOT" +(defproject io.github.jank-lang/clojure-test-suite "0.1.0-SNAPSHOT" :description "Dialect-independent tests for clojure.core, focused on locking down how Clojure JVM behaves so that other dialects to reach parity." - :url "https://github.com/jank-lang/clojure.core-test" + :url "https://github.com/jank-lang/clojure-test-suite" :license {:name "MPL 2.0" :url "https://www.mozilla.org/en-US/MPL/2.0/"} :dependencies [[org.clojure/clojure "1.12.0"]] diff --git a/templates/test-template.cljc b/templates/test-template.cljc index ff6840b..2305ce1 100644 --- a/templates/test-template.cljc +++ b/templates/test-template.cljc @@ -1,8 +1,9 @@ -(ns clojure.core-test.{{ns-name}} - (:require [clojure.test :as t :refer [deftest testing is are]] +(ns {{base-ns}}-test.{{ns-suffix}} + (:require {{base-ns}} + [clojure.test :as t :refer [deftest testing is are]] [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) -(when-var-exists clojure.core/{{sym-name}} +(when-var-exists {{base-ns}}/{{sym-name}} (deftest test-{{sym-name}} ;; `testing` sections are optional, depending on how you want to ;; structure your tests. If you have a lot of tests and they group