[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Test framework for C tests - svn_test__sandbox_create()

From: Greg Stein <gstein_at_gmail.com>
Date: Thu, 5 May 2011 14:40:49 -0400

On Thu, May 5, 2011 at 11:20, Julian Foad <julian.foad_at_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?)
* wc_mkdir() and friends will need prefixes...

</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.

Cheers,
-g
Received on 2011-05-05 20:41:17 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.