From 3b4a8eb10c185a65619b72264a1df4ac643451fc Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Wed, 25 Oct 2006 23:04:33 -0700 Subject: [PATCH] Initial commit of the test library Signed-off-by: Brandon Philips --- t/Makefile | 24 ++++++ t/README | 183 +++++++++++++++++++++++++++++++++++++++++++ t/t0000-basic.sh | 27 +++++++ t/test-lib.sh | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 462 insertions(+), 0 deletions(-) diff --git a/t/Makefile b/t/Makefile new file mode 100644 index 0000000..5567b15 --- /dev/null +++ b/t/Makefile @@ -0,0 +1,24 @@ +# Run tests +# +# Copyright (c) 2005 Junio C Hamano +# + +SHELL_PATH ?= $(SHELL) +TAR ?= $(TAR) + +# Shell quote; +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) + +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) + +all: $(T) clean + +$(T): + @echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ + +clean: + rm -fr trash + +.PHONY: $(T) clean +.NOTPARALLEL: + diff --git a/t/README b/t/README new file mode 100644 index 0000000..cfa5bbc --- /dev/null +++ b/t/README @@ -0,0 +1,183 @@ +chunkfs Tests +============= + +This directory may hold many test scripts for chunkfs in the future. The first +part of this short document describes how to run the tests and read their +output. + +When fixing the tools or adding enhancements, you are strongly encouraged to +add tests in this directory to cover what you are trying to fix or enhance. +The later part of this short document describes how your test scripts should be +organized. + + +Running Tests +------------- + +The easiest way to run tests is to say "make". This runs all +the tests. + + *** t0000-basic.sh *** + chunkfs initialized with 3 chunks + * ok 1: create file foo + * ok 2: rm file foo + * passed all 2 test(s) + +Or you can run each test individually from command line, like +this: + + $ ./t0000-basic.sh + chunkfs initialized with 3 chunks + * ok 1: create file foo + * ok 2: rm file foo + * passed all 2 test(s) + + +You can pass --verbose (or -v), --debug (or -d), and --immediate +(or -i) command line argument to the test. + +--verbose:: + This makes the test more verbose. Specifically, the + command being run and their output if any are also + output. + +--debug:: + This may help the person who is developing a new test. + It causes the command defined with test_debug to run. + +--immediate:: + This causes the test to immediately exit upon the first + failed test. + + +Naming Tests +------------ + +TODO: decide on the naming scheme. + +The test files are named as: + + tNNNN-commandname-details.sh + +where N is a decimal digit. + +First digit tells the family: + + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + +Second digit tells the particular command we are testing. + +Third digit (optionally) tells the particular switch or group of switches we +are testing. + +If you create files under t/ directory (i.e. here) that is not the top-level +test script, never name the file to match the above pattern. The Makefile here +considers all such files as the top-level test script and tries to run all of +them. A care is especially needed if you are creating a common test library +file, similar to test-lib.sh, because such a library file may not be suitable +for standalone execution. + + +Writing Tests +------------- + +The test script is written as a shell script. It should start with the +standard "#!/bin/sh" with copyright notices, and an assignment to the variables +'test_description' and 'chunk_sizes', like this: + + #!/bin/sh + # + # Copyright (c) 2006 Brandon Philips + # + + test_description='xxx test + + This test does some fancy filesystems type stuff' + + chunk_sizes=(1 1 1) # Create three one block chunks + + +Source 'test-lib.sh' +-------------------- + +After assigning test_description, the test script should source test-lib.sh +like this: + + . ./test-lib.sh + +This test harness library does the following things: + + - If the script is invoked with command line argument --help (or -h), it shows + the test_description and exits. + + - Creates a directory with a disk/ and mnt/ chdir into mnt/ after creating and + mounting the disks. This directory is 't/trash' if you must know, but I do + not think you care. + + - Defines standard test helper functions for your scripts to use. These + functions are designed to make all scripts behave consistently when command + line arguments --verbose (or -v), --debug (or -d), and --immediate (or -i) + is given. + + +End with test_done +------------------ + +Your script will be a sequence of tests, using helper functions from the test +harness library. At the end of the script, call 'test_done'. + + +Test harness library +-------------------- + +There are a handful helper functions defined in the test harness library for +your script to use. + + - test_expect_success