On Thu, 2011-05-05 at 14:40 -0400, Greg Stein wrote:
> On Thu, May 5, 2011 at 11:20, Julian Foad <julian.f...@wandisco.com> wrote:
> > I keep coming across simple bugs in untested APIs, and sometimes I try
> > to write simple unit tests for those APIs.  To make this easier, I have
> > started to create a "svn_test__sandbox" class, with which a C test can
> > very easily set up a repository and a working copy, like the Python
> > tests do.  Then it can run the low-level functions that it is
> > unit-testing.
> 
> Sounds like a good idea.
> 
> >...
> >  {
> >    svn_test__sandbox_t b;
> >
> >    SVN_ERR(svn_test__sandbox_create(&b, "del_replace_not_present",
> >                                     opts, pool));
> >    SVN_ERR(wc_mkdir(&b, "A"));
> >    SVN_ERR(wc_mkdir(&b, "A/B"));
> >    SVN_ERR(wc_mkdir(&b, "A/B/X"));
> >    SVN_ERR(wc_mkdir(&b, "A/B/Y"));
> >    SVN_ERR(wc_mkdir(&b, "A/B/Z"));
> >    SVN_ERR(wc_commit(&b, ""));
> >    ...
> >  }
> 
> <bikeshed>
> 
> * call the variable "sbox" rather than the rather barren "b" (baton?)

Heh.  That variable *was* an anonymous baton until I abstracted the
baton's content from that old code to create this new 'sandbox' struct
type and switched it over :-)  I've used 'sbox' in new code.

> * wc_mkdir() and friends will need prefixes...

Sure.

> </bikeshed>
> 
> :-)
> 
> I would also recommend some commentary about pool usage.
> Implementation-wise, I would recommend creating a subpool in the
> create() function, putting the struct in there, and having a
> sandbox_destroy() function which throws out that pool. I don't like
> the idea of a test suite growing without bound because the individual
> test cases aren't clearing some pool. The sandbox lifetime seems a
> good marker for when to clear the pool.

I don't get it.  Roughly there's one sandbox used per test.  Each test
passes its own (scratch) pool to sandbox_create().  The test runner is
responsible for clearing that (scratch) pool between one test and the
next, I assume.

- Julian


Reply via email to