diff --git a/spec/edu/unc/applab/clem/db/exception_spec.clj b/spec/edu/unc/applab/clem/db/exception_spec.clj index 177b096def4ac3d341494b1a897c728fef1deba4..c3e45354c4f3a179207c04d5e835c3a9ee4d3c45 100644 --- a/spec/edu/unc/applab/clem/db/exception_spec.clj +++ b/spec/edu/unc/applab/clem/db/exception_spec.clj @@ -79,6 +79,21 @@ :line 4321}] :caused-by nil}) +(def exception3 {:clojure-version "1.10.0" + :class "ClassCastException" + :message "There a casting problem in a new version." + :message-explanation nil + :timestamp 1548710228726 + :stack-trace [{:class "clojure.CCastClass" + :method "CastMethod" + :file "CastFile" + :line 15} + {:class "BClass" + :method "AMethod" + :file "BFile" + :line 4321}] + :caused-by nil}) + (describe "Saving Exceptions:" (with client (memdb/client {})) @@ -669,4 +684,28 @@ (exc/increment-occurrences! @conn excid) (should= 3 (exc/fetch-occurences (d/db @conn) excid))))) +(describe "Fetch all Clojure versions" + + (with client (memdb/client {})) + + (with conn (d/create-database @client {:db-name "exc"}) + (let [conn (d/connect @client {:db-name "exc"})] + (schema/install-schema! conn) + conn)) + + (after (memdb/close @client)) + + (it "returns all versions" + (exc/save! @conn exception) + (exc/save! @conn exception3) + (should== ["1.10.0" "1.9.0"] (exc/fetch-clojure-versions (d/db @conn)))) + + (it "returns empty with no exceptions" + (should= [] (exc/fetch-clojure-versions (d/db @conn)))) + + (it "returns only one copy of a version, even if multiple instances exist in the db" + (exc/save! @conn exception) + (exc/save! @conn exception2) + (should= ["1.9.0"] (exc/fetch-clojure-versions (d/db @conn))))) + (run-specs) diff --git a/src/edu/unc/applab/clem/db/exception.clj b/src/edu/unc/applab/clem/db/exception.clj index 99797e91a019136579523c9f745fdc43074ffd15..d63b244c3ee7d32b2bedbe8224e7afea5a6645d4 100644 --- a/src/edu/unc/applab/clem/db/exception.clj +++ b/src/edu/unc/applab/clem/db/exception.clj @@ -314,3 +314,12 @@ (catch java.lang.IllegalStateException e (increment-occurrences! conn eid))))) + +(defn fetch-clojure-versions + "Returns all clojure versions used by exceptions in the database." + [db] + (map first + (d/q + '[:find ?v + :where [_ :clojure/version ?v]] + db)))