Understanding Acceptance Tests

Setup for a test

As you'll soon discover, there can be a lot of repeated setup to test a particular command: for example, if you're testing the checkout command you need to:

  1. Initialize a Gitlet Repository
  2. Create a commit with a file in some version (v1)
  3. Create another commit with that file in some other version (v2)
  4. Checkout that file to v1

And perhaps even more if you want to test with files that were untracked in the second commit but tracked in the first.

So the way you can save yourself time is by adding all that setup in a file and using the I command. Say we do that here:

# Initialize, add, and commit a file.
> init
<<<
+ a.txt wug.txt
> add a.txt
<<<
> commit "a is a wug"
<<<

We should place this file with the rest of the tests in the samples directory, but with a file extension .inc, so maybe we name it samples/commit_setup.inc. If we gave it the file extension .in, our testing script will mistake it for a test and try to run it individually. Now, in our actual test, we simply use the command:

I commit_setup.inc

This will have the testing script run all of the commands in that file and keep the temporary directory it creates. This keeps your tests relatively short and thus easier to read.

We've included one .inc file called definitions.inc that will set up patterns for your convenience. Let's understand what patterns are.