On Dec 1, 3:33 pm, Ken Wesson <kwess...@gmail.com> wrote: > On Wed, Dec 1, 2010 at 9:38 AM, Laurent PETIT <laurent.pe...@gmail.com> wrote: > > 2010/12/1 Ken Wesson <kwess...@gmail.com> > > >> On Wed, Dec 1, 2010 at 8:29 AM, Laurent PETIT <laurent.pe...@gmail.com> > >> wrote: > >> > If so, then it may be sufficient to leverage the possibility, in your > >> > testing "framework" (clojure.test ? anything else ...) to redefine the > >> > functions of the backend before the tests run. I'm pretty sure there are > >> > already such features allowing to temporarily "redef" (and "restore" at > >> > the > >> > end) the root value of global vars. > > >> (binding [*global-var* temp-value] > >> (run-some-tests)) > > >> :) > > > I didn't forget it. But : > > * in Clojure 1.2 : these binding do not automatically flow from thread to > > thread, so they do not work "in the general case" (though arguably this > > general case may not be the usual case) > > * in Clojure 1.3 : the bindings will now flow from thread to thread when > > using clojure primitives (agents, futures, pmap, etc.), *but* the default > > for vars will change from dynamic rebindable to not dynamic rebindable > > (dynamic rebindability will have to be explicit) > > > :) > > If you need it in multiple threads, you're just gonna have to go with > the slightly evil > > (let [x *foo*] > (alter-var-root #'*foo* (constantly testing-value)) > (do-some-tests) > (alter-var-root #'*foo* (constantly x)))
There's actually a shortcut for this in 1.3.0-alpha3, thanks to Chris Houser and Stuart Halloway: (with-redefs [*foo* (constantly testing-value)] (do-some-tests)) -Colin -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en