Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ported t04_commit.c to Clar. #603

Merged
merged 0 commits into from

2 participants

@ben

Helping out with issue #406.

@arrbee
Owner

Hey @benstraub. Thanks for doing this. Everything seems to work, but in the new clar-based testing world, we are trying to do things a little differently from the old tests, so this isn't quite matching the new style.

First off, clar has a notion of fixtures that can be installed automatically before every test (and cleaned up afterwards). This means you don't have to (and shouldn't) do stuff like:

#define REPOSITORY_FOLDER CLAR_RESOURCES "/testrepo.git/"
...
git_repository_open(&repo, REPOSITORY_FOLDER);

Instead, you just need to call cl_fixture("testrepo.git") and it will be installed for you. There is actually an existing helper called cl_git_sandbox_init() that wraps this up in a way that is super-easy to use. Just call:

git_repository *repo = cl_git_sandbox_init("testrepo.git");

at the top of your test and then:

cl_git_sandbox_cleanup();

at the bottom. You can see a simple example of this in tests-clar/status/ignore.c using the initialize/cleanup functions that clar automatically calls before and after every test.

If you use the fixtures, there is no need to call stuff like remove_loose_object() after the test is over, since clar will automatically cleanup and rebuild the whole fixture for you.

Also, the clar fixture directory is configurable, so right now we point it at libgit2/tests/resources so we don't have to recreate all the test data in tests-clar/resources. Once all of the tests have been moved to clar, we will just git mv the old resources directory from tests to tests-clar. But for now, there is no need to recreate whole new testing repos in the tests-clar area.

Lastly, we have tried to get away from the macro-driven style of the old tests. Instead, we are trying to just write plain C functions or put test data into static structures. I feel like it makes the tests easier to read, but of course, you are free to disagree.

As a quick example, if I were to write the tests-clar/commit/parse.c tests, I would probably start the file looking something like: https://gist.github.com/2141997

@ben ben merged commit e71b78b into from
@ben

Please ignore this pull in favor of #606. Sorry for the mess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Sorry, commit information is not available for this pull request.

Something went wrong with that request. Please try again.