From abc888a195a14a60b822f07569c789bda5317b57 Mon Sep 17 00:00:00 2001 From: Rick Moynihan Date: Fri, 12 Feb 2021 14:25:30 +0000 Subject: [PATCH 1/2] Fix #40 some non validation errors error when printing the error --- src/rdf_validator/core.clj | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/rdf_validator/core.clj b/src/rdf_validator/core.clj index 2060f50..b8cb92b 100644 --- a/src/rdf_validator/core.clj +++ b/src/rdf_validator/core.clj @@ -71,21 +71,23 @@ :errors (mapv str 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)) From 65af791f7b3a16f78eb6a23333a3aedb8fdabf75 Mon Sep 17 00:00:00 2001 From: Rick Moynihan Date: Fri, 12 Feb 2021 14:26:34 +0000 Subject: [PATCH 2/2] Improve console error reporter slightly Pretty print a table of error results if we can. --- src/rdf_validator/core.clj | 2 +- src/rdf_validator/reporting.clj | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/rdf_validator/core.clj b/src/rdf_validator/core.clj index b8cb92b..cd1c442 100644 --- a/src/rdf_validator/core.clj +++ b/src/rdf_validator/core.clj @@ -68,7 +68,7 @@ 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] (let [source (:source test-case)] diff --git a/src/rdf_validator/reporting.clj b/src/rdf_validator/reporting.clj index b1465f2..ed1ef2e 100644 --- a/src/rdf_validator/reporting.clj +++ b/src/rdf_validator/reporting.clj @@ -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] @@ -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)))) -