Fork me on GitHub

Hello, does clojure.test supports parameterized tests ? I would like to inject parameters created in fixtures to my tests. I can rely on dynamic var but I would rather not. (Unfortunately, I think I know the response, I'm hoping for some magic)


@jerome.prudent.ext remember. Tests are functions. You can call other functions from tests. The functions you can call can contain ‘is’ and ‘are’.


sure but I will just repeat the same boilerplate in each deftest won't I ?


You probably could write a macro for it.


No, from a deftest call a defn


The deftest can loop through all test cases and call the defn with the parameters one after the other


I think that should work


I have to be more precise on this topic. What I don't want is to call the same test over and over with subtle variations of inputs


What I want is to call different tests with a fresh state


what I have now is :

(deftest my-test
  (with-database [db]
    (is (blah db))))


what I'm looking for is


(with-fixture :each (fn [t] (t (new-database)))
(deftest my-test [db] (is (blah db))))


So that I don't have to write that with-database call over and over


macro should do it, but maybe I'm missing something


(doseq [db all-dbs] (with-database [db] (is ....))


if you need it to be a different deftest for each one, then (defn exercise-db [db] (with-database [db] (is ...))) then (deftest db-a-test (exercise-db a)) and (deftest db-b-test (exercise-db b)) etc.


no need for a macro


Hello. Is it possible for a macro to get the name of the function which called it? Example: I would like a macro (defmacro fn-name [] "placeholder-for-name-of-the-caller-fn-here") which returns the name of the calling function as string. So that when I have a function (defn foo [] (fn-name)) and I call (foo) it returns "foo". It would be nice to get the name of the outer most function definition. But even a cryptic name of a nested (anonymous) function would be ok. Is this even possible?


I'm curious too. But given Clojure's focus on pure functions (only input determines output) I think this is unlikely. All I can think about is, throw an exception and examine the stack trace.


I hoped, macros would be different. For example I can get the namespace of the calling function in the macro: (ns-name *ns*)


I believe the stacktrace can be obtained from the current Java Thread, without raising an exception. This could work....


if the name of the function was avalable, it would be found in &env or &form (the invisible, implicit, macro arguments). &env has all locals (including loop bindings, function args, let bindings) and &form has the form invoking the macro


yes, you can get the current stack trace, and if the function calling you was named, then you would see it - but a macro wouldn't see the wrapping functin, it would see the clojure compiler


inss)user=>(defmacro prints-stack [] (prn (seq (.getStackTrace (Thread/currentThread)))))
kcmds)user=>(defn x [] (prints-stack))
([java.lang.Thread getStackTrace "" 1606] [user$prints_stack invokeStatic "NO_SOURCE_FILE" 1] [user$prints_stack invoke "NO_SOURCE_FILE" 1] [clojure.lang.AFn applyToHelper "" 156] [clojure.lang.AFn applyTo "" 144] [clojure.lang.Var applyTo "" 705] [clojure.lang.Compiler macroexpand1 "" 6993] [clojure.lang.Compiler analyzeSeq "" 7093] [clojure.lang.Compiler analyze "" 6789] [clojure.lang.Compiler analyze "" 6745] [clojure.lang.Compiler$BodyExpr$Parser parse "" 6120] [clojure.lang.Compiler$FnMethod parse "" 5467] [clojure.lang.Compiler$FnExpr parse "" 4029] [clojure.lang.Compiler analyzeSeq "" 7105] [clojure.lang.Compiler analyze "" 6789] [clojure.lang.Compiler analyzeSeq "" 7095] [clojure.lang.Compiler analyze "" 6789] [clojure.lang.Compiler access$300 "" 38] [clojure.lang.Compiler$DefExpr$Parser parse "" 596] [clojure.lang.Compiler analyzeSeq "" 7107] [clojure.lang.Compiler analyze "" 6789] [clojure.lang.Compiler analyze "" 6745] [clojure.lang.Compiler eval "" 7181] [clojure.lang.Compiler eval "" 7132] [clojure.core$eval invokeStatic "core.clj" 3214] [clojure.core$eval invoke "core.clj" 3210] [clojure.main$repl$read_eval_print__9086$fn__9089 invoke "main.clj" 437] [clojure.main$repl$read_eval_print__9086 invoke "main.clj" 437] [clojure.main$repl$fn__9095 invoke "main.clj" 458] [clojure.main$repl invokeStatic "main.clj" 458] [clojure.main$repl_opt invokeStatic "main.clj" 522] [clojure.main$main invokeStatic "main.clj" 667] [clojure.main$main doInvoke "main.clj" 616] [clojure.lang.RestFn invoke "" 397] [clojure.lang.AFn applyToHelper "" 152] [clojure.lang.RestFn applyTo "" 132] [clojure.lang.Var applyTo "" 705] [clojure.main main "" 40])


can anyone recommend a way to standardise indentation for projects whose contributors use IntelliJ, emacs, and calva? enforce a policy with a subset of indentation features found amongst all editors? preprocess commits when they reach your favourite git server?


clj-fmt is good for that

👍 4

Supported by most editors too, there's also a graal build


Then have ci fail on linting errors


What is the simplest way to return string (which I got from bash command, because of convertion to pdf) in ring as a pdf file?


I've never had to do such a thing but the way I'd probably approach it would be to treat the string as a series of bytes (you'd need to know the encoding used in the string) and create an output stream from them with a content-type corresponding to a pdf (`application/pdf`?).


Content type application/pdf seems right, I think you need an Input stream. You could use java's ByteArrayInputStream (


thank you, I will try this