Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Port to data.xml v0.2.0-alpha5 #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
key: v1-jars-

- run: lein test
- run: lein with-profile +alpha-data-xml test

- cache-save:
key: v1-jars-{{ checksum "project.clj" }}
Expand Down
2 changes: 2 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
:pedantic? :abort
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/data.xml "0.0.8"]]
:profiles {:alpha-data-xml
{:dependencies [[org.clojure/data.xml "0.2.0-alpha5"]]}}
:aliases {"test" ["run" "-m" "circleci.test/dir" :project/test-paths]
"tests" ["run" "-m" "circleci.test"]
"retest" ["run" "-m" "circleci.test.retest"]})
12 changes: 7 additions & 5 deletions src/circleci/test/report/junit.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"Junit reporter for circleci.test"
(:require [clojure.data.xml :as xml]
[clojure.java.io :as io]
[circleci.test.report :as report])
(:import clojure.data.xml.Element))
[circleci.test.report :as report]))

(defn- element? [el]
(and (map? el) (some? (:tag el))))

(defn- stacktrace->string
"given an exception, returns the result of printStackTrace as a string"
Expand Down Expand Up @@ -38,8 +40,8 @@

(defn- suite-xml
[m testcases]
{:pre [(class testcases) (every? #(instance? Element %) testcases)]}
(apply xml/element :testsuite {:name (-> m :ns (.name))
{:pre [(class testcases) (every? element? testcases)]}
(apply xml/element :testsuite {:name (-> m :ns ns-name str)
:errors (count-errors testcases)
:tests (count testcases)
:failures (count-failures testcases)
Expand All @@ -48,7 +50,7 @@

(defn- test-name
[v]
(-> v meta :name))
(-> v meta :name str))

(defn- testcase-xml
"Generate a testcase XML element. Takes the map from a (clojure.test/do-report :end-test-var), and a seq of failure/error reports "
Expand Down
43 changes: 21 additions & 22 deletions test/circleci/test/report/test_junit.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
circleci.test
circleci.test.report
[circleci.test.report.junit :as junit])
(:import clojure.data.xml.Element
java.nio.file.Files
(:import java.nio.file.Files
java.nio.file.attribute.FileAttribute))

(deftest failure-works
(is (instance? Element (#'junit/failure-xml
{:expected (= 3 (+ 1 1)),
:message nil,
:type :fail,
:actual (not (= 3 2)),
:file "test_junit.clj",
:line 8}))))
(is (#'junit/element? (#'junit/failure-xml
{:expected (= 3 (+ 1 1)),
:message nil,
:type :fail,
:actual (not (= 3 2)),
:file "test_junit.clj",
:line 8}))))

(deftest testcase-works
(let [ret (#'junit/testcase-xml {:type :end-test-var
Expand All @@ -27,23 +26,23 @@
:actual (not (= 3 2)),
:file "test_junit.clj",
:line 8}))]
(is (instance? Element ret))
(is (#'junit/element? ret))
(testing "it has a time"
(is (-> ret :attrs :time float?)))))

(deftest testsuite-works
(is (instance? Element
(#'junit/suite-xml {:ns (find-ns 'clojure.core)}
[(#'junit/testcase-xml {:type :end-test-var
:name #'clojure.core/map
:elapsed 0.03}
[(#'junit/failure-xml
{:expected (= 3 (+ 1 1)),
:message nil,
:type :fail,
:actual (not (= 3 2)),
:file "test_junit.clj",
:line 8})])]))))
(is (#'junit/element?
(#'junit/suite-xml {:ns (find-ns 'clojure.core)}
[(#'junit/testcase-xml {:type :end-test-var
:name #'clojure.core/map
:elapsed 0.03}
[(#'junit/failure-xml
{:expected (= 3 (+ 1 1)),
:message nil,
:type :fail,
:actual (not (= 3 2)),
:file "test_junit.clj",
:line 8})])]))))

(deftest junit-doesn't-break-return-code
;; `lein test` assumes tests return a map.
Expand Down