Skip to content

Commit 4716901

Browse files
vemvbbatsov
authored andcommitted
Exercise enrich-classpath and all Orchard Parser variants in CI
1 parent ea14baf commit 4716901

File tree

7 files changed

+120
-21
lines changed

7 files changed

+120
-21
lines changed

.circleci/config.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ jobs:
148148
clojure_version:
149149
description: Version of Clojure to test against
150150
type: string
151+
parser_target:
152+
description: The Orchard Java parser to be exercised
153+
type: string
151154
executor: << parameters.jdk_version >>
152155
environment:
153156
VERSION: << parameters.clojure_version >>
@@ -159,10 +162,10 @@ jobs:
159162
steps:
160163
- run:
161164
name: Running tests # Redundant relative to `make test`, however it makes the CI jobs fail faster, given how much time mranderson takes.
162-
command: make quick-test
165+
command: PARSER_TARGET=<< parameters.parser_target >> make --debug quick-test
163166
- run:
164167
name: Running tests with inlined deps
165-
command: make test smoketest
168+
command: PARSER_TARGET=<< parameters.parser_target >> make --debug test smoketest
166169
- run:
167170
name: Install the Clojure CLI
168171
command: |
@@ -199,6 +202,7 @@ workflows:
199202
parameters:
200203
clojure_version: ["1.8", "1.9", "1.10", "1.11", "master"]
201204
jdk_version: [openjdk8, openjdk11, openjdk16, openjdk17]
205+
parser_target: ["parser-next", "parser", "legacy-parser"]
202206
filters:
203207
branches:
204208
only: /.*/

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ out
2020
.source-deps
2121
.clj-kondo/.cache
2222
/.no-mranderson
23+
/test-runner
24+
/.test-classpath

Makefile

+50-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test quick-test fast-test eastwood cljfmt install fast-install smoketest deploy clean detect_timeout lein-repl repl lint light-kondo docs
1+
.PHONY: test quick-test fast-test eastwood cljfmt install fast-install smoketest deploy clean detect_timeout lein-repl repl lint light-kondo docs test_impl
22
.DEFAULT_GOAL := quick-test
33

44
CLOJURE_VERSION ?= 1.11
@@ -9,9 +9,26 @@ CLOJURE_VERSION ?= 1.11
99
# Don't use spaces here.
1010
LEIN_PROFILES ?= "+dev,+test"
1111

12+
TEST_PROFILES ?= "-user,-dev,+test"
13+
1214
# The enrich-classpath version to be injected.
1315
# Feel free to upgrade this.
14-
ENRICH_CLASSPATH_VERSION="1.17.1"
16+
ENRICH_CLASSPATH_VERSION="1.18.0"
17+
18+
# Set bash instead of sh for the @if [[ conditions,
19+
# and use the usual safety flags:
20+
SHELL = /bin/bash -Eeu
21+
22+
ifeq ($(OS),Darwin) # macOS
23+
SED_INPLACE = -i ''
24+
else
25+
SED_INPLACE = -i
26+
endif
27+
28+
TEST_RUNNER_SOURCE_DIR = test-runner
29+
30+
$(TEST_RUNNER_SOURCE_DIR):
31+
@if [ ! -d "$(TEST_RUNNER_SOURCE_DIR)" ]; then git clone https://github.com/cognitect-labs/test-runner.git $(TEST_RUNNER_SOURCE_DIR) --depth=1; fi
1532

1633
test/resources/cider/nrepl/clojuredocs/export.edn:
1734
curl -o $@ https://github.com/clojure-emacs/clojuredocs-export-edn/raw/master/exports/export.compact.edn
@@ -24,12 +41,35 @@ dump-version:
2441
lein with-profile -user,-dev inline-deps
2542
touch $@
2643

27-
test: clean .inline-deps test/resources/cider/nrepl/clojuredocs/export.edn
44+
test_impl: $(TEST_RUNNER_SOURCE_DIR) test/resources/cider/nrepl/clojuredocs/export.edn
2845
rm -f .no-mranderson
29-
lein with-profile -user,-dev,+$(CLOJURE_VERSION),+test,+plugin.mranderson/config test
46+
@if [[ "$$PARSER_TARGET" == "parser-next" ]] ; then \
47+
export SKIP_INLINING_TEST_DEPS=true; \
48+
bash 'lein' 'update-in' ':plugins' 'conj' "[mx.cider/lein-enrich-classpath \"$(ENRICH_CLASSPATH_VERSION)\"]" '--' 'with-profile' $(TEST_PROFILES),+cognitest,+$(CLOJURE_VERSION) 'update-in' ':middleware' 'conj' 'cider.enrich-classpath.plugin-v2/middleware' '--' 'repl' | grep " -cp " > .test-classpath; \
49+
cat .test-classpath; \
50+
eval "$$(cat .test-classpath)"; \
51+
rm .test-classpath; \
52+
elif [[ "$$PARSER_TARGET" == "parser" ]] ; then \
53+
export SKIP_INLINING_TEST_DEPS=true; \
54+
bash 'lein' 'update-in' ':plugins' 'conj' "[mx.cider/lein-enrich-classpath \"$(ENRICH_CLASSPATH_VERSION)\"]" '--' 'with-profile' $(TEST_PROFILES),+cognitest,+$(CLOJURE_VERSION) 'update-in' ':middleware' 'conj' 'cider.enrich-classpath.plugin-v2/middleware' '--' 'repl' | grep " -cp " > .test-classpath; \
55+
cat .test-classpath; \
56+
sed $(SED_INPLACE) 's/--add-opens=jdk.compiler\/com.sun.tools.javac.code=ALL-UNNAMED//g' .test-classpath; \
57+
sed $(SED_INPLACE) 's/--add-opens=jdk.compiler\/com.sun.tools.javac.tree=ALL-UNNAMED//g' .test-classpath; \
58+
cat .test-classpath; \
59+
eval "$$(cat .test-classpath)"; \
60+
rm .test-classpath; \
61+
elif [[ "$$PARSER_TARGET" == "legacy-parser" ]] ; then \
62+
export SKIP_INLINING_TEST_DEPS=true; \
63+
lein with-profile +$(CLOJURE_VERSION),$(TEST_PROFILES) test; \
64+
else \
65+
echo "PARSER_TARGET unset!"; \
66+
exit 1; \
67+
fi
68+
69+
test: clean .inline-deps
70+
@make test_impl TEST_PROFILES="$(TEST_PROFILES),+plugin.mranderson/config"
3071

31-
quick-test: clean
32-
lein with-profile -user,-dev,+$(CLOJURE_VERSION),+test test
72+
quick-test: clean test_impl
3373

3474
fast-test: quick-test
3575

@@ -81,7 +121,9 @@ fast-install: dump-version check-install-env
81121
make clean
82122
git checkout resources/cider/nrepl/version.edn
83123

84-
smoketest: install
124+
smoketest:
125+
export SKIP_INLINING_TEST_DEPS=true
126+
make install
85127
cd test/smoketest && \
86128
lein with-profile -user,-dev,+$(CLOJURE_VERSION) uberjar && \
87129
java -jar target/smoketest-0.1.0-SNAPSHOT-standalone.jar
@@ -127,6 +169,7 @@ clean:
127169
# Launches a repl, falling back to vanilla lein repl if something went wrong during classpath calculation.
128170
lein-repl: .enrich-classpath-lein-repl
129171
@if grep --silent " -cp " .enrich-classpath-lein-repl; then \
172+
export YOURKIT_SESSION_NAME="$(basename $(PWD))";
130173
eval "$$(cat .enrich-classpath-lein-repl) --interactive"; \
131174
else \
132175
echo "Falling back to lein repl... (you can avoid further falling back by removing .enrich-classpath-lein-repl)"; \

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ These are its main tasks for local development:
7373
make repl
7474
7575
# Run tests, using mranderson (slower but more realistic)
76-
make test
76+
PARSER_TARGET=parser-next make test
7777
7878
# Run tests, without using mranderson (considerably faster)
79-
make fast-test
79+
PARSER_TARGET=parser-next make fast-test
8080
8181
# Install the project in your local ~/.m2 directory, using mranderson (recommended)
8282
# The JVM flag is a temporary workaround.

project.clj

+27-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
:url "http://www.eclipse.org/legal/epl-v10.html"}
99
:scm {:name "git" :url "https://github.com/clojure-emacs/cider-nrepl"}
1010
:dependencies [[nrepl "1.0.0"]
11-
^:inline-dep [cider/orchard "0.15.1" :exclusions [com.google.code.findbugs/jsr305 com.google.errorprone/error_prone_annotations]]
11+
~(with-meta '[cider/orchard "0.15.1" :exclusions [com.google.code.findbugs/jsr305 com.google.errorprone/error_prone_annotations]]
12+
;; orchard is used in a test, so we cannot inline it while running tests.
13+
{:inline-dep (not= "true" (System/getenv "SKIP_INLINING_TEST_DEPS"))})
1214
^:inline-dep [mx.cider/haystack "0.3.1"]
1315
^:inline-dep [thunknyc/profile "0.5.2"]
1416
^:inline-dep [mvxcvi/puget "1.3.4"]
1517
^:inline-dep [fipp ~fipp-version] ; can be removed in unresolved-tree mode
1618
^:inline-dep [compliment "0.4.4-20230929.205009-1"]
1719
^:inline-dep [org.rksm/suitable "0.5.0" :exclusions [org.clojure/clojurescript]]
1820
^:inline-dep [cljfmt "0.9.2" :exclusions [org.clojure/clojurescript]]
19-
^:inline-dep [org.clojure/tools.namespace "1.3.0"]
21+
~(with-meta '[org.clojure/tools.namespace "1.3.0"]
22+
;; :cognitest uses tools.namespace, so we cannot inline it while running tests.
23+
{:inline-dep (not= "true" (System/getenv "SKIP_INLINING_TEST_DEPS"))})
2024
^:inline-dep [org.clojure/tools.trace "0.7.11"]
2125
^:inline-dep [org.clojure/tools.reader "1.3.6"]
2226
[mx.cider/logjam "0.1.1"]]
@@ -104,7 +108,7 @@
104108
[org.clojure/clojurescript "1.11.60" :scope "provided"]]}
105109

106110
:maint {:source-paths ["src" "maint"]
107-
:dependencies [[org.clojure/tools.cli "1.0.206"]]}
111+
:dependencies [[org.clojure/tools.cli "1.0.214"]]}
108112

109113
:test {:global-vars {*assert* true}
110114
:source-paths ["test/src"]
@@ -123,6 +127,26 @@
123127
com.google.code.findbugs/jsr305]]
124128
[cider/piggieback "0.5.3"]]}
125129

130+
;; Running the tests with enrich-classpath doing its thing isn't compatible with `lein test`
131+
;; (because there's no such thing as "run `lein test` using this specific classpath"),
132+
;; So we use cognitect.test-runner instead.
133+
:cognitest {:dependencies [[org.clojure/tools.namespace "1.4.4"]
134+
[org.clojure/tools.cli "1.0.214"]]
135+
:source-paths ["test-runner/src"]
136+
;; This piece of middleware dynamically adds the test paths to a cognitect.test-runner main invocation.
137+
:middleware [~(do
138+
(defn add-cognitest [{:keys [test-paths] :as project}]
139+
(assert (seq test-paths))
140+
(let [cmd (reduce into [["cognitect.test-runner"]
141+
(vec
142+
(interleave (take (count test-paths)
143+
(repeat "--dir"))
144+
test-paths))
145+
["--namespace-regex" (pr-str ".*")]
146+
["--exclude" "cognitest-exclude"]])]
147+
(assoc-in project [:enrich-classpath :main] (clojure.string/join " " cmd))))
148+
`add-cognitest)]}
149+
126150
;; Need ^:repl because of: https://github.com/technomancy/leiningen/issues/2132
127151
:repl ^:repl [:test
128152
{:repl-options {:nrepl-middleware [cider.nrepl/wrap-apropos

test/clj/cider/nrepl/middleware/info_test.clj

+32-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
[clojure.data]
77
[clojure.java.io :as io]
88
[clojure.string :as str]
9-
[clojure.test :refer :all])
9+
[clojure.test :refer :all]
10+
[orchard.misc :as misc])
1011
(:import
1112
(cider.nrepl.test AnotherTestClass TestClass YetAnotherTest)
1213
(org.apache.commons.lang3 SystemUtils)))
@@ -20,6 +21,23 @@
2021
(boolean (or (io/resource "java/lang/Thread.java")
2122
(io/resource "java.base/java/lang/Thread.java"))))
2223

24+
;; TODO: use `orchard.java/parser-next-available?` after Orchar's next release
25+
(def parser-next-available?
26+
(delay ;; avoid the side-effects at compile-time
27+
(atom ;; make the result mutable - this is helpful in case the detection below wasn't sufficient
28+
(and (>= misc/java-api-version 9)
29+
(try
30+
;; indicates that the classes are available
31+
;; however it does not indicate if necessary `add-opens=...` JVM flag is in place:
32+
(and
33+
(Class/forName "com.sun.tools.javac.tree.DCTree$DCBlockTag")
34+
(Class/forName "com.sun.tools.javac.code.Type$ArrayType")
35+
(seq (do
36+
(require 'orchard.java.parser-next)
37+
((resolve 'orchard.java.parser-next/source-info) `String))))
38+
(catch Throwable e
39+
false))))))
40+
2341
(deftest format-response-test
2442
(is (re-find #"^(https?|file|jar|zip):" ; resolved either locally or online
2543
(-> (info/info {:class "java.lang.Object" :member "toString"})
@@ -146,7 +164,7 @@
146164
(is (= (:doc response) "a macro for testing"))
147165
(is (nil? (:spec response)))))
148166

149-
(when enriched-classpath?
167+
(when @@parser-next-available?
150168
(testing "'fragments' attributes are returned"
151169
(let [{:keys [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments]
152170
:as response}
@@ -197,7 +215,9 @@
197215
(pr-str response))
198216
(is (= (:class response) "cider.nrepl.test.TestClass"))
199217
(is (= (:member response) "doSomething"))
200-
(is (= "[int int java.lang.String]" (:arglists-str response)))
218+
(is (#{"[int int java.lang.String]" ;; without enrich-classpath in
219+
"[a b c]"} ;; with enrich-classpath in
220+
(:arglists-str response)))
201221
(is (= (:argtypes response) ["int" "int" "java.lang.String"]))
202222
(is (= (:returns response) "void"))
203223
(is (= (:modifiers response) "#{:private :static}"))
@@ -382,7 +402,7 @@
382402
(is (not (contains? response :ns)))
383403
(is (= "function" (:type response)))))))
384404

385-
(when enriched-classpath?
405+
(when @@parser-next-available?
386406
(testing "Fragments for java interop method with single class"
387407
(let [{:keys [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments]
388408
:as response}
@@ -403,10 +423,16 @@
403423

404424
(testing "java method eldoc lookup, internal testing methods"
405425
(let [response (session/message {:op "eldoc" :sym "fnWithSameName" :ns "cider.nrepl.middleware.info-test"})]
406-
(is (= #{["this"] ;;TestClass
426+
(is (#{;; without enrich-classpath in:
427+
#{["this"] ;;TestClass
407428
["int" "java.lang.String" "boolean"] ;;AnotherTestClass
408429
["this" "byte[]" "java.lang.Object[]" "java.util.List"]} ;;YetAnotherTest
409-
(set (:eldoc response)))
430+
431+
;; with enrich-classpath in:
432+
#{["this"]
433+
["a" "b" "c"]
434+
["this" "prim" "things" "generic"]}}
435+
(set (:eldoc response)))
410436
(pr-str response))
411437
(is (= "function" (:type response)))))))
412438

test/clj/cider/nrepl/plugin_test.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
['cider/cider-nrepl version-string]]
1111
:repl-options {:nrepl-middleware mw/cider-middleware}})
1212

13-
(deftest version-checks
13+
(deftest ^:cognitest-exclude version-checks
1414
(testing "undefined versions work"
1515
(is (= expected-output
1616
(middleware {:dependencies [['org.clojure/clojure]]}))))

0 commit comments

Comments
 (0)