Fork me on GitHub
#kaocha
<
2022-04-23
>
MIJOTHY11:04:20

Is there a way to extract the full file path (relative to the project) of a test in a kaocha plugin? As far as I can tell, the :file property in :kaocha.testable/meta is relative to one of the entries in the :kaocha/test-paths vector, and which test-path is used for a given test isn’t retained anywhere. Is that correct?

plexus11:04:15

You get run that through io/resource to get a full URL

MIJOTHY11:04:05

i’ll give that a shot, cheers

MIJOTHY11:04:13

as in

( (get-in m [::testable/meta :file]))
?

MIJOTHY11:04:00

or joining the :file entry to each element of the test-paths vector, and testing if it exists?

MIJOTHY18:04:26

also happy to submit a PR to add :test-path into the testable/meta map, since that may be a more direct way of achieving this?

plexus06:04:01

> (http://clojure.java.io/resource (get-in m [::testable/meta :file])) yes, exactly > or joining the :file entry to each element of the test-paths vector, and testing if it exists? don't do that, the :file var metadata you get from clojure is relative to the classpath, the correct way to resolve something on the classpath is with io/resource. The way Kaocha works it'll scan test-paths for namespaces, and will then require those namespaces through standard clojure mechanisms, and then use runtime inspection to find the vars. So the actual loading happens based on the classpath (since that's what clojure does) > also happy to submit a PR to add :test-path into the testable/meta map, since that may be a more direct way of achieving this? the testable/meta is not something we build up, it's just the metadata that clojure puts on the test var, so we don't add anything to it. You could add it to the testable, but classpath lookups aren't free, I don't think we should impose this cost just in case a plugin might want it, since it's trivial for a plugin to the do the lookup itself.

MIJOTHY08:04:10

ah i see thanks

MIJOTHY09:04:30

ah interesting, i need to explicitly supply Compiler/LOADER to io/resource