This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (17)
- # babashka (109)
- # beginners (212)
- # calva (1)
- # chlorine (7)
- # cider (8)
- # clj-kondo (31)
- # cljsrn (2)
- # clojure (33)
- # clojure-dusseldorf (1)
- # clojure-finland (2)
- # clojure-france (22)
- # clojure-germany (1)
- # clojure-losangeles (1)
- # clojure-spec (6)
- # clojure-uk (19)
- # clojurescript (31)
- # conjure (41)
- # crux (9)
- # cryogen (1)
- # data-science (11)
- # datomic (6)
- # emacs (5)
- # exercism (8)
- # figwheel-main (2)
- # fulcro (57)
- # graalvm (15)
- # hoplon (15)
- # jobs-discuss (32)
- # kaocha (7)
- # off-topic (14)
- # pathom (2)
- # planck (9)
- # quil (1)
- # rum (5)
- # shadow-cljs (34)
- # spacemacs (33)
- # tools-deps (1)
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 ?
The deftest can loop through all test cases and call the defn with the parameters one after the other
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 have now is :
(deftest my-test (with-database [db] (is (blah db))))
(with-fixture :each (fn [t] (t (new-database))) (deftest my-test [db] (is (blah db))))
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.
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:
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
&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))))) #'user/prints-stack kcmds)user=>(defn x  (prints-stack)) ([java.lang.Thread getStackTrace "Thread.java" 1606] [user$prints_stack invokeStatic "NO_SOURCE_FILE" 1] [user$prints_stack invoke "NO_SOURCE_FILE" 1] [clojure.lang.AFn applyToHelper "AFn.java" 156] [clojure.lang.AFn applyTo "AFn.java" 144] [clojure.lang.Var applyTo "Var.java" 705] [clojure.lang.Compiler macroexpand1 "Compiler.java" 6993] [clojure.lang.Compiler analyzeSeq "Compiler.java" 7093] [clojure.lang.Compiler analyze "Compiler.java" 6789] [clojure.lang.Compiler analyze "Compiler.java" 6745] [clojure.lang.Compiler$BodyExpr$Parser parse "Compiler.java" 6120] [clojure.lang.Compiler$FnMethod parse "Compiler.java" 5467] [clojure.lang.Compiler$FnExpr parse "Compiler.java" 4029] [clojure.lang.Compiler analyzeSeq "Compiler.java" 7105] [clojure.lang.Compiler analyze "Compiler.java" 6789] [clojure.lang.Compiler analyzeSeq "Compiler.java" 7095] [clojure.lang.Compiler analyze "Compiler.java" 6789] [clojure.lang.Compiler access$300 "Compiler.java" 38] [clojure.lang.Compiler$DefExpr$Parser parse "Compiler.java" 596] [clojure.lang.Compiler analyzeSeq "Compiler.java" 7107] [clojure.lang.Compiler analyze "Compiler.java" 6789] [clojure.lang.Compiler analyze "Compiler.java" 6745] [clojure.lang.Compiler eval "Compiler.java" 7181] [clojure.lang.Compiler eval "Compiler.java" 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 "RestFn.java" 397] [clojure.lang.AFn applyToHelper "AFn.java" 152] [clojure.lang.RestFn applyTo "RestFn.java" 132] [clojure.lang.Var applyTo "Var.java" 705] [clojure.main main "main.java" 40]) #'user/x
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?
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 (https://docs.oracle.com/javase/8/docs/api/java/io/ByteArrayInputStream.html)