testing

gleisonsilva 2023-11-16T20:32:05.087079Z

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}}

plexus 2023-11-20T07:18:53.060889Z

Thanks @seancorfield for helping to figure this out!

seancorfield 2023-11-16T20:37:15.841549Z

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

gleisonsilva 2023-11-16T20:43:55.419509Z

Slingshot? Sorry... what that should be?

seancorfield 2023-11-16T20:45:26.661649Z

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

gleisonsilva 2023-11-16T20:49:10.052469Z

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"]}
		   }
 }
```

seancorfield 2023-11-16T20:59:47.624739Z

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?

gleisonsilva 2023-11-16T21:00:17.318009Z

I have none.

seancorfield 2023-11-16T21:00:31.037549Z

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

gleisonsilva 2023-11-16T21:01:26.862469Z

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 "$@"

seancorfield 2023-11-16T21:01:54.264839Z

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?

gleisonsilva 2023-11-16T21:02:19.244659Z

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

seancorfield 2023-11-16T21:02:29.325349Z

And what does clojure -version print out?

gleisonsilva 2023-11-16T21:02:33.703569Z

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

gleisonsilva 2023-11-16T21:02:43.635039Z

clojure -version Clojure CLI version 1.11.1.1347

seancorfield 2023-11-16T21:03:34.854549Z

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

gleisonsilva 2023-11-16T21:04:55.929139Z

yes, it is

gleisonsilva 2023-11-16T21:05:31.278169Z

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

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

gleisonsilva 2023-11-16T21:05:40.153339Z

^ it's this simple

seancorfield 2023-11-16T21:07:38.059679Z

And that's under your test tree?

gleisonsilva 2023-11-16T21:08:36.941029Z

yes:

seancorfield 2023-11-16T21:10:47.926159Z

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.

seancorfield 2023-11-16T21:11:23.396749Z

(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)

gleisonsilva 2023-11-16T21:23:42.557009Z

It gives an error:

seancorfield 2023-11-16T21:25:11.772399Z

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.

seancorfield 2023-11-16T21:26:18.890249Z

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.

seancorfield 2023-11-16T21:26:43.931669Z

(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)

seancorfield 2023-11-16T21:27:22.151389Z

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

gleisonsilva 2023-11-16T21:31:16.552879Z

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

gleisonsilva 2023-11-16T22:10:51.991709Z

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

gleisonsilva 2023-11-16T22:11:00.631879Z

thank you very much for the tips

seancorfield 2023-11-16T22:11:31.411799Z

Happy to help! Glad you figured it out 🙂

seancorfield 2023-11-16T22:12:32.126649Z

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?

gleisonsilva 2023-11-16T22:14:05.616159Z

it was both in both places

gleisonsilva 2023-11-16T22:27:26.339609Z

😞 i was wrong

gleisonsilva 2023-11-16T22:27:30.150789Z

it didn't work

gleisonsilva 2023-11-16T22:28:11.041619Z

it's really weird, @seancorfield

gleisonsilva 2023-11-16T22:28:33.650949Z

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

gleisonsilva 2023-11-16T22:28:43.295269Z

seancorfield 2023-11-16T22:52:29.425679Z

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

seancorfield 2023-11-16T22:53:28.959079Z

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.

seancorfield 2023-11-16T22:54:59.580579Z

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

seancorfield 2023-11-16T22:55:25.907309Z

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

gleisonsilva 2023-11-16T22:59:24.986859Z

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

gleisonsilva 2023-11-16T22:59:43.254719Z

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

gleisonsilva 2023-11-16T22:59:59.642899Z

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

gleisonsilva 2023-11-16T23:00:30.320929Z

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

gleisonsilva 2023-11-16T23:01:19.730089Z

(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)

seancorfield 2023-11-16T23:04:54.091929Z

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

seancorfield 2023-11-16T23:05:18.177079Z

You need to do little tiny steps in the REPL.

seancorfield 2023-11-16T23:05:39.501449Z

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

gleisonsilva 2023-11-16T23:05:44.469809Z

from repl it's working

gleisonsilva 2023-11-16T23:05:52.233439Z

there's no syntax error

seancorfield 2023-11-16T23:06:13.091989Z

37 minutes ago, you said there was still.

seancorfield 2023-11-16T23:06:35.883739Z

Fresh REPL. One require. It failed.

gleisonsilva 2023-11-16T23:06:41.215119Z

yeah... but that i could figure out

gleisonsilva 2023-11-16T23:06:49.178679Z

and fixed

gleisonsilva 2023-11-16T23:07:10.970229Z

the only thing now is this code:

gleisonsilva 2023-11-16T23:07:17.760969Z

gleisonsilva 2023-11-16T23:07:22.018299Z

it's a test

gleisonsilva 2023-11-16T23:07:34.375279Z

and it need the class docx.servlet

gleisonsilva 2023-11-16T23:07:43.244469Z

but it can't find this class

seancorfield 2023-11-16T23:07:57.375069Z

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

gleisonsilva 2023-11-16T23:07:59.686889Z

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

seancorfield 2023-11-16T23:08:21.484299Z

That hook was what was compiling the classes you need.

gleisonsilva 2023-11-16T23:08:33.247319Z

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

gleisonsilva 2023-11-16T23:09:13.839449Z

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

seancorfield 2023-11-16T23:09:44.306299Z

No.

seancorfield 2023-11-16T23:10:27.510639Z

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

gleisonsilva 2023-11-16T23:12:36.947659Z

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

gleisonsilva 2023-11-16T23:12:52.790159Z

gleisonsilva 2023-11-16T23:13:03.384899Z

Now I came back to Kaocha

gleisonsilva 2023-11-16T23:13:23.063489Z

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

gleisonsilva 2023-11-16T23:13:40.105939Z

gleisonsilva 2023-11-16T23:13:56.399879Z

that has to be with some logging shit..

gleisonsilva 2023-11-16T23:18:29.349239Z

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

seancorfield 2023-11-16T23:19:28.834799Z

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).

seancorfield 2023-11-16T23:20:12.877959Z

Systematic, step-by-step debugging FTW 🙂