Skip to content

Commit

Permalink
Instrumented more functions and added more spec errors to the error d…
Browse files Browse the repository at this point in the history
…ictionary. Refactored the length checking function to be a hashmap in dictionaries. Added a test for map.
  • Loading branch information
EthanUphoff committed Aug 23, 2018
1 parent c5053d7 commit 964c367
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 30 deletions.
14 changes: 14 additions & 0 deletions src/corefns/instrumentfunctionsfortesting.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@
(stest/instrument `sql/metadata-query)
(stest/instrument `sql/metadata-result)
(stest/instrument `sql/with-db-metadata)
(stest/instrument `sql/with-db-connection)
(stest/instrument `sql/with-db-transaction)
(stest/instrument `sql/db-transaction*)
(stest/instrument `sql/get-isolation-level)
(stest/instrument `sql/db-is-rollback-only)
(stest/instrument `sql/db-unset-rollback-only!)
(stest/instrument `sql/db-set-rollback-only!)
(stest/instrument `sql/db-connection)
(stest/instrument `sql/db-find-connection)
(stest/instrument `sql/prepare-statement)
(stest/instrument `sql/result-set-seq)
(stest/instrument `sql/get-connection)
(stest/instrument `sql/quoted)
(stest/instrument `sql/as-sql-name)
56 changes: 26 additions & 30 deletions src/errors/dictionaries.clj
Original file line number Diff line number Diff line change
Expand Up @@ -204,36 +204,32 @@
the correct response."
[failedvals failedlength]
(if (not= "nil" failedvals)
(let [x (count (read-string failedvals))]
(cond
(= failedlength "b-length-one") (if (> x 1)
(str (number-word (str x)) " arguments")
(str "no arguments"))
(= failedlength "b-length-two") (if (> x 2)
(str (number-word (str x)) " arguments")
(str "one argument"))
(= failedlength "b-length-three") (if (> x 3)
(str (number-word (str x)) " arguments")
(if (= x 1)
(str "one argument")
(str (number-word (str x)) " arguments")))
(= failedlength "b-length-greater-zero") (str "no arguments")
(= failedlength "b-length-greater-one") (if (= x 1)
(str "one argument")
(str "no arguments"))
(= failedlength "b-length-greater-two") (if (= x 2)
(str "two arguments")
(if (= x 1)
(str "one argument")
(str "no arguments")))
(= failedlength "b-length-zero-or-one") (str (number-word (str x)) " arguments")
(= failedlength "b-length-two-or-three") (if (> x 3)
(str (number-word (str x)) " arguments")
(if (= x 1)
(str "one argument")
(str "no arguments")))
(= failedlength "b-length-zero-to-three") (str (number-word (str x)) " arguments")
:else failedlength))
(let [x (count (read-string failedvals))
y (keyword failedlength)
z ({:b-length-one (if (> x 1)
(str (number-word (str x)) " arguments")
"no arguments")
:b-length-two (if (> x 2)
(str (number-word (str x)) " arguments")
"one argument")
:b-length-three (if (= x 1)
"one argument"
(str (number-word (str x)) " arguments"))
:b-length-greater-zero "no arguments"
:b-length-greater-one (if (= x 1)
"one argument"
"no arguments")
:b-length-greater-two (if (= x 1)
"one argument"
"two arguments")
:b-length-zero-or-one (str (number-word (str x)) " arguments")
:b-length-two-or-three (if (= x 1)
"one argument"
(str (number-word (str x)) " arguments"))
:b-length-zero-to-three (str (number-word (str x)) " arguments")} y)]
(if (nil? z)
failedlength
z))
"no arguments"))

(defn ?-name
Expand Down
24 changes: 24 additions & 0 deletions src/errors/error_dictionary.clj
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,30 @@
print-val :arg
" instead.\n")))}

{:key :exception-info-other-spec-map-predicate
:class "ExceptionInfo"
:match (beginandend "Call to (.*)/(.*) did not conform to spec:\\nIn: \\[(.*)\\] val: (.*) fails spec: (.*) at: \\[:args (:\\S*\\s)*\\:(\\S*)\\] predicate: \\((.*)\\)(\\s+)")
:make-msg-info-obj (fn [matches]
(let [[print-type print-val] (type-and-val (nth matches 4))]
(make-msg-info-hashes "In function " (nth matches 2) :arg
", the " (arg-str (subs (nth matches 3) 0 1)) :arg
" is expected to be a " (?-name (nth matches 7)) :type
", but is " print-type :type
print-val :arg
" instead.\n")))}

{:key :exception-info-other-spec-no-pound
:class "ExceptionInfo"
:match (beginandend "Call to (.*)/(.*) did not conform to spec:\\nIn: \\[(.*)\\] val: (.*) fails spec: (.*) at: \\[:args (:\\S*\\s)*\\:(\\S*)\\] predicate: (.*)(\\s+)\\#")
:make-msg-info-obj (fn [matches]
(let [[print-type print-val] (type-and-val (nth matches 4))]
(make-msg-info-hashes "In function " (nth matches 2) :arg
", the " (arg-str (subs (nth matches 3) 0 1)) :arg
" is expected to be a " (?-name (nth matches 7)) :type
", but is " print-type :type
print-val :arg
" instead.\n")))}



;#############################
Expand Down
1 change: 1 addition & 0 deletions test/babel/error_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
(expect "In function map, the second argument is expected to be a collection, but is a number 3 instead.\n" (get-error "(map even? 3)"))
(expect "In function map, the 6th argument is expected to be a collection, but is a number 3 instead.\n" (get-error "(map even? [3] [3] [3] [3] 3)"))
(expect "In function map, the first argument is expected to be a function, but is a number 3 instead.\n" (get-error "(map 3 [3])"))
(expect "In function map, the first argument is expected to be a function, but is a number 3 instead.\n" (get-error "(map 3 3)"))
(expect "In function denominator, the first argument is expected to be a ratio, but is a number 3 instead.\n" (get-error "(denominator 3)"))
(expect "In function numerator, the first argument is expected to be a ratio, but is a number 3 instead.\n" (get-error "(numerator 3)"))
(expect "In function map, the second argument is expected to be a collection, but is a regular expression pattern #\"h\" instead.\n" (get-error "(map [3 2 3 4 5] #\"h\")"))
Expand Down

0 comments on commit 964c367

Please sign in to comment.