Skip to content

Add build cache, update readme, enhance template #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 21 additions & 54 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 <args>

new-test Creates new test for the Clojure symbols named by <args>. 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.
Expand All @@ -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
```

Expand Down
14 changes: 12 additions & 2 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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 <args>"
new-test {:doc "Creates new test for the Clojure symbols named by <args>. 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)))}}}
34 changes: 21 additions & 13 deletions bb/new_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 "-")
Expand All @@ -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)))))



4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -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"]]
Expand Down
7 changes: 4 additions & 3 deletions templates/test-template.cljc
Original file line number Diff line number Diff line change
@@ -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
Expand Down