Skip to content

Commit b617559

Browse files
authored
Add build cache, update readme, enhance template (#80)
* add build cache, update readme, enhance template * improve * test cache * mv * create parent directories * build
1 parent 9832b4d commit b617559

File tree

7 files changed

+67
-79
lines changed

7 files changed

+67
-79
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,38 @@ on:
77
branches: [main]
88
workflow_dispatch: # Supports manual triggering
99

10-
jobs:
11-
clojure:
12-
strategy:
13-
matrix:
14-
# Uncomment to enable all of them
15-
# os: [ubuntu-latest, macOS-latest, windows-latest]
16-
os: [ubuntu-latest]
17-
18-
runs-on: ${{ matrix.os }}
10+
env:
11+
# increment to "clear" the cache
12+
CACHE_VERSION: "v1"
1913

14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
2017
steps:
21-
- name: Checkout
22-
uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
2319

24-
# It is important to install java before installing clojure tools which needs java
25-
# exclusions: babashka, clj-kondo and cljstyle
2620
- name: Prepare java
27-
uses: actions/setup-java@v3
21+
uses: actions/setup-java@v4
2822
with:
29-
distribution: "zulu"
30-
java-version: "17"
23+
distribution: "temurin"
24+
java-version: "21"
3125

3226
- name: Install clojure tools
33-
uses: DeLaGuardo/setup-clojure@12.5
27+
uses: DeLaGuardo/setup-clojure@13.2
3428
with:
35-
# Install just one or all simultaneously
36-
# The value must indicate a particular version of the tool, or use 'latest'
37-
# to always provision the latest version
38-
cli: 1.10.1.693 # Clojure CLI based on tools.deps
39-
lein: 2.11.2 # Leiningen
29+
cli: 1.12.0.1530
30+
lein: 2.11.2
4031

41-
# Optional step:
4232
- name: Cache clojure dependencies
43-
uses: actions/cache@v3
33+
uses: actions/cache@v4
4434
with:
4535
path: |
4636
~/.m2/repository
4737
~/.gitlibs
4838
~/.deps.clj
4939
# List all files containing dependencies:
50-
key: cljdeps-${{ hashFiles('project.clj') }}
51-
# key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
52-
# key: cljdeps-${{ hashFiles('project.clj') }}
53-
# key: cljdeps-${{ hashFiles('build.boot') }}
54-
restore-keys: cljdeps-
55-
56-
- name: Run Tests
57-
run: lein test
58-
clojurescript:
59-
strategy:
60-
matrix:
61-
# Uncomment to enable all of them
62-
# os: [ubuntu-latest, macOS-latest, windows-latest]
63-
os: [ubuntu-latest]
64-
65-
runs-on: ${{ matrix.os }}
66-
67-
steps:
68-
- name: Checkout
69-
uses: actions/checkout@v3
70-
71-
# It is important to install java before installing clojure tools which needs java
72-
# exclusions: babashka, clj-kondo and cljstyle
73-
- name: Prepare java
74-
uses: actions/setup-java@v3
75-
with:
76-
distribution: "zulu"
77-
java-version: "17"
40+
key: cljdeps-${{ env.CACHE_VERSION }}-${{ hashFiles('project.clj') }}-${{ hashFiles('deps.edn') }}-${{ hashFiles('bb.edn') }}
41+
restore-keys: cljdeps-${{ env.CACHE_VERSION }}-
7842

7943
- name: Prepare node
8044
uses: actions/setup-node@v4
@@ -87,8 +51,11 @@ jobs:
8751
- name: Install Node Dependencies
8852
run: npm ci
8953

90-
- name: Compile Tests
54+
- name: Compile ClojureScript Tests
9155
run: npm run build
9256

93-
- name: Run Tests
57+
- name: Run ClojureScript Tests
9458
run: npm test
59+
60+
- name: Run Clojure tests
61+
run: lein test

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ yet, so we're just focusing on building out the test cases for now.
1111
## How to contribute
1212
Anyone with Clojure knowledge can help out!
1313

14-
Check out the latest progress and the steps for helping out here: https://github.com/jank-lang/clojure.core-test/issues/1
14+
Check out the latest progress and the steps for helping out here: https://github.com/jank-lang/clojure-test-suite/issues/1
1515

1616
## Running the tests
1717

@@ -83,8 +83,8 @@ The following tasks are available:
8383

8484
test-jvm Runs JVM tests
8585
test-cljs Runs CLJS tests
86-
new-test Creates new test for the Clojure symbols named by <args>
87-
86+
new-test Creates new test for the Clojure symbols named by <args>. Unqualified symbols assume clojure.core
87+
nrepl Starts an nrepl server on port 1339 using an .nrepl-port file
8888
```
8989

9090
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
9595
would type:
9696

9797
```bash
98+
bb new-test clojure.core/foo
99+
;; or
98100
bb new-test foo
99101
```
100102

bb.edn

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
:task (shell "lein test")}
66
test-cljs {:doc "Runs CLJS tests"
77
:task (shell "npx shadow-cljs compile test")}
8-
new-test {:doc "Creates new test for the Clojure symbols named by <args>"
8+
new-test {:doc "Creates new test for the Clojure symbols named by <args>. Unqualified symbols assume clojure.core"
99
:requires ([new-test])
10-
:task (new-test/new-test *command-line-args*)}}}
10+
:task (new-test/new-test *command-line-args*)}
11+
nrepl {:doc "Starts an nrepl server on port 1339 using an .nrepl-port file"
12+
:requires ([babashka.fs :as fs]
13+
[babashka.nrepl.server :as srv])
14+
:task (do (srv/start-server! {:host "localhost"
15+
:port 1339})
16+
(spit ".nrepl-port" "1339")
17+
(-> (Runtime/getRuntime)
18+
(.addShutdownHook
19+
(Thread. (fn [] (fs/delete ".nrepl-port")))))
20+
(deref (promise)))}}}

bb/new_test.clj

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
[selmer.util :as util]))
77

88
;;; *, +, !, -, _, ', ?, <, > and =
9-
(defn sym-name->ns-name
10-
"Replace special characters in symbol name to make an ns-name."
9+
(defn sym-name->ns-suffix
10+
"Replace special characters in symbol name to make the final component of the ns name."
1111
[sym]
1212
(let [n (name sym)
1313
ns-sym (-> (if (str/starts-with? n "-")
@@ -26,31 +26,39 @@
2626
(subs ns-sym 1)
2727
ns-sym)))
2828

29-
(defn ns-name->file-name
29+
(defn ns-suffix->file-name
3030
"Replace hyphens with underscores to create the file name."
3131
[ns-name]
3232
(str/replace ns-name "-" "_"))
3333

34+
(defn ns->resource [nsym]
35+
(-> nsym namespace-munge (str/replace "." "/")))
36+
3437
(defn new-test
3538
"Create a new test file for the symbol which is the first command line argument."
3639
[args]
3740
(if (zero? (count args))
3841
(println "Please supply one or more Clojure symbols corresponding to the new tests.")
39-
(loop [[sym-name & args] args]
40-
(when sym-name
41-
(let [ns-name (sym-name->ns-name sym-name)
42-
file-name (ns-name->file-name ns-name)
43-
dest-file-name (str "test/clojure/core_test/" file-name ".cljc")]
42+
(loop [[sym & args] (map symbol args)]
43+
(when sym
44+
(let [sym-name (if (namespace sym)
45+
(-> sym name symbol)
46+
sym)
47+
base-ns (or (some-> sym namespace symbol)
48+
'clojure.core)
49+
ns-suffix (sym-name->ns-suffix sym-name)
50+
file-name (namespace-munge ns-suffix)
51+
dest-dir (format "test/%s_test" (ns->resource base-ns))
52+
dest-file-name (format "%s/%s.cljc" dest-dir file-name)]
4453
(if (fs/exists? dest-file-name)
4554
(println dest-file-name "already exists. No action taken.")
4655
(do (println "Creating" dest-file-name)
56+
(fs/create-dirs dest-dir)
4757
(let [template (slurp "templates/test-template.cljc")]
4858
(spit dest-file-name
4959
(util/without-escaping
50-
(s/render template {:sym-name sym-name
51-
:ns-name ns-name
60+
(s/render template {:base-ns base-ns
61+
:sym-name sym-name
62+
:ns-suffix ns-suffix
5263
:file-name file-name})))))))
5364
(recur args)))))
54-
55-
56-

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "clojure.core-test",
2+
"name": "io.github.jank-lang/clojure-test-suite",
33
"version": "1.0.0",
44
"description": "Node config for compiling tests to js",
5-
"repository": "https://github.com/jank-lang/clojure.core-test",
5+
"repository": "https://github.com/jank-lang/clojure-test-suite",
66
"directories": {
77
"test": "test"
88
},

project.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
(defproject clojure.core-test "0.1.0-SNAPSHOT"
1+
(defproject io.github.jank-lang/clojure-test-suite "0.1.0-SNAPSHOT"
22
:description "Dialect-independent tests for clojure.core, focused on locking down how Clojure JVM behaves so that other dialects to reach parity."
3-
:url "https://github.com/jank-lang/clojure.core-test"
3+
:url "https://github.com/jank-lang/clojure-test-suite"
44
:license {:name "MPL 2.0"
55
:url "https://www.mozilla.org/en-US/MPL/2.0/"}
66
:dependencies [[org.clojure/clojure "1.12.0"]]

templates/test-template.cljc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
(ns clojure.core-test.{{ns-name}}
2-
(:require [clojure.test :as t :refer [deftest testing is are]]
1+
(ns {{base-ns}}-test.{{ns-suffix}}
2+
(:require {{base-ns}}
3+
[clojure.test :as t :refer [deftest testing is are]]
34
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
45

5-
(when-var-exists clojure.core/{{sym-name}}
6+
(when-var-exists {{base-ns}}/{{sym-name}}
67
(deftest test-{{sym-name}}
78
;; `testing` sections are optional, depending on how you want to
89
;; structure your tests. If you have a lot of tests and they group

0 commit comments

Comments
 (0)