Skip to content

Commit 28e040d

Browse files
mfikesdnolen
authored and
dnolen
committed
CLJS-1626: cljs.test for bootstrap
1 parent 56611b5 commit 28e040d

File tree

5 files changed

+534
-77
lines changed

5 files changed

+534
-77
lines changed

script/test-self-parity

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
# stop blowing compiled stuff
4+
rm -rf builds/out-self-parity
5+
mkdir -p builds/out-self-parity
6+
7+
# extract needed files from clojure.jar
8+
if [ ! -f lib/clojure.jar ]; then
9+
echo "Run script/bootstrap first"
10+
exit 1
11+
fi
12+
jar xvf lib/clojure.jar clojure/template.clj > /dev/null
13+
mkdir -p builds/out-self-parity/clojure
14+
mv clojure/template.clj builds/out-self-parity/clojure
15+
16+
bin/cljsc src/test/self/self_parity "{:optimizations :none :output-to \"builds/out-self-parity/main.js\" :output-dir \"builds/out-self-parity\" :main self-parity.test :target :nodejs}"
17+
18+
echo "Testing with Node"
19+
node builds/out-self-parity/main.js

src/main/cljs/cljs/test.clj renamed to src/main/cljs/cljs/test.cljc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
; You must not remove this notice, or any other, from this software.
88

99
(ns cljs.test
10+
#?(:cljs (:require-macros [clojure.template :as temp]))
1011
(:require [cljs.env :as env]
1112
[cljs.analyzer :as ana]
1213
[cljs.analyzer.api :as ana-api]
13-
[clojure.template :as temp]))
14+
#?(:clj [clojure.template :as temp])))
1415

1516
;; =============================================================================
1617
;; Utilities for assertions
@@ -137,7 +138,7 @@
137138
You don't call this."
138139
[msg form]
139140
`(try
140-
~(cljs.test/assert-expr &env msg form)
141+
~(assert-expr &env msg form)
141142
(catch :default t#
142143
(cljs.test/do-report
143144
{:type :error, :message ~msg,
@@ -162,7 +163,7 @@
162163
re-find) the regular expression re."
163164
([form] `(cljs.test/is ~form nil))
164165
([form msg]
165-
`(cljs.test/try-expr ~msg ~form)))
166+
`(try-expr ~msg ~form)))
166167

167168
(defmacro are
168169
"Checks multiple assertions with a template expression.
@@ -186,7 +187,7 @@
186187
(pos? (count args))
187188
(zero? (mod (count args) (count argv)))))
188189
`(clojure.template/do-template ~argv (is ~expr) ~@args)
189-
(throw (IllegalArgumentException. "The number of args doesn't match are's argv."))))
190+
(throw (#?(:clj Exception. :cljs js/Error.) "The number of args doesn't match are's argv."))))
190191

191192
(defmacro testing
192193
"Adds a new string to the list of testing contexts. May be nested,
@@ -276,8 +277,8 @@
276277
namespaces))
277278
[(fn []
278279
(cljs.test/set-env! ~env)
279-
(do-report (deref ~summary))
280-
(report (assoc (deref ~summary) :type :end-run-tests))
280+
(cljs.test/do-report (deref ~summary))
281+
(cljs.test/report (assoc (deref ~summary) :type :end-run-tests))
281282
(cljs.test/clear-env!))]))))
282283

283284
(defmacro run-tests
@@ -384,4 +385,4 @@
384385
[~@fns])
385386
:else
386387
(throw
387-
(Exception. "First argument to cljs.test/use-fixtures must be :once or :each"))))
388+
(#?(:clj Exception. :cljs js/Error.) "First argument to cljs.test/use-fixtures must be :once or :each"))))

src/main/clojure/cljs/analyzer/api.clj renamed to src/main/clojure/cljs/analyzer/api.cljc

Lines changed: 73 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -65,75 +65,78 @@
6565
([state]
6666
(get @state :js-dependency-index)))
6767

68-
(defn analyze
69-
"Given an environment, a map containing {:locals (mapping of names to bindings), :context
70-
(one of :statement, :expr, :return), :ns (a symbol naming the
71-
compilation ns)}, and form, returns an expression object (a map
72-
containing at least :form, :op and :env keys). If expr has any (immediately)
73-
nested exprs, must have :children [exprs...] entry. This will
74-
facilitate code walking without knowing the details of the op set."
75-
([env form] (analyze env form nil))
76-
([env form name] (analyze env form name nil))
77-
([env form name opts]
78-
(analyze
79-
(if-not (nil? env/*compiler*)
80-
env/*compiler*
81-
(env/default-compiler-env opts))
82-
env form name opts))
83-
([state env form name opts]
84-
(env/with-compiler-env state
85-
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
86-
(ana/analyze env form name opts)))))
87-
88-
(defn forms-seq
89-
"Seq of Clojure/ClojureScript forms from rdr, a java.io.Reader. Optionally
90-
accepts a filename argument which will be used in any emitted errors."
91-
([rdr] (ana/forms-seq* rdr nil))
92-
([rdr filename] (ana/forms-seq* rdr filename)))
93-
94-
(defn parse-ns
95-
"Helper for parsing only the essential namespace information from a
96-
ClojureScript source file and returning a cljs.closure/IJavaScript compatible
97-
map _not_ a namespace AST node.
98-
99-
By default does not load macros or perform any analysis of dependencies. If
100-
opts parameter provided :analyze-deps and :load-macros keys their values will
101-
be used for *analyze-deps* and *load-macros* bindings respectively. This
102-
function does _not_ side-effect the ambient compilation environment unless
103-
requested via opts where :restore is false."
104-
([src] (parse-ns src nil nil))
105-
([src opts] (parse-ns src nil opts))
106-
([src dest opts]
107-
(parse-ns
108-
(if-not (nil? env/*compiler*)
109-
env/*compiler*
110-
(env/default-compiler-env opts))
111-
src dest opts))
112-
([state src dest opts]
113-
(env/with-compiler-env state
114-
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
115-
(ana/parse-ns src dest opts)))))
116-
117-
(defn analyze-file
118-
"Given a java.io.File, java.net.URL or a string identifying a resource on the
119-
classpath attempt to analyze it.
120-
121-
This function side-effects the ambient compilation environment
122-
`cljs.env/*compiler*` to aggregate analysis information. opts argument is
123-
compiler options, if :cache-analysis true will cache analysis to
124-
\":output-dir/some/ns/foo.cljs.cache.edn\". This function does not return a
125-
meaningful value."
126-
([f] (analyze-file f nil))
127-
([f opts]
128-
(analyze-file
129-
(if-not (nil? env/*compiler*)
130-
env/*compiler*
131-
(env/default-compiler-env opts))
132-
f opts))
133-
([state f opts]
134-
(env/with-compiler-env state
135-
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
136-
(ana/analyze-file f opts)))))
68+
#?(:clj
69+
(defn analyze
70+
"Given an environment, a map containing {:locals (mapping of names to bindings), :context
71+
(one of :statement, :expr, :return), :ns (a symbol naming the
72+
compilation ns)}, and form, returns an expression object (a map
73+
containing at least :form, :op and :env keys). If expr has any (immediately)
74+
nested exprs, must have :children [exprs...] entry. This will
75+
facilitate code walking without knowing the details of the op set."
76+
([env form] (analyze env form nil))
77+
([env form name] (analyze env form name nil))
78+
([env form name opts]
79+
(analyze
80+
(if-not (nil? env/*compiler*)
81+
env/*compiler*
82+
(env/default-compiler-env opts))
83+
env form name opts))
84+
([state env form name opts]
85+
(env/with-compiler-env state
86+
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
87+
(ana/analyze env form name opts))))))
88+
89+
#?(:clj
90+
(defn forms-seq
91+
"Seq of Clojure/ClojureScript forms from rdr, a java.io.Reader. Optionally
92+
accepts a filename argument which will be used in any emitted errors."
93+
([rdr] (ana/forms-seq* rdr nil))
94+
([rdr filename] (ana/forms-seq* rdr filename))))
95+
96+
#?(:clj
97+
(defn parse-ns
98+
"Helper for parsing only the essential namespace information from a
99+
ClojureScript source file and returning a cljs.closure/IJavaScript compatible
100+
map _not_ a namespace AST node.
101+
102+
By default does not load macros or perform any analysis of dependencies. If
103+
opts parameter provided :analyze-deps and :load-macros keys their values will
104+
be used for *analyze-deps* and *load-macros* bindings respectively. This
105+
function does _not_ side-effect the ambient compilation environment unless
106+
requested via opts where :restore is false."
107+
([src] (parse-ns src nil nil))
108+
([src opts] (parse-ns src nil opts))
109+
([src dest opts]
110+
(parse-ns
111+
(if-not (nil? env/*compiler*)
112+
env/*compiler*
113+
(env/default-compiler-env opts))
114+
src dest opts))
115+
([state src dest opts]
116+
(env/with-compiler-env state
117+
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
118+
(ana/parse-ns src dest opts))))))
119+
#?(:clj
120+
(defn analyze-file
121+
"Given a java.io.File, java.net.URL or a string identifying a resource on the
122+
classpath attempt to analyze it.
123+
124+
This function side-effects the ambient compilation environment
125+
`cljs.env/*compiler*` to aggregate analysis information. opts argument is
126+
compiler options, if :cache-analysis true will cache analysis to
127+
\":output-dir/some/ns/foo.cljs.cache.edn\". This function does not return a
128+
meaningful value."
129+
([f] (analyze-file f nil))
130+
([f opts]
131+
(analyze-file
132+
(if-not (nil? env/*compiler*)
133+
env/*compiler*
134+
(env/default-compiler-env opts))
135+
f opts))
136+
([state f opts]
137+
(env/with-compiler-env state
138+
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
139+
(ana/analyze-file f opts))))))
137140

138141
;; =============================================================================
139142
;; Main API
@@ -146,7 +149,7 @@
146149
(try
147150
(ana/resolve-var env sym
148151
(ana/confirm-var-exists-throw))
149-
(catch Exception e
152+
(catch #?(:clj Exception :cljs :default) e
150153
(ana/resolve-macro-var env sym))))
151154

152155
(defn all-ns

src/test/self/self_parity/aux.cljs

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
(ns ^{:doc "This auxiliary namespace is not actually loaded.
2+
Its mere presence cause it to be compiled and thus causes
3+
the libs listed here to be dumped into the compiler output
4+
directory where they can be loaded on demand when running
5+
the compiler tests in bootstrap mode."}
6+
self-parity.aux
7+
(:require
8+
goog.Delay
9+
goog.Disposable
10+
goog.Promise
11+
goog.Throttle
12+
goog.Timer
13+
goog.Uri
14+
goog.array.ArrayLike
15+
goog.color
16+
goog.color.Hsl
17+
goog.color.Hsv
18+
goog.color.Rgb
19+
goog.color.alpha
20+
goog.color.names
21+
goog.crypt
22+
goog.crypt.Aes
23+
goog.crypt.Arc4
24+
goog.crypt.BlobHasher
25+
goog.crypt.Cbc
26+
goog.crypt.Hash
27+
goog.crypt.Hmac
28+
goog.crypt.JpegEncoder
29+
goog.crypt.Md5
30+
goog.crypt.Sha1
31+
goog.crypt.Sha2
32+
goog.crypt.Sha224
33+
goog.crypt.Sha256
34+
goog.crypt.Sha2_64bit
35+
goog.crypt.Sha512
36+
goog.crypt.Sha512_256
37+
goog.crypt.base64
38+
goog.crypt.baseN
39+
goog.crypt.hash32
40+
goog.crypt.hashTester
41+
goog.crypt.pbkdf2
42+
goog.date.Date
43+
goog.date.DateLike
44+
goog.date.DateRange
45+
goog.date.DateTime
46+
goog.date.Interval
47+
goog.date.UtcDateTime
48+
goog.date.duration
49+
goog.date.month
50+
goog.date.relative.TimeDeltaFormatter
51+
goog.date.relative.Unit
52+
goog.date.relativeWithPlurals
53+
goog.date.weekDay
54+
goog.format
55+
goog.format.EmailAddress
56+
goog.format.HtmlPrettyPrinter
57+
goog.format.InternationalizedEmailAddress
58+
goog.format.JsonPrettyPrinter
59+
goog.i18n.BidiFormatter
60+
goog.i18n.CharListDecompressor
61+
goog.i18n.CharPickerData
62+
goog.i18n.DateTimeFormat
63+
goog.i18n.DateTimeParse
64+
goog.i18n.GraphemeBreak
65+
goog.i18n.MessageFormat
66+
goog.i18n.NumberFormat
67+
goog.i18n.TimeZone
68+
goog.i18n.bidi
69+
goog.i18n.bidi.Dir
70+
goog.i18n.bidi.Format
71+
goog.i18n.collation
72+
goog.i18n.currency
73+
goog.i18n.mime
74+
goog.i18n.ordinalRules
75+
goog.i18n.pluralRules
76+
goog.i18n.uChar
77+
goog.i18n.uChar.LocalNameFetcher
78+
goog.i18n.uChar.RemoteNameFetcher
79+
goog.i18n.uCharNames
80+
goog.iter
81+
goog.iter.Iterable
82+
goog.iter.Iterator
83+
goog.json
84+
goog.json.EvalJsonProcessor
85+
goog.json.HybridJsonProcessor
86+
goog.json.NativeJsonProcessor
87+
goog.json.Replacer
88+
goog.json.Reviver
89+
goog.json.Serializer
90+
goog.json.hybrid
91+
goog.locale
92+
goog.locale.TimeZoneFingerprint
93+
goog.locale.defaultLocaleNameConstants
94+
goog.locale.genericFontNames
95+
goog.locale.timeZoneDetection
96+
goog.math
97+
goog.math.AffineTransform
98+
goog.math.Bezier
99+
goog.math.Box
100+
goog.math.Coordinate
101+
goog.math.Coordinate3
102+
goog.math.ExponentialBackoff
103+
goog.math.Integer
104+
goog.math.Line
105+
goog.math.Long
106+
goog.math.Matrix
107+
goog.math.Path
108+
goog.math.Path.Segment
109+
goog.math.Range
110+
goog.math.RangeSet
111+
goog.math.Rect
112+
goog.math.Size
113+
goog.math.Vec2
114+
goog.math.Vec3
115+
goog.math.interpolator.Linear1
116+
goog.math.interpolator.Pchip1
117+
goog.math.interpolator.Spline1
118+
goog.math.paths
119+
goog.math.tdma
120+
goog.spell.SpellCheck
121+
goog.string
122+
goog.string.Const
123+
goog.string.StringBuffer
124+
goog.string.Unicode
125+
goog.string.format
126+
goog.string.newlines
127+
goog.string.newlines.Line
128+
goog.structs
129+
goog.structs.AvlTree
130+
goog.structs.AvlTree.Node
131+
goog.structs.CircularBuffer
132+
goog.structs.Heap
133+
goog.structs.InversionMap
134+
goog.structs.LinkedMap
135+
goog.structs.Map
136+
goog.structs.Node
137+
goog.structs.Pool
138+
goog.structs.PriorityPool
139+
goog.structs.PriorityQueue
140+
goog.structs.QuadTree
141+
goog.structs.QuadTree.Node
142+
goog.structs.QuadTree.Point
143+
goog.structs.Queue
144+
goog.structs.Set
145+
goog.structs.SimplePool
146+
goog.structs.StringSet
147+
goog.structs.TreeNode
148+
goog.structs.Trie
149+
goog.structs.weak
150+
goog.text.LoremIpsum))

0 commit comments

Comments
 (0)