2010/12/1 Ken Wesson <kwess...@gmail.com> > 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))) > >
Yes, that's more or less what I was suggesting, and is, I think, implemented somehow in mocking test libraries, probably with a guarding try/finally. -- 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