Skip to content

Commit

Permalink
Bump lazytest, move metrics tests to lazytest
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed Jun 26, 2024
1 parent 9914b92 commit 25d0561
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 130 deletions.
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
nubank/matcher-combinators {:mvn/version "3.8.5"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1"
:git/sha "dfb30dd"}
io.github.noahtheduke/lazytest {:mvn/version "0.2.0"}}}
io.github.noahtheduke/lazytest {:mvn/version "0.2.1"}}}
:runner {:main-opts ["-m" "noahtheduke.splint.utils.test-runner"]}
:profile {:extra-deps {com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.0.3"}
com.clojure-goes-fast/clj-memory-meter {:mvn/version "0.3.0"}}
Expand Down
4 changes: 3 additions & 1 deletion tasks/new_rule_test.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

(set! *warn-on-reflection* true)

(defn config [] (single-rule-config '{{genre}}/{{rule-name}}))
(defn config [& [style]]
(cond-> (single-rule-config '{{genre}}/{{rule-name}})
style (update '{{genre}}/{{rule-name}} merge style)))

(defdescribe {{rule-name}}-test
(expect-match
Expand Down
147 changes: 75 additions & 72 deletions test/noahtheduke/splint/rules/metrics/fn_length_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,84 @@

(ns noahtheduke.splint.rules.metrics.fn-length-test
(:require
[expectations.clojure.test :refer [defexpect]]
[noahtheduke.splint.test-helpers :refer [expect-match]]))
[lazytest.core :refer [defdescribe describe given it]]
[noahtheduke.splint.test-helpers :refer [expect-match single-rule-config]]))

(set! *warn-on-reflection* true)

(def config
'{metrics/fn-length {:enabled true}
style/multiple-arity-order {:enabled false}})
(defn config [& [style]]
(cond-> (single-rule-config 'metrics/fn-length)
style (update 'metrics/fn-length merge style)))

(defexpect fn-length-defn-test
(let [config (assoc-in config '[metrics/fn-length :chosen-style] :defn)]
(expect-match nil "(defn n\n[]\n1 2 3)" config)
(expect-match
'[{:message "defn forms shouldn't be longer than 10 lines."}]
"(defn n\n[arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11)" config)
(expect-match
'[{:alt nil
:line 1
:column 1
:end-line 13
:end-column 4}]
"(defn n\n[arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11)" config)
(expect-match
'[{:alt nil
:line 1
:column 1
:end-line 13
:end-column 5}]
"(defn n\n([arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11))" config)
(expect-match
'[{:alt nil
:line 1
:column 1
:end-line 14
:end-column 5}]
"(defn n\n([] 1 2 3)\n([arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11))"
config)))
(defdescribe fn-length-defn-test

(defexpect fn-length-body-test
(let [config (assoc-in config '[metrics/fn-length :chosen-style] :body)]
(expect-match nil "(defn n\n[]\n1 2 3)" config)
(expect-match
'[{:message "Function bodies shouldn't be longer than 10 lines."}]
"(defn n\n[arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11)" config)
(expect-match
'[{:alt nil
:line 2
:column 1
:end-line 13
:end-column 3}]
"(defn n\n[arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11)" config)
(expect-match
'[{:alt nil
:line 2
:column 1
:end-line 13
:end-column 4}]
"(defn n\n([arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11))" config)
(expect-match
'[{:alt nil
:line 3
:column 1
:end-line 14
:end-column 4}]
"(defn n\n([] 1 2 3)\n([arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11))"
config)))
(describe "chosen style"
(given [config (config {:chosen-style :defn})]
(it :defn
(expect-match nil "(defn n\n[]\n1 2 3)" config)
(expect-match
'[{:message "defn forms shouldn't be longer than 10 lines."}]
"(defn n\n[arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11)" config)
(expect-match
'[{:alt nil
:line 1
:column 1
:end-line 13
:end-column 4}]
"(defn n\n[arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11)" config)
(expect-match
'[{:alt nil
:line 1
:column 1
:end-line 13
:end-column 5}]
"(defn n\n([arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11))" config)
(expect-match
'[{:alt nil
:line 1
:column 1
:end-line 14
:end-column 5}]
"(defn n\n([] 1 2 3)\n([arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11))"
config)))
(given [config (config {:chosen-style :body})]
(it :body
(expect-match nil "(defn n\n[]\n1 2 3)" config)
(expect-match
'[{:message "Function bodies shouldn't be longer than 10 lines."}]
"(defn n\n[arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11)" config)
(expect-match
'[{:alt nil
:line 2
:column 1
:end-line 13
:end-column 3}]
"(defn n\n[arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11)" config)
(expect-match
'[{:alt nil
:line 2
:column 1
:end-line 13
:end-column 4}]
"(defn n\n([arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11))" config)
(expect-match
'[{:alt nil
:line 3
:column 1
:end-line 14
:end-column 4}]
"(defn n\n([] 1 2 3)\n([arg1]\na\nb\nc\nd\n5\n6\n7\n8\n9\n10\n11))"
config))))

(defexpect fn-length-config-length-test
(let [config (assoc-in config '[metrics/fn-length :length] 5)]
(expect-match nil "(defn n\n[]\n0\n1\n2\n3)" config)
(expect-match
'[{:alt nil
:message "Function bodies shouldn't be longer than 5 lines."
:line 2
:column 1
:end-line 8
:end-column 2}]
"(defn n\n[]\n0\n1\n2\n3\n4\n5)" config)))
(describe "config length"
(given [config (config {:length 5})]
(it "custom length"
(expect-match nil "(defn n\n[]\n0\n1\n2\n3)" config)
(expect-match
'[{:alt nil
:message "Function bodies shouldn't be longer than 5 lines."
:line 2
:column 1
:end-line 8
:end-column 2}]
"(defn n\n[]\n0\n1\n2\n3\n4\n5)" config)))))
115 changes: 59 additions & 56 deletions test/noahtheduke/splint/rules/metrics/parameter_count_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,69 @@

(ns noahtheduke.splint.rules.metrics.parameter-count-test
(:require
[expectations.clojure.test :refer [defexpect]]
[noahtheduke.splint.test-helpers :refer [expect-match]]))
[lazytest.core :refer [defdescribe describe it]]
[noahtheduke.splint.test-helpers :refer [expect-match single-rule-config]]))

(set! *warn-on-reflection* true)

(defexpect parameter-count-test
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d e]
:message "Avoid parameter lists with more than 4 parameters."
:alt nil}]
"(defn example ([a b c d]) ([a b c d e]))"
'{metrics/parameter-count {:enabled true}}))
(defn config [& [style]]
(cond-> (single-rule-config 'metrics/parameter-count)
style (update 'metrics/parameter-count merge style)))

(defexpect parameter-count-multiple-arglists-test
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d e f]
:message "Avoid parameter lists with more than 4 parameters."
:line 1
:column 30
:end-line 1
:end-column 43}
{:rule-name 'metrics/parameter-count
:form '[a b c d e]
:message "Avoid parameter lists with more than 4 parameters."
:line 1
:column 16
:end-line 1
:end-column 27}]
"(defn example ([a b c d e]) ([a b c d e f]))"
'{metrics/parameter-count {:enabled true}}))
(defdescribe parameter-count-test
(it "defaults to 4"
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d e]
:message "Avoid parameter lists with more than 4 parameters."
:alt nil}]
"(defn example ([a b c d]) ([a b c d e]))"
'{metrics/parameter-count {:enabled true}}))

(defexpect parameter-count-config-count-test
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d e f]
:message "Avoid parameter lists with more than 5 parameters."
:line 1
:column 30
:end-line 1
:end-column 43}]
"(defn example ([a b c d e]) ([a b c d e f]))"
'{metrics/parameter-count {:enabled true
:count 5}}))
(it "works with multiple arglists"
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d e f]
:message "Avoid parameter lists with more than 4 parameters."
:line 1
:column 30
:end-line 1
:end-column 43}
{:rule-name 'metrics/parameter-count
:form '[a b c d e]
:message "Avoid parameter lists with more than 4 parameters."
:line 1
:column 16
:end-line 1
:end-column 27}]
"(defn example ([a b c d e]) ([a b c d e f]))"
'{metrics/parameter-count {:enabled true}}))

(defexpect parameter-count-config-style-positional-test
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d e & args]
:message "Avoid parameter lists with more than 4 parameters."}]
"(defn example ([a b c d]) ([a b c d e & args]))"
'{metrics/parameter-count {:enabled true
:chosen-style :positional}}))
(describe "chosen styles"
(it "custom count"
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d e f]
:message "Avoid parameter lists with more than 5 parameters."
:line 1
:column 30
:end-line 1
:end-column 43}]
"(defn example ([a b c d e]) ([a b c d e f]))"
(config {:count 5})))

(defexpect parameter-count-config-style-include-rest-test
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d & args]
:message "Avoid parameter lists with more than 4 parameters (including & rest parameters)."}]
"(defn example ([a b c d]) ([a b c d & args]))"
'{metrics/parameter-count {:enabled true
:chosen-style :include-rest}}))
(it :positional
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d e & args]
:message "Avoid parameter lists with more than 4 parameters."}]
"(defn example ([a b c d]) ([a b c d e & args]))"
(config {:chosen-style :positional})))

(it :include-rest
(expect-match
[{:rule-name 'metrics/parameter-count
:form '[a b c d & args]
:message "Avoid parameter lists with more than 4 parameters (including & rest parameters)."}]
"(defn example ([a b c d]) ([a b c d & args]))"
(config {:chosen-style :include-rest})))))

0 comments on commit 25d0561

Please sign in to comment.