Skip to content
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

REPL+CLI support #44

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
446e1d9
clojure cli/repl support
frenchy64 Jan 31, 2022
9c281ea
fix doc
frenchy64 Feb 2, 2022
1328997
fix some oversights
frenchy64 Feb 3, 2022
14f566c
move repl defaults to exec
frenchy64 Feb 3, 2022
a1b8a2f
fix up build.yml
frenchy64 Feb 3, 2022
a1f575b
share test-matcher-directories impl with lein+boot
frenchy64 Feb 4, 2022
f802b9f
port :enter-key-listener to lein/boot
frenchy64 Feb 4, 2022
60f2772
wip kv leiningen interface
frenchy64 Feb 4, 2022
2f8d9fd
fix
frenchy64 Feb 6, 2022
c0c1e2c
wip
frenchy64 Feb 6, 2022
70a3a20
start testing lein cli interface
frenchy64 Feb 6, 2022
3467e6c
I've misunderstood Leiningen test selectors
frenchy64 Feb 6, 2022
194069e
disable tests that need impl changes
frenchy64 Feb 6, 2022
d3b2f6e
wip
frenchy64 Feb 7, 2022
35c179f
fix tests
frenchy64 Feb 7, 2022
ab5ee81
wip
frenchy64 Feb 7, 2022
0d47cf5
push regex coercion into impl
frenchy64 Feb 7, 2022
c87b25b
add project.clj to cli-no-tests project
frenchy64 Feb 7, 2022
e4264e6
doc
frenchy64 Feb 7, 2022
ae0c0b1
only activate selectors when provided
frenchy64 Feb 7, 2022
efc7880
empty args should revert to old behavior
frenchy64 Feb 7, 2022
1db9363
wip -M cli interface
frenchy64 Feb 7, 2022
f49f83b
fix
frenchy64 Feb 7, 2022
9acbb23
test -M correctly
frenchy64 Feb 7, 2022
17300cf
doc
frenchy64 Feb 7, 2022
5066929
add lein style args to cli main
frenchy64 Feb 7, 2022
359ccdc
rename :test-matcher-directories => :test-dirs
frenchy64 Feb 7, 2022
9d4fdf9
allow :test-dirs to be a string
frenchy64 Feb 7, 2022
15fa5e4
push exec args file parsing later
frenchy64 Feb 7, 2022
a780b23
start testing -M sugar
frenchy64 Feb 7, 2022
7916d53
parallelize tests
frenchy64 Feb 7, 2022
77abb96
fix test parallelism
frenchy64 Feb 8, 2022
302dd80
main tests
frenchy64 Feb 8, 2022
b6b1786
split tests
frenchy64 Feb 8, 2022
8037345
remove unused test paths
frenchy64 Feb 9, 2022
9a3435c
absolutize lein paths
frenchy64 Feb 9, 2022
b0c6996
absolutize opts
frenchy64 Feb 9, 2022
28cc4bc
fix lein logic
frenchy64 Feb 9, 2022
9849a49
restage
frenchy64 Feb 9, 2022
88a8f85
refactor
frenchy64 Feb 9, 2022
734f101
todos
frenchy64 Feb 9, 2022
fc8487e
drop cli :only arg
frenchy64 Feb 9, 2022
ad33592
rm prints
frenchy64 Mar 3, 2022
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
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test

on:
push:
branches:
- master
pull_request:

jobs:
test:
strategy:
matrix:
jdk: ['8', '11', '17']
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: |
~/.m2/repository
~/.gitlibs
key: ${{ runner.os }}-maven-${{ hashFiles('deps.edn') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Prepare java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: ${{ matrix.jdk }}

- name: Install clojure tools
uses: DeLaGuardo/[email protected]
with:
cli: latest
lein: latest
boot: latest
- name: Clojure CLI tests
run: clojure -X:test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ pom.xml.asc
.hgignore
.hg/
.nrepl-history
.cpcache
test-projects/*/target
.lein-failures
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,90 @@ See `boot bat-test -h` for a list of available task options.

See `lein bat-test help` for a list of available task options.

## Clojure CLI Usage

### Main style

### Exec style

Add the following alias to your deps.edn:

```clojure
{:aliases {:test {:extra-deps {metosin/bat-test {...}}
:extra-paths ["test"]
:exec-fn metosin.bat-test.cli/exec
:exec-args {:test-dirs ["test"]}}}}
```

Invoke with exec (`-X`), and see `metosin.bat-test.cli/{test,exec,run-tests}` for options. Here are some examples:

```sh
# run all tests once
clojure -X:test

# continuously run tests
clojure -X:test :watch true

# run tests in parallel
clojure -X:test :parallel true

# just test files under particular directories (handy for monorepos)
clojure -X:test :test-dirs '["module1" "module3"]'

# use Leiningen-style test selectors (see next section for custom selectors)
clojure -X:test :selectors '[:all]' # <- lein test :all
clojure -X:test :selectors '[my-ns :only other-ns/foo]' # <- lein test my-ns :only other-ns/foo
```

### Handy default arguments

Use `:exec-args` for default values. Especially useful for Leiningen-style test selectors:

eg.,

```clojure
; selectors.clj
{:default (clojure.core/complement (clojure.core/some-fn :integration :disabled))
:integration :integration
:all (clojure.core/complement :disabled)}
```

```clojure
; deps.edn
{:aliases {:test {:extra-deps {metosin/bat-test {...}}
:extra-paths ["test"]
:exec-fn metosin.bat-test.cli/exec
:exec-args {:test-dirs ["test"]
;; add this line
:test-selectors-form-file "selectors.clj"}}}}
```

You can share this file with Leiningen like so:

```clojure
; project.clj
(defproject ...
:test-selectors ~(-> "selectors.clj" slurp read-string))
```

## REPL Usage

Almost identical to Clojure CLI usage (above), except use `metosin.bat-test.cli/test`.

The major difference is that `test` throws exceptions, whereas `metosin.bat-test.cli/exec` uses `System/exit` (you don't
want this at the REPL).

You may want to create your own wrapper to provide some default arguments:

```clojure
(ns my-repl-ns
(:refer-clojure :exclude [test])
(:require [metosin.bat-test.cli :as bat-test]))

(defn test [args]
(bat-test/test (into {:test-selectors-form-file "selectors.clj"} args)))
```

## License

Copyright © 2016-2019 [Metosin Oy](http://www.metosin.fi)
Expand Down
2 changes: 1 addition & 1 deletion build.boot
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(def +version+ "0.4.4")
(def +version+ (slurp "version"))

(set-env!
:resource-paths #{"src"}
Expand Down
56 changes: 56 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(ns build
(:refer-clojure :exclude [compile])
(:require [clojure.tools.build.api :as b]
[clojure.java.io :as io]
[clojure.string :as str]))

(def lib 'metosin/bat-test)
(def +version+ (format "%s.%s" (slurp "version") (b/git-count-revs nil)))
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "target/%s-%s.jar" (name lib) +version+))

(defn write-version-file [d nsym]
(let [f (io/file d (-> (name nsym)
(str/replace #"\." "/")
(str/replace #"-" "_")
(str ".clj")))]
(io/make-parents f)
(spit f (format "(ns %s)\n\n(def +version+ \"%s\")" (name nsym) +version+))))

;; operations

(defn clean [_]
(b/delete {:path "target"}))

(defn compile [_]
(write-version-file class-dir 'metosin.bat-test.version))

(defn jar [_]
(b/write-pom {:class-dir class-dir
:lib lib
:version +version+
:basis basis
:src-dirs ["src"]})
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(compile {})
(b/jar {:class-dir class-dir
:jar-file jar-file}))

;; clojure -T:build version
(defn version [_] (print +version+))

;; clojure -T:build install
(defn install
"Prints the version that was installed."
[_]
(clean {})
(jar {})
(b/install {:basis basis
:lib lib
:version +version+
:class-dir class-dir
:jar-file jar-file})
;; test-projects expect version to be printed
(version {}))
25 changes: 25 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{:paths ["src"]
:deps {eftest/eftest {:mvn/version "0.5.9"}
org.clojure/tools.namespace {:mvn/version "1.2.0"}
cloverage/cloverage {:mvn/version "1.1.1"}
hawk/hawk {:mvn/version "0.2.11"}}
;; Note: prep is commented out because it only generates metosin.bat-test.version,
;; which is only used in leiningen.bat-test--ie., only ever from a jar. This will
;; thus never be used via a deps.edn source dependency. If enabling this prep step,
;; add "target/classes" to the top-level :paths entry.
;; clj -X:deps prep
;; https://clojure.org/guides/deps_and_cli#prep_libs
;:deps/prep-lib {:alias :build
; :fn compile
; :ensure "target/classes"}
:aliases {;; clojure -X:test
:test {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner
{:git/tag "v0.5.0" :git/sha "b3fd0d2"}}
:exec-fn cognitect.test-runner.api/test}
;; clj -T:build clean
;; clj -T:build jar
;; clj -T:build install
;; clj -T:build version
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.7.5" :git/sha "34727f7"}}
:ns-default build}}}
Loading