Add clojurescript support

This commit is contained in:
Miloslav Nenadal 2016-02-20 19:26:44 +01:00
parent 80f91373bb
commit 9cc02ff5bc
11 changed files with 464 additions and 1 deletions

1
.gitignore vendored
View file

@ -10,3 +10,4 @@
/pom.xml
*jar
*.asc
/resources/public/js/compiled/

View file

@ -4,6 +4,19 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:deploy-repositories [["releases" :clojars]]
:profiles {:dev {:dependencies [[org.clojure/clojure "1.3.0"]]}
:profiles {:dev {:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.7.228"]
[org.seleniumhq.selenium/selenium-java "2.52.0"]
[com.codeborne/phantomjsdriver "1.2.1"]]
:plugins [[lein-cljsbuild "1.1.2"]]
:cljsbuild {
:test-commands {"test" ["phantomjs" "resources/test/phantom/run.js" "resources/test/test.html"]}
:builds [{:id "test"
:source-paths ["src" "test"]
:compiler {:main pjstadig.run-all
:asset-path "../public/js/compiled/test/out"
:output-to "resources/public/js/compiled/humanize-test-output-test.js"
:output-dir "resources/public/js/compiled/test/out"
:source-map-timestamp true}}]}}
:test {:injections [(require 'pjstadig.humane-test-output)
(pjstadig.humane-test-output/activate!)]}})

View file

@ -0,0 +1,33 @@
var page = require('webpage').create();
var system = require('system');
if (system.args.length !== 2) {
console.log('Expected a target URL parameter.');
phantom.exit(1);
}
page.onConsoleMessage = function (message) {
console.log(message);
};
var url = system.args[1];
page.open(url, function (status) {
if (status !== "success") {
console.log('Failed to open ' + url);
setTimeout(function() { // https://github.com/ariya/phantomjs/issues/12697
phantom.exit(1);
}, 0);
}
var exitStatus = page.evaluate(function() {
pjstadig.run_all.run();
return window.testStatus;
});
setTimeout(function() { // https://github.com/ariya/phantomjs/issues/12697
phantom.exit(exitStatus);
}, 0);
});

6
resources/test/test.html Normal file
View file

@ -0,0 +1,6 @@
<html>
<body>
<script src="../public/js/compiled/humanize-test-output-test.js" type="text/javascript"></script>
</body>
</html>

View file

@ -0,0 +1,23 @@
(ns pjstadig.assert-expr
(:require [cljs.test :refer [assert-expr]]))
(defn =-body
[msg a more]
`(let [a# ~a]
(if-let [more# (seq (list ~@more))]
(let [result# (apply = a# more#)]
(if result#
(cljs.test/do-report {:type :pass, :message ~msg,
:expected a#, :actual more#})
(cljs.test/do-report {:type :fail, :message ~msg,
:expected a#, :actual more#,
:diffs (map vector
more#
(map #(take 2 (clojure.data/diff a# %))
more#))}))
result#)
(throw (Exception. "= expects more than one argument")))))
(defmethod assert-expr '= [menv msg [_ a & more]]
(=-body msg a more))

106
test/fixtures/test_output vendored Normal file
View file

@ -0,0 +1,106 @@
lein test pjstadig.humane-test-output.formatting-test
lein test :only pjstadig.humane-test-output.formatting-test/t-formatting
FAIL in (t-formatting) (formatting_test.clj:6)
FIXME, I fail.
expected: {:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}
actual: {:fo :bar}
diff: - {:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}
+ {:fo :bar}
lein test :only pjstadig.humane-test-output.formatting-test/t-formatting
FAIL in (t-formatting) (formatting_test.clj:9)
FIXME, I fail.
expected: {:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}
actual: {:foo :bar}
diff: - {:baz :quux,
:something "a long string?",
:another-key "and another value"}
lein test :only pjstadig.humane-test-output.formatting-test/t-formatting
FAIL in (t-formatting) (formatting_test.clj:12)
FIXME, I fail.
expected: {:foo :bar}
actual: {:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}
diff: + {:baz :quux,
:something "a long string?",
:another-key "and another value"}
lein test :only pjstadig.humane-test-output.formatting-test/t-formatting
FAIL in (t-formatting) (formatting_test.clj:15)
FIXME, I fail.
expected: {:foo :bar, :baz :quux}
actual: {:foo :bar, :baz :quux}
diff: + expected: {:foo :bar, :baz :quux}
actual: {:fo :bar, :baz :quux}
diff: - {:foo :bar}
+ {:fo :bar}
expected: {:foo :bar, :baz :quux}
actual: {:fo :bar, :baz :quux}
diff: - {:foo :bar}
+ {:fo :bar}
lein test :only pjstadig.humane-test-output.formatting-test/t-formatting
FAIL in (t-formatting) (formatting_test.clj:19)
FIXME, I fail.
expected: (list? foo)
actual: (not
(list?
{:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}))
lein test :only pjstadig.humane-test-output.formatting-test/t-macro-wrapping
FAIL in (t-macro-wrapping) (formatting_test.clj:26)
expected: 1
actual: 2
diff: - 1
+ 2
lein test pjstadig.humane-test-output.records-test
lein test :only pjstadig.humane-test-output.records-test/t-records
FAIL in (t-records) (records_test.clj:9)
these should not print as plain maps
expected: #pjstadig.humane_test_output.records_test.ARecord{:foo :foo}
actual: #pjstadig.humane_test_output.records_test.ARecord{:foo :bar}
diff: - {:foo :foo}
+ {:foo :bar}
lein test :only pjstadig.humane-test-output.records-test/t-records
FAIL in (t-records) (records_test.clj:11)
there should be a diff here
expected: #pjstadig.humane_test_output.records_test.ARecord{:foo :foo}
actual: {:foo :foo}
lein test :only pjstadig.humane-test-output.records-test/t-records
FAIL in (t-records) (records_test.clj:13)
and here
expected: #pjstadig.humane_test_output.records_test.ARecord{:foo :foo}
actual: #pjstadig.humane_test_output.records_test.BRecord{:foo :foo}
Ran 3 tests containing 9 assertions.
9 failures, 0 errors.

171
test/fixtures/test_output_cljs vendored Normal file
View file

@ -0,0 +1,171 @@
Compiling ClojureScript...
Running ClojureScript test: test
Testing pjstadig.humane-test-output.formatting-test
FAIL in (t-formatting) (:)
FIXME, I fail.
expected:
{:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}
actual:
{:fo :bar}
diff:
-
{:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}
+
{:fo :bar}
FAIL in (t-formatting) (:)
FIXME, I fail.
expected:
{:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}
actual:
{:foo :bar}
diff:
-
{:baz :quux,
:something "a long string?",
:another-key "and another value"}
+
FAIL in (t-formatting) (:)
FIXME, I fail.
expected:
{:foo :bar}
actual:
{:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}
diff:
+
{:baz :quux,
:something "a long string?",
:another-key "and another value"}
FAIL in (t-formatting) (:)
FIXME, I fail.
expected:
{:foo :bar, :baz :quux}
actual:
{:foo :bar, :baz :quux}
diff:
+
expected:
{:foo :bar, :baz :quux}
actual:
{:fo :bar, :baz :quux}
diff:
-
{:foo :bar}
+
{:fo :bar}
expected:
{:foo :bar, :baz :quux}
actual:
{:fo :bar, :baz :quux}
diff:
-
{:foo :bar}
+
{:fo :bar}
FAIL in (t-formatting) (:)
FIXME, I fail.
expected:
(list? foo)
actual:
(not
(list?
{:foo :bar,
:baz :quux,
:something "a long string?",
:another-key "and another value"}))
FAIL in (t-macro-wrapping) (:)
expected:
(clojure.core/= 1 2)
actual:
(not (clojure.core/= 1 2))
Testing pjstadig.humane-test-output.records-test
FAIL in (t-records) (:)
these should not print as plain maps
expected:
##pjstadig.humane-test-output.records-test.ARecord{:foo :foo}{:foo:foo}
actual:
##pjstadig.humane-test-output.records-test.ARecord{:foo :bar}{:foo:bar}
diff:
-
{:foo :foo}
+
{:foo :bar}
FAIL in (t-records) (:)
there should be a diff here
expected:
##pjstadig.humane-test-output.records-test.ARecord{:foo :foo}{:foo:foo}
actual:
{:foo :foo}
diff:
+
FAIL in (t-records) (:)
and here
expected:
##pjstadig.humane-test-output.records-test.ARecord{:foo :foo}{:foo:foo}
actual:
##pjstadig.humane-test-output.records-test.BRecord{:foo :foo}{:foo:foo}
diff:
+
Ran 3 tests containing 9 assertions.
9 failures, 0 errors.

View file

@ -0,0 +1,24 @@
(ns pjstadig.humane-test-output.formatting-test
(:use [clojure.data :only [diff]])
(:require [cljs.test :refer [do-report]])
(:require-macros [cljs.test :refer [deftest testing is]]
[pjstadig.macro :refer [deftest+]]))
(deftest t-formatting
(testing "FIXME, I fail."
(is (= {:foo :bar :baz :quux :something "a long string?"
:another-key "and another value"}
{:fo :bar}))
(is (= {:foo :bar :baz :quux :something "a long string?"
:another-key "and another value"}
{:foo :bar}))
(is (= {:foo :bar}
{:foo :bar :baz :quux :something "a long string?"
:another-key "and another value"}))
(is (= {:foo :bar :baz :quux} {:foo :bar :baz :quux} {:fo :bar :baz :quux}
{:fo :bar :baz :quux}))
(let [foo {:foo :bar :baz :quux :something "a long string?"
:another-key "and another value"}]
(is (list? foo)))))
(deftest+ t-macro-wrapping 1 2)

View file

@ -0,0 +1,15 @@
(ns pjstadig.humane-test-output.records-test
(:use [clojure.data :only [diff]])
(:require [cljs.test :refer [do-report]])
(:require-macros [cljs.test :refer [deftest testing is]]))
(defrecord ARecord [foo])
(defrecord BRecord [foo])
(deftest t-records
(testing "these should not print as plain maps"
(is (= (->ARecord :foo) (->ARecord :bar))))
(testing "there should be a diff here"
(is (= (->ARecord :foo) {:foo :foo})))
(testing "and here"
(is (= (->ARecord :foo) (->BRecord :foo)))))

7
test/pjstadig/macro.clj Normal file
View file

@ -0,0 +1,7 @@
(ns pjstadig.macro)
(defmacro deftest+
[test-name expected actual]
`(~'deftest ~test-name
(~'is (= ~expected ~actual))))

View file

@ -0,0 +1,64 @@
(ns pjstadig.run-all
(:require [cljs.test
:refer [inc-report-counter! testing-vars-str testing-contexts-str get-current-env]
:refer-macros [run-all-tests run-tests]]
[pjstadig.humane-test-output.formatting-test]
[pjstadig.humane-test-output.records-test]
[cljs.pprint :as pp])
(:require-macros [pjstadig.assert-expr]))
(enable-console-print!)
(def pprint-map (get-method pp/simple-dispatch :map))
(defn pprint-record [arec]
(pp/pprint-logical-block
:prefix (str "#" (with-out-str (print arec)) "{") :suffix "}"
(pp/print-length-loop
[aseq (seq arec)]
(when aseq
(pp/pprint-logical-block
(pp/write-out (ffirst aseq))
(print " ")
(pp/pprint-newline :linear)
;; [pjs] this is kind of ugly, but it is a private var :(
(set! pp/*current-length* 0) ; always print both parts of the [k v] pair
(pp/write-out (fnext (first aseq))))
(when (next aseq)
(print ", ")
(pp/pprint-newline :linear)
(recur (next aseq)))))))
(defmethod pp/simple-dispatch :map [amap]
(if (record? amap)
(pprint-record amap)
(pprint-map amap)))
(defmethod cljs.test/report [:cljs.test/default :fail]
[{:keys [type expected actual diffs message] :as event}]
(inc-report-counter! :fail)
(println "\nFAIL in" (testing-vars-str event))
(when (:testing-contexts (get-current-env)) (println (testing-contexts-str)))
(when message (println message))
(binding [*out* (pp/get-pretty-writer *out*)]
(let [print-expected (fn [actual]
(print "expected: ")
(pp/pprint expected)
(print " actual: ")
(pp/pprint actual))]
(if (seq diffs)
(doseq [[actual [a b]] diffs]
(print-expected actual)
(print " diff:")
(if a
(do (print " - ")
(pp/pprint a)
(print " + "))
(print " + "))
(when b
(pp/pprint b)))
(print-expected actual)))))
(defn ^:export run []
(run-all-tests #"pjstadig.*-test"))