Fork me on GitHub
#testing
<
2023-11-16
>
gleisonsilva20:11:05

Hello! May you can help me... I'm not succeding in using #kaocha for testing... when I call bin/kaocha --version, for exemplo, it gives me a compilation error... Here's the complete error report:

{:clojure.main/message
 "Syntax error (ArityException) compiling at (kaocha/version_check.clj:1:1).\nWrong number of args (3) passed to: clojure.spec.alpha/amp-impl\n",
 :clojure.main/triage
 {:clojure.error/phase :compile-syntax-check,
  :clojure.error/line 1,
  :clojure.error/column 1,
  :clojure.error/source "version_check.clj",
  :clojure.error/path "kaocha/version_check.clj",
  :clojure.error/class clojure.lang.ArityException,
  :clojure.error/cause
  "Wrong number of args (3) passed to: clojure.spec.alpha/amp-impl"},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.Compiler$CompilerException,
    :message
    "Syntax error compiling at (kaocha/version_check.clj:1:1).",
    :data
    {:clojure.error/phase :compile-syntax-check,
     :clojure.error/line 1,
     :clojure.error/column 1,
     :clojure.error/source "kaocha/version_check.clj"},
    :at [clojure.lang.Compiler load "Compiler.java" 7648]}
   {:type java.lang.ExceptionInInitializerError,
    :at [java.lang.Class forName0 "Class.java" -2]}
   {:type clojure.lang.ArityException,
    :message
    "Wrong number of args (3) passed to: clojure.spec.alpha/amp-impl",
    :at [clojure.lang.AFn throwArity "AFn.java" 429]}],
  :trace
  [[clojure.lang.AFn throwArity "AFn.java" 429]
   [clojure.lang.AFn invoke "AFn.java" 40]
   [clojure.core.specs.alpha$fn__59 invokeStatic "alpha.clj" 107]
   [clojure.core.specs.alpha$fn__59 invoke "alpha.clj" 107]
   [clojure.core.specs.alpha__init load nil 107]
   [clojure.core.specs.alpha__init <clinit> nil -1]
   [java.lang.Class forName0 "Class.java" -2]
   [java.lang.Class forName "Class.java" 348]
   [clojure.lang.RT classForName "RT.java" 2211]
   [clojure.lang.RT classForName "RT.java" 2220]
   [clojure.lang.RT loadClassForName "RT.java" 2239]
   [clojure.lang.RT load "RT.java" 449]
   [clojure.lang.RT load "RT.java" 424]
   [clojure.lang.Compiler ensureMacroCheck "Compiler.java" 6958]
   [clojure.lang.Compiler checkSpecs "Compiler.java" 6970]
   [clojure.lang.Compiler macroexpand1 "Compiler.java" 6988]
   [clojure.lang.Compiler macroexpand "Compiler.java" 7075]
   [clojure.lang.Compiler eval "Compiler.java" 7161]
   [clojure.lang.Compiler load "Compiler.java" 7636]
   [clojure.lang.RT loadResourceScript "RT.java" 381]
   [clojure.lang.RT loadResourceScript "RT.java" 372]
   [clojure.lang.RT load "RT.java" 459]
   [clojure.lang.RT load "RT.java" 424]
   [clojure.core$load$fn__6839 invoke "core.clj" 6126]
   [clojure.core$load invokeStatic "core.clj" 6125]
   [clojure.core$load doInvoke "core.clj" 6109]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [clojure.core$load_one invokeStatic "core.clj" 5908]
   [clojure.core$load_one invoke "core.clj" 5903]
   [clojure.core$load_lib$fn__6780 invoke "core.clj" 5948]
   [clojure.core$load_lib invokeStatic "core.clj" 5947]
   [clojure.core$load_lib doInvoke "core.clj" 5928]
   [clojure.lang.RestFn applyTo "RestFn.java" 142]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.core$load_libs invokeStatic "core.clj" 5985]
   [clojure.core$load_libs doInvoke "core.clj" 5969]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.core$require invokeStatic "core.clj" 6007]
   [clojure.core$require doInvoke "core.clj" 6007]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [user$eval1 invokeStatic "runner.clj" 1]
   [user$eval1 invoke "runner.clj" 1]
   [clojure.lang.Compiler eval "Compiler.java" 7177]
   [clojure.lang.Compiler load "Compiler.java" 7636]
   [clojure.lang.RT loadResourceScript "RT.java" 381]
   [clojure.lang.RT loadResourceScript "RT.java" 372]
   [clojure.lang.RT load "RT.java" 459]
   [clojure.lang.RT load "RT.java" 424]
   [clojure.core$load$fn__6839 invoke "core.clj" 6126]
   [clojure.core$load invokeStatic "core.clj" 6125]
   [clojure.core$load doInvoke "core.clj" 6109]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [clojure.core$load_one invokeStatic "core.clj" 5908]
   [clojure.core$load_one invoke "core.clj" 5903]
   [clojure.core$load_lib$fn__6780 invoke "core.clj" 5948]
   [clojure.core$load_lib invokeStatic "core.clj" 5947]
   [clojure.core$load_lib doInvoke "core.clj" 5928]
   [clojure.lang.RestFn applyTo "RestFn.java" 142]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.core$load_libs invokeStatic "core.clj" 5985]
   [clojure.core$load_libs doInvoke "core.clj" 5969]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.core$require invokeStatic "core.clj" 6007]
   [clojure.main$main_opt invokeStatic "main.clj" 514]
   [clojure.main$main_opt invoke "main.clj" 510]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause
  "Wrong number of args (3) passed to: clojure.spec.alpha/amp-impl",
  :phase :compile-syntax-check}}

seancorfield20:11:15

Is your own code using Slingshot perhaps, and bringing in an older version than Kaocha needs?

gleisonsilva20:11:55

Slingshot? Sorry... what that should be?

seancorfield20:11:26

You're probably going to need to share your deps.edn file and you may do better getting help directly in the #CCY2V0U6A channel (I don't use Kaocha so I'm speculating based on that stacktrace and what the kaocha.version-check namespace contains).

gleisonsilva20:11:10

This is how my deps.end looks like

{:deps    {org.clojure/clojure {:mvn/version "1.10.1"}

           ;; DATABASE ACCESS
           org.clojure/java.jdbc {:mvn/version "0.6.1"}

           org.clojure/data.json {:mvn/version "2.1.1"}
           javax.servlet/servlet-api {:mvn/version "2.5"}
           org.flatland/ordered {:mvn/version "1.15.10"}

           ;; LOGGING
           com.taoensso/timbre {:mvn/version "4.10.0"}
           org.slf4j/slf4j-api {:mvn/version "1.7.14"}
           com.fzakaria/slf4j-timbre {:mvn/version "0.3.13"}
           org.slf4j/log4j-over-slf4j {:mvn/version "1.7.14"}
           org.slf4j/jul-to-slf4j {:mvn/version "1.7.14"}
           org.slf4j/jcl-over-slf4j {:mvn/version "1.7.14"}

           }

 :paths   ["src" "classes" "resources"]

 :aliases {:test
           {:extra-paths ["test"]
            :extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"}
                         com.h2database/h2 {:mvn/version  "1.3.148"}
                         org.postgresql/postgresql {:mvn/version "42.2.20"}
                         expectations/expectations {:mvn/version "2.2.0-rc3"}
                         org.eclipse.jetty/jetty-servlet-tester {:mvn/version "7.0.0.M2"}}
            :main-opts ["-m" "kaocha.runner" #_"--watch" #_"--no-capture-output" "--fail-fast"]}
		   }
 }
```

seancorfield20:11:47

I don't see anything wrong with that (tried it locally -- only Kaocha brings in Slingshot and it brings in the latest version). What's in your Kaocha config file?

seancorfield21:11:31

And you're running this with clojure -M:test ?

gleisonsilva21:11:26

kind of... I've follow the install instruction on kaocha site and have created a bin/kaocha with this:

#!/usr/bin/env bash

clojure -M:test "$@"

seancorfield21:11:54

When I run that, using your deps.edn, I get warnings:

WARNING: Did not load a configuration file and using the defaults.
This is fine for experimenting, but for long-term use, we recommend creating a configuration file to avoid changes in behavior between releases.
To create a configuration file using the current defaults and configuration file location, create a file named tests.edn that contains '#kaocha/v1 {}'.
Do you get that? Or does it fail prior to that?

gleisonsilva21:11:19

sorry... I have a tests.edn indeed.

seancorfield21:11:29

And what does clojure -version print out?

gleisonsilva21:11:33

#kaocha/v1
 {:plugins [:hooks]
  :kaocha.hooks/pre-load [docx.hooks/pre-load-hook]}

gleisonsilva21:11:43

clojure -version Clojure CLI version 1.11.1.1347

seancorfield21:11:34

OK, good. And docx.hooks/pre-load-hook is in your own code?

gleisonsilva21:11:31

(ns docx.hooks
  (:require [ :as io]))

(defn pre-load-hook [test-plan]
  (compile 'docx.core)
  (compile 'docx.servlet)
  test-plan)

gleisonsilva21:11:40

^ it's this simple

seancorfield21:11:38

And that's under your test tree?

seancorfield21:11:47

OK, so run this command to get an interactive REPL:

clj -Sdeps '{:aliases {:repl {:main-opts ["-r"]}}}' -M:test:repl
and then do
(require 'docx.hooks)
(docx.hooks/pre-load-hook nil)
This should validate that you can load the test dependencies and run that hook. To eliminate any of that code as a problem.

seancorfield21:11:23

(that alias/repl trick is a way to override the :main-opts in your :test alias so you can get a REPL with test stuff loaded)

gleisonsilva21:11:42

It gives an error:

seancorfield21:11:11

OK, so you probably have an error in one of your files, and because it's a compile error when Kaocha tries to load your code, the stacktrace is misleading.

seancorfield21:11:18

So start a fresh REPL like you did above and try to (require 'docx.core) and then (require 'docx.servlet) to see if that helps narrow down where your syntax error is.

seancorfield21:11:43

(unless all your code is up on GH or somewhere I can just go look at it and see if I can spot the problem)

seancorfield21:11:22

It may be easier to use your editor and just try loading each file into the REPL and see what errors you get...

gleisonsilva21:11:16

what i can't understand is that this very base code can compile and generate a .jar file that can be run with success...

gleisonsilva22:11:51

😉 it was a comment (;) inside the (ns ... )

gleisonsilva22:11:00

thank you very much for the tips

seancorfield22:11:31

Happy to help! Glad you figured it out 🙂

seancorfield22:11:32

Remember that your test code does not get compiled or loaded when you make a JAR -- I assume the ns error was in a test file somewhere?

gleisonsilva22:11:05

it was both in both places

gleisonsilva22:11:26

😞 i was wrong

gleisonsilva22:11:30

it didn't work

gleisonsilva22:11:33

the first time I do a require, it dont work, but if I call require again, it works.

seancorfield22:11:29

That's why I said you needed a fresh REPL for the test...

seancorfield22:11:28

So if docx.core won't load, start a new REPL and try to require each of the nses it requires in its ns. Repeat recursively until you find the culprit.

seancorfield22:11:59

The "Syntax error .. at (.. :1:1)" suggests it's something in an ns form somewhere in your code.

seancorfield22:11:25

(if this was up on GitHub, I could take a look and probably find it faster)

gleisonsilva22:11:24

I'm cutting piece by piece to find out...

gleisonsilva22:11:43

to running test, do I need do first compile the classes?

gleisonsilva22:11:59

i mean... I do need to add a 'compile' step before calling the tests?

gleisonsilva23:11:30

I'm getting errors like that: clj -X:test Running tests in #{"test"} Syntax error (ClassNotFoundException) compiling at (docx/servlet_test.clj:20:20). docx.servlet

gleisonsilva23:11:19

(i've dumped the kaocha and now using just the regular clojure test runner... then I'm getting those error about having not compile the classes)

seancorfield23:11:54

Do what I suggested above: start a REPL from the command-line and just try to require a namespace.

seancorfield23:11:18

You need to do little tiny steps in the REPL.

seancorfield23:11:39

Until you've figured out what is causing the syntax error, there's no point in trying to run the tests at all.

gleisonsilva23:11:44

from repl it's working

gleisonsilva23:11:52

there's no syntax error

seancorfield23:11:13

37 minutes ago, you said there was still.

seancorfield23:11:35

Fresh REPL. One require. It failed.

gleisonsilva23:11:41

yeah... but that i could figure out

gleisonsilva23:11:10

the only thing now is this code:

gleisonsilva23:11:34

and it need the class docx.servlet

gleisonsilva23:11:43

but it can't find this class

seancorfield23:11:57

Why did you switch away from Kaocha and the pre load hook?

gleisonsilva23:11:59

so I'm thinking that I will need to compile that in some way

seancorfield23:11:21

That hook was what was compiling the classes you need.

gleisonsilva23:11:33

because I couldn't find out any useful messages when using it

gleisonsilva23:11:13

with the clojure test runner, there's some "hook" alternative that I can use do compile the classes?

seancorfield23:11:27

If you think you've "fixed" the problem in your code, go back and repeat this experiment and make sure you can load and run the hook: https://clojurians.slack.com/archives/C08LK2DH7/p1700169047926159?thread_ts=1700166725.087079&amp;cid=C08LK2DH7

gleisonsilva23:11:36

The problem was with the sfl4j shit... after I've removed (comment out) that error on spec alfa gone

gleisonsilva23:11:03

Now I came back to Kaocha

gleisonsilva23:11:23

and is almost 100% working.. there's just this error:

gleisonsilva23:11:56

that has to be with some logging shit..

gleisonsilva23:11:29

Finnaly! Everything working... in the end, I think it was just an 'require' that wasn't present... thank you very much, @U04V70XH6 You're the best Sean that I know of.

seancorfield23:11:28

Logging is a giant pain. Personally, I think Timbre makes it worse. We use clojure.tools.logging and log4j2 at work (after trying a lot of other things).

seancorfield23:11:12

Systematic, step-by-step debugging FTW 🙂

plexus07:11:53

Thanks @U04V70XH6 for helping to figure this out!