Skip to content

Commit 86fe091

Browse files
ikappakifogus
authored andcommitted
DXML-67 support cljs tests on JDK [15,17]
- Also fixes newline test errors on MS-Windows.
1 parent b869406 commit 86fe091

File tree

7 files changed

+54
-26
lines changed

7 files changed

+54
-26
lines changed

pom.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@
3535
<version>1.1.0</version>
3636
</parent>
3737

38+
<profiles>
39+
<profile>
40+
<id>openjdk-nashorn</id>
41+
<activation>
42+
<jdk>[15,18)</jdk>
43+
</activation>
44+
<dependencies>
45+
<dependency>
46+
<groupId>org.openjdk.nashorn</groupId>
47+
<artifactId>nashorn-core</artifactId>
48+
<version>15.3</version>
49+
<scope>test</scope>
50+
</dependency>
51+
</dependencies>
52+
</profile>
53+
</profiles>
54+
3855
<dependencies>
3956
<dependency>
4057
<groupId>org.clojure</groupId>
@@ -64,7 +81,7 @@
6481
<properties>
6582
<!-- set clojure.version to >= 1.8.0 to run cljs test suite
6683
(and make sure to run on jdk >= 1.8 for nashorn support) -->
67-
<clojure.version>1.7.0</clojure.version>
84+
<clojure.version>1.8.0</clojure.version>
6885
</properties>
6986

7087
<pluginRepositories>

project.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
:resource-paths ["src/main/resources" "src/test/resources" "target/gen-resources"]
55
:dependencies [[org.clojure/clojure "1.10.0-beta8"]
66
[org.clojure/clojurescript "1.10.439"]
7-
[com.cemerick/piggieback "0.2.2"]
7+
[cider/piggieback "0.5.3"]
88
[org.clojure/tools.nrepl "0.2.13"]
99
[org.clojure/test.check "0.9.0"]
1010
[figwheel-sidecar "0.5.17"]
11-
[binaryage/devtools "0.9.10"]]
12-
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]})
11+
[binaryage/devtools "0.9.10"]
12+
[org.openjdk.nashorn/nashorn-core "15.3"]]
13+
:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]})

src/test/clojure/clojure/data/xml/test_emit.clj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:author "Chris Houser"}
1111
clojure.data.xml.test-emit
1212
(:require
13+
[clojure.string :as str]
1314
[clojure.test :refer :all]
1415
[clojure.data.xml :refer :all]
1516
[clojure.data.xml.test-utils :refer [test-stream lazy-parse*]]
@@ -137,7 +138,8 @@
137138

138139
(deftest test-indent
139140
(let [nested-xml (lazy-parse* (str "<a><b><c><d>foo</d></c></b></a>"))
140-
expect (str "<a>\n <b>\n <c>\n <d>foo</d>\n </c>\n </b>\n</a>\n")
141+
expect (-> "<a>\n <b>\n <c>\n <d>foo</d>\n </c>\n </b>\n</a>\n"
142+
(str/replace #"\n" (System/lineSeparator)))
141143
sw (java.io.StringWriter.)
142144
_ (indent nested-xml sw)
143145
result (.toString sw)]
@@ -146,14 +148,16 @@
146148

147149
(deftest test-indent-str
148150
(let [nested-xml (lazy-parse* (str "<a><b><c><d>foo</d></c></b></a>"))
149-
expect (str "<a>\n <b>\n <c>\n <d>foo</d>\n </c>\n </b>\n</a>\n")
151+
expect (-> "<a>\n <b>\n <c>\n <d>foo</d>\n </c>\n </b>\n</a>\n"
152+
(str/replace #"\n" (System/lineSeparator)))
150153
result (indent-str nested-xml)]
151154
(is (= expect (subs result (.indexOf result "<a>"))))))
152155

153156
(deftest test-indent-str-with-doctype
154157
(let [nested-xml (lazy-parse* (str "<a><b><c><d>foo</d></c></b></a>"))
155158
doctype "<!DOCTYPE html>"
156-
expect "\n<a>\n <b>\n <c>\n <d>foo</d>\n </c>\n </b>\n</a>\n"
159+
expect (-> "\n<a>\n <b>\n <c>\n <d>foo</d>\n </c>\n </b>\n</a>\n"
160+
(str/replace #"\n" (System/lineSeparator)))
157161
result (indent-str nested-xml :doctype doctype)
158162
offset-dt (.indexOf result "<!DOCTYPE")
159163
offset-res (inc (.indexOf result ">" offset-dt))]

src/test/clojure/clojure/data/xml/test_pprint.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:author "Herwig Hochleitner"}
1111
clojure.data.xml.test-pprint
1212
(:require
13+
[clojure.string :as str]
1314
[clojure.test :refer :all]
1415
[clojure.data.xml :refer :all]))
1516

@@ -26,5 +27,6 @@
2627
"))
2728

2829
(deftest test-indent
29-
(is (= indented-xml (indent-str (parse-str xml)))))
30+
(is (= (str/replace indented-xml #"\n" (System/lineSeparator))
31+
(indent-str (parse-str xml)))))
3032

src/test/clojurescript/clojure/data/xml/cljs_repls.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(ns clojure.data.xml.cljs-repls
22
(:require
33
[cljs.repl :as repl]
4-
[cljs.repl.nashorn :as repl-nh]
5-
[cemerick.piggieback :as pback]
4+
[clojure.data.xml.cljs-repl-nashorn :as repl-nh]
5+
[cider.piggieback :as pback]
66
[cljs.closure :as closure]
77
[figwheel-sidecar.repl-api :refer [start-figwheel! stop-figwheel! cljs-repl]]))
88

src/test/resources/clojure/data/xml/cljs_repl_nashorn.clj

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
;; the terms of this license.
77
;; You must not remove this notice, or any other, from this software.
88

9-
(ns cljs.repl.nashorn
9+
;; cljs repl nashorn update to support the openjdk nashorn package in
10+
;; JDK versions greater than 15.
11+
;;
12+
;; Adapted from
13+
;; https://raw.githubusercontent.com/clojure/clojurescript/r1.10.439/src/main/clojure/cljs/repl/nashorn.clj.
14+
15+
(ns clojure.data.xml.cljs-repl-nashorn
1016
(:require [clojure.java.io :as io]
1117
[clojure.string :as string]
1218
[clojure.stacktrace]
@@ -21,17 +27,25 @@
2127
[cljs.stacktrace :as st])
2228
(:import [javax.script ScriptEngine ScriptEngineManager ScriptException ScriptEngineFactory]))
2329

24-
(util/compile-if (Class/forName "jdk.nashorn.api.scripting.NashornException")
30+
(def engine-name
31+
(util/compile-if (Class/forName "org.openjdk.nashorn.api.scripting.NashornException")
32+
(do
33+
(import 'org.openjdk.nashorn.api.scripting.NashornException)
34+
"OpenJDK Nashorn")
35+
(do
36+
(import 'jdk.nashorn.api.scripting.NashornException)
37+
"Oracle Nashorn")))
38+
39+
(do
2540
(do
26-
(import 'jdk.nashorn.api.scripting.NashornException)
2741
;; Implementation
2842

2943
(defn create-engine
3044
([] (create-engine nil))
3145
([{:keys [code-cache] :or {code-cache true}}]
3246
(let [args (when code-cache ["-pcc"])
3347
factories (.getEngineFactories (ScriptEngineManager.))
34-
factory (get (zipmap (map #(.getEngineName %) factories) factories) "Oracle Nashorn")]
48+
factory (get (zipmap (map #(.getEngineName %) factories) factories) engine-name)]
3549
(if-let [engine (if-not (empty? args)
3650
(.getScriptEngine ^ScriptEngineFactory factory (into-array args))
3751
(.getScriptEngine ^ScriptEngineFactory factory))]
@@ -180,14 +194,4 @@
180194
(defn -main [& args]
181195
(apply cli/main repl-env args)))
182196

183-
(do
184-
(defn repl-env* [{:keys [debug] :as opts}]
185-
(throw (ex-info "Nashorn not supported" {:type :repl-error})))
186-
187-
(defn repl-env
188-
"Create a Nashorn repl-env for use with the repl/repl* method in Clojurescript."
189-
[& {:as opts}]
190-
(throw (ex-info "Nashorn not available under this Java runtime" {:type :repl-error})))
191-
192-
(defn -main []
193-
(throw (ex-info "Nashorn not available under this Java runtime" {:type :repl-error})))))
197+
)

src/test/resources/clojure/data/xml/cljs_testsuite.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(:require
33
[clojure.test :refer :all]
44
[cljs.repl :as repl]
5-
[cljs.repl.nashorn :as repl-nh]
5+
[clojure.data.xml.cljs-repl-nashorn :as repl-nh]
66
[cljs.closure :as closure]
77
[cljs.build.api :as bapi]
88
[clojure.string :as str]

0 commit comments

Comments
 (0)