Hey all. I’m trying to use test.check/generators in GraalVM and am getting the following error:
Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/test/check/generators__init.class, clojure/test/check/generators.clj or clojure/test/check/generators.cljc on classpath.
The demo app is very simple:
(ns test-check.main
(:require
[clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen])
(:gen-class))
(defn -main []
(println "Hello test.check")
(println (gen/generate (s/gen int?)))
(println (gen/generate (s/gen nil?)))
(println (gen/sample (s/gen string?)))
(println (gen/sample (s/gen #{:club :diamond :heart :spade})))
(println (gen/sample (s/gen (s/cat :k keyword? :ns (s/+ number?))))))
With the following in the project.clj
(defproject test-check "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.10.3"]
[org.clojure/test.check "1.1.0"]]
:main test-check.main
:profiles {:uberjar {:aot :all}
:dev {:plugins [[lein-shell "0.5.0"]]}}
:aliases
{"native"
["shell"
"native-image"
"--no-fallback"
"--no-server"
"--report-unsupported-elements-at-runtime"
"--initialize-at-build-time"
"-jar" "./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}"
"-H:Name=./target/${:name}"]
"run-native" ["shell" "./target/${:name}"]})
As a sanity check, I do have other successful native-image
builds going, but am getting hung up on this one… Any advice?@campeterson > and am getting the following error when?
@campeterson fwiw, clojure.test.check is also bundled with babashka and compiled with lein so you could look at that project
Sorry, getting that error when run the executable I built w/ native-image
It builds successfully, but when I run the output, that’s where it chokes
@borkdude I’ll take a look at babashka.
there is also a fix for the randomizer which doesn't work out of the box with graalvm native-image. I logged an issue about this in test.check
Yes, I saw your issue. Was double checking I was using the same flags
I think you might need to require the clojure.test.check namespaces at compile time
That did it! source now looks like this:
(ns test-check.main
(:require
[clojure.spec.alpha :as s]
#_[clojure.spec.gen.alpha :as gen]
)
(:gen-class))
(require '[clojure.test.check.generators :as gen])
(defn -main []
(println "Hello test.check")
(println (gen/generate (s/gen int?)))
(println (gen/generate (s/gen nil?)))
(println (gen/sample (s/gen string?)))
(println (gen/sample (s/gen #{:club :diamond :heart :spade})))
(println (gen/sample (s/gen (s/cat :k keyword? :ns (s/+ number?))))))
Compiles fine and now the executable runs
But do you get random samples every new run?
Nope. Same samples each run
A workaround can be found in the link I posted earlier
Thanks @borkdude this is all great stuff. I appreciate the help
(We love bb
at work, by the way. Your open source contributions are stellar)
P.S. I added these lines in and it works as you said https://github.com/babashka/babashka/blob/master/feature-test-check/babashka/impl/clojure/test/check.clj#L6-L27