testing

fabrao 2022-01-07T00:15:56.000700Z

Hello, any one used cloverage with cognitec test-runner ?

seancorfield 2022-01-07T00:42:55.001200Z

@fabrao You don't use it with test-runner. Cloverage is a test runner itself.

fabrao 2022-01-07T00:43:40.002300Z

why some tests fail in cloverage but in test-runner don´t?

seancorfield 2022-01-07T00:43:41.002400Z

We have a wrapper for it, called from our build.clj script:

(defn coverage
  "Invoked via exec-fn (-X). Accepts all the same options that Cloverage's
  `run-project` function accepts (and passes them through).

  Looks for all `src` and `test` paths on the classpath. For any `/test`
  path, assume there's an equivalent `/src` path because we tend to bring
  in source dependencies via `:local/root` as a project but we bring in
  test dependencies via `:extra-paths`. Pass the final set of source and
  test paths into Cloverage and let it run all the tests it can find."
  [{:keys [src-ns-path test-ns-path] :as options}]
  (let [paths   (when-not (and src-ns-path test-ns-path)
                  (into #{}
                        (comp (remove #(str/starts-with? % "/"))
                              (mapcat #(vector % (str/replace % #"/test$" "/src"))))
                        (str/split (System/getProperty "java.class.path") #":")))
        sources (or src-ns-path
                    (filter #(str/ends-with? % "/src")  paths))
        tests   (or test-ns-path
                    (filter #(str/ends-with? % "/test") paths))]
    ((requiring-resolve 'cloverage.coverage/run-project)
     (assoc options :src-ns-path sources :test-ns-path tests))))

fabrao 2022-01-07T00:44:45.002900Z

I run this

clojure -M:test:runner --exclude :integration

... 
with
:runner
  {:extra-deps {com.cognitect/test-runner
                {:git/url ""
                 :sha     "b6b3193fcc42659d7e46ecd1884a228993441182"}}
   :main-opts  ["-m" "cognitect.test-runner"
                "-d" "test"]}

seancorfield 2022-01-07T00:47:53.003900Z

As I recall, the way Cloverage instruments your code causes it to lose type hints which can definitely cause some code to fail.

fabrao 2022-01-07T00:47:57.004100Z

may be something in integration ?

fabrao 2022-01-07T00:48:43.004600Z

is there any ideas for considering this hints?

seancorfield 2022-01-07T00:49:20.005300Z

Yeah, if you're excluding some tests with test-runner and it passes, I expect cloverage is running those tests...

fabrao 2022-01-07T00:50:47.006200Z

so, do I have to manually excludes this (deftest ^:integration...)?

seancorfield 2022-01-07T00:51:51.007500Z

How are you running Cloverage? Check its docs and see if it has options to exclude tests (although that kind of flies in the face of calculating coverage since you'll have gaps in your tests that way).

fabrao 2022-01-07T00:53:20.008200Z

I´m using this

:cloverage
  {:extra-paths ["test"]
   :extra-deps {cloverage/cloverage {:mvn/version "1.2.2"}
                babashka/process {:mvn/version "0.0.2"}
                spec-provider/spec-provider {:mvn/version "0.4.14"}}
   :main-opts ["-m" "cloverage.coverage"
               "--no-html"
               "-p" "src"
               "-s" "test"
               "-t" "^(?!.*?(?:integration)).*$"
               "--fail-threshold" "90"]}
I think the -t parameter is not the way to do this

seancorfield 2022-01-07T00:54:16.008800Z

No idea. My experience of Cloverage is that it's pretty flaky if you have complex code.

seancorfield 2022-01-07T00:55:18.009400Z

It's been a while since I ran it on our code but I know some of our tests fail with Cloverage but pass with test-runner...

fabrao 2022-01-07T00:57:19.009600Z

thank you

fabrao 2022-01-07T00:57:46.010300Z

I think I´m going try to exclude the tests manually

seancorfield 2022-01-07T00:58:50.011600Z

I'm running it now to see if I can figure out a pattern in what fails. But because of the instrumentation, we can't run it on our entire codebase in one go so I have to run it on chunks of subprojects which takes a while and it's a bit manual.

seancorfield 2022-01-07T01:00:15.012900Z

Ah, I can't run it on some subprojects now because we're using :as-alias from Clojure 1.11 and clojure.tools.namespace (which Cloverage uses) doesn't support that properly yet:

clojure.lang.ExceptionInfo: Circular dependency between ws.profile.field and ws.domain.member.validation {:reason :clojure.tools.namespace.dependency/circular-dependency, :node ws.profile.field, :dependency ws.domain.member.validation}
(there is no circular dependency -- c.t.n.dependency is "broken" regarding :as-alias)

fabrao 2022-01-07T01:04:47.014300Z

in my case, will be difficult because all the regex stuffs are only for namespaces, maybe using your wrapper for build will be possible if we can filter functions with metadata.

seancorfield 2022-01-07T01:30:16.017Z

@fabrao If it helps, I've just found one of our subprojects that breaks horribly under Cloverage and it seems to be related to multi-methods...

#error {
 :cause "No method in multimethod 'clear-redis' for dispatch value: class ws.redis.jedis_pool$pooled_jedis_object$reify__34674"
 :via
 [{:type java.lang.IllegalArgumentException
   :message "No method in multimethod 'clear-redis' for dispatch value: class ws.redis.jedis_pool$pooled_jedis_object$reify__34674"
   :at [clojure.lang.MultiFn getFn "MultiFn.java" 156]}]
 :trace
 [[clojure.lang.MultiFn getFn "MultiFn.java" 156]
  [clojure.lang.MultiFn invoke "MultiFn.java" 229]
  [ws.redis_expectations$new_test_redis invokeStatic "redis_expectations.clj" 43]
  [ws.redis_expectations$new_test_redis invoke "redis_expectations.clj" 42]
So the instrumentation is breaking that code.

seancorfield 2022-01-07T01:30:49.018Z

(but you should share details of what fails under Cloverage with your tests so folks can offer more specific feedback)

vemv 2022-01-07T01:32:46.019800Z

@fabrao cloverage has a variety of open issues unfortunately, so in practice it's apt for some projects, and for others it isn't The larger your project is and the more techniques it uses, the more likely it is that it hits some funny edge case. My recommendation (having used cloverage the last few years) would be to consider it an 'informative' step in the CI pipeline; it's no replacement for a more standard test runner.

seancorfield 2022-01-07T01:36:46.020100Z

Yup, definitely that point_up::skin-tone-2

seancorfield 2022-01-07T01:38:07.021Z

(and I consider coverage information to be "interesting" rather than "useful" -- and any goals of percentage coverage for "all" code to be... misguided)

vemv 2022-01-07T01:46:52.025100Z

In all honesty, last time I gave real use to coverage metrics was in my Ruby days. Especially in 'rescue' projects with absent test suites. These clojurey days any email from Coveralls or such will be graciously deleted by a gmail filter :) OTOH I tend to be pretty strict self-reviewing my code, before each commit and after creating every PR. This includes a coverage assessment. So I do see value in ensuring team-wide standards, but at a personal productivity level coverage tooling is irrelevant.

fabrao 2022-01-07T02:23:38.027400Z

our code fails only in this kind of test (deftest ^:integration...) . I´m thinking use like sean said, in build-clj process, adding filtering tests without ^:integration.

fabrao 2022-01-07T02:24:24.027900Z

maybe it can be an issue for cloverage later

seancorfield 2022-01-07T02:28:48.028400Z

@fabrao What sort of failures? Just test failures, or exceptions?

fabrao 2022-01-07T02:29:16.028700Z

testing failures

fabrao 2022-01-07T02:30:35.029900Z

integration will check some testing that will always fail in test enviroment

fabrao 2022-01-07T02:31:12.030300Z

integration tests will be in another task