cljs.test for bootstrap
Description
Environment
Attachments
Activity
I've tested this patch using a downstream example repository that illustrates testing a library targeting bootstrap. It also makes use of a custom test assert. This shows that all of the secondary goals in the ticket description are met.
(The downstream repo, for those interested: https://github.com/mfikes/titrate)
Attaching CLJS-1616-1.patch for feedback. (It might be good to go.)
It makes some very minor changes to the production code so that cljs.test
can be loaded in bootstrap environments.
The renames
src/main/cljs/cljs/test.clj → src/main/cljs/cljs/test.cljc
src/main/clojure/cljs/analyzer/api.clj → src/main/clojure/cljs/analyzer/api.cljc
actually involve very few changes after renames.
In addition to running the regular ClojureScript tests, I've confirmed that you can build an uberjar and still properly (require '[cljs.test :refer-macros [deftest is]])
in a REPL. I've also confirmed that tools.reader
, which runs CLJS tests can still do so with these changes.
In addition it adds a new script/test-self-parity
which will run (most of) the compiler unit tests in bootstrap mode in Node. This is done by bringing up an :optimizations :none
environment in Node and using the cljs.js
capability to load the compiler unit tests along with cljs.test
. Of interest is that this script pulls out the clojure.template
namespace so it can be loaded. (Downstream projects that might end using script/test-self-parity
as an example of how to run their own unit tests in bootstrap mode would need to do something similar.)
(Note: If we can come up with a better name than "parity", willing to revise it. script/test-self-host
was taken.)
This patch does not address writing custom assert assert-expr
in ClojureScript by treating the defaulti
as being in the cljs.test
namespace (as is illustrated in http://blog.fikesfarm.com/posts/2016-02-25-custom-test-asserts-in-planck.html), but I did confirm that you can easily achieve the same by simply working with cljs.test$macros/assert-expr
.
Make it so that the
cljs.test
namespace can work with bootstrap ClojureScript.Currently the known obstacles that prevent this largely surround macros, but they are known to be solvable. (It has been done successfully downstream in Planck.)
Primary goals:
Preserve existing functionality and performance for regular JVM ClojureScript users of
cljs.test
Make it so that
cljs.test
namespace can be loaded in any bootstrap environment that makes use ofcljs.js
and implements load functions supporting macros.Add scripted facilities so that the ClojureScript compiler's unit tests can be executed (perhaps in Node if installed) as an auxiliarry test capability (like
script/test
but for self-host)Secondary goals:
Ensure that it is possible for downstream ClojureScript projects that target bootstrap can make use
cljs.test
to run their test suites in bootstrap mode. (The ClojureScript compiler wouldn't provide any scripts for this—it would just strive to ensure that this is possible.)Support custom asserts
assert-expr
in bootstrap mode which are written in ClojureScript (as compared to Clojure for the JVM-based approach). (This has been shown to be possible with downstream Planck.)Rationale:
While bootstrap is of lower priority than regular JVM-based ClojureScript, it is still a burden to support it: It is easy to make a change to the compiler, but forget a conditional branch for bootstrap, or some such, thus causing a regression for bootstrap. With this capability, we'd have the ability to run the very same compiler unit tests in bootstrap mode, thus drastically reducing the support burden for bootstrap's existence.
Secondarily, this would help downstream libraries confidently target bootstrap as an environment by facilitating those libraries in running their own unit tests using
cljs.test
.