/ build.clj
build.clj
 1  (ns build
 2    "Basic build script for Selmer.
 3  
 4    Automatically compiles selmer.node when running tests:
 5  
 6    clojure -T:build test
 7  
 8    This will exclude the :benchmark tests by default.
 9    You can specify :select :benchmark to run just the
10    benchmark tests, or :select :all to run all the tests."
11    (:refer-clojure :exclude [test])
12    (:require [clojure.tools.build.api :as b]
13              [org.corfield.build :as bb]))
14  
15  (defn prep
16    "Compile selmer.node to target/classes."
17    [_]
18    (b/compile-clj {:basis (bb/default-basis)
19                    :class-dir (bb/default-class-dir)
20                    :ns-compile ['selmer.node]}))
21  
22  (defn test
23    "Run the tests, ensuring that selmer.node is compiled first.
24  
25    The :select option can be provided to determine which tests
26    to run, and can be :default, :benchmark, or :all. If omitted,
27    the :default selector is used, which means 'not :benchmark'.
28  
29    If :aliases is specified, those will be used in addition to
30    the :dev alias (which is always used)."
31    [opts]
32    ;; find ALL test namespaces under test, not just *-test ones:
33    ;; (because benchmarks are not in *-test namespace!)
34    (let [selector (case (:select opts :default)
35                     :default   {:main-opts ["-e" "benchmark" "-r" ".*"]}
36                     :benchmark {:main-opts ["-i" "benchmark" "-r" ".*"]}
37                     :all       {:main-opts ["-r" ".*"]})]
38      (prep {})
39      (bb/run-tests (-> opts
40                        (dissoc :select) ; remove our custom option
41                        (merge selector) ; add our main opts
42                        ;; ensure :dev alias is used!
43                        (update :aliases (fnil conj []) :dev)))))