Skip to content

Commit

Permalink
Merge pull request #41 from Swirrl/error-reporting-improvements
Browse files Browse the repository at this point in the history
Error reporting improvements
  • Loading branch information
RickMoynihan authored Feb 12, 2021
2 parents c62546f + 65af791 commit 5ecc5fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
34 changes: 18 additions & 16 deletions src/rdf_validator/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,26 @@
failed (pos? (count results))]
{:test-source test-source
:result (if failed :failed :passed)
:errors (mapv str results)})))
:errors results})))

(defn run-test-case [test-case query-variables endpoint]
(try
(let [source (:source test-case)
^String sparql-str (load-sparql-template source query-variables)
query (QueryFactory/create sparql-str Syntax/syntaxSPARQL_11)
test {:test-source source :query-string sparql-str}]
(cond
(.isAskType query) (run-sparql-ask-test test endpoint)
(.isSelectType query) (run-sparql-select-test test endpoint)
:else {:test-case test-case
:result :ignored
:errors []}))
(catch Exception ex
{:test-case test-case
:result :errored
:errors [(.getMessage ex)]})))
(let [source (:source test-case)]
(try
(let [^String sparql-str (load-sparql-template source query-variables)
query (QueryFactory/create sparql-str Syntax/syntaxSPARQL_11)
test {:test-source source :query-string sparql-str}]
(cond
(.isAskType query) (run-sparql-ask-test test endpoint)
(.isSelectType query) (run-sparql-select-test test endpoint)
:else {:test-source source
:test-case test-case
:result :ignored
:errors []}))
(catch Exception ex
{:test-source source
:test-case test-case
:result :errored
:errors [(.getMessage ex)]}))))

(defn run-test-cases [test-cases query-variables endpoint]
(map #(run-test-case % query-variables endpoint) test-cases))
Expand Down
11 changes: 7 additions & 4 deletions src/rdf_validator/reporting.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns rdf-validator.reporting
"Used for creating reports of test executions."
(:require [clojure.string :as string]
[rdf-validator.util :as util]))
[rdf-validator.util :as util]
[clojure.pprint :as pp]))

(defprotocol TestReporter
(report-test-result! [this test-result]
Expand All @@ -13,12 +14,14 @@
TestReporter
(report-test-result! [_this {:keys [number test-source result errors] :as test-result}]
(println (format "%d %s: %s" number (util/get-path test-source) (string/upper-case (name result))))
(doseq [error errors]
(println (format "\t%s" error)))
(when (seq errors)
(if (map? (first errors))
(pp/print-table errors)
(doseq [error errors]
(println (format "\t%s" error)))))
(when (pos? (count errors))
(println)))

(report-test-summary! [_this {:keys [passed failed errored ignored] :as test-summary}]
(println)
(println (format "Passed %d Failed %d Errored %d Ignored %d" passed failed errored ignored))))

0 comments on commit 5ecc5fa

Please sign in to comment.