From b4649fc90597910c89c3f37a6aec9af54d9f416b Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 11 Nov 2007 00:40:58 +0100 Subject: Create initial testsuite This creates a simple testsuite, heavily inspired by the testsuite in git. Signed-off-by: Lars Hjemli --- tests/.gitignore | 2 + tests/Makefile | 13 ++++++ tests/setup.sh | 108 +++++++++++++++++++++++++++++++++++++++++++ tests/t0010-validate-html.sh | 31 +++++++++++++ tests/t0101-index.sh | 13 ++++++ tests/t0102-summary.sh | 20 ++++++++ tests/t0103-log.sh | 15 ++++++ tests/t0104-tree.sh | 15 ++++++ tests/t0105-commit.sh | 22 +++++++++ tests/t0106-diff.sh | 20 ++++++++ tests/t0107-snapshot.sh | 36 +++++++++++++++ 11 files changed, 295 insertions(+) create mode 100644 tests/.gitignore create mode 100644 tests/Makefile create mode 100755 tests/setup.sh create mode 100755 tests/t0010-validate-html.sh create mode 100755 tests/t0101-index.sh create mode 100755 tests/t0102-summary.sh create mode 100755 tests/t0103-log.sh create mode 100755 tests/t0104-tree.sh create mode 100755 tests/t0105-commit.sh create mode 100755 tests/t0106-diff.sh create mode 100755 tests/t0107-snapshot.sh (limited to 'tests') diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..c1c1c0b --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +trash +test-output.log diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..697e5a1 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,13 @@ + + +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) + +all: $(T) + +$(T): + @$@ + +clean: + $(RM) -rf trash + +.PHONY: $(T) clean diff --git a/tests/setup.sh b/tests/setup.sh new file mode 100755 index 0000000..51d5a75 --- /dev/null +++ b/tests/setup.sh @@ -0,0 +1,108 @@ +# This file should be sourced by all test-scripts +# +# Main functions: +# prepare_tests(description) - setup for testing, i.e. create repos+config +# run_test(description, script) - run one test, i.e. eval script +# +# Helper functions +# cgit_query(querystring) - call cgit with the specified querystring +# cgit_url(url) - call cgit with the specified virtual url +# +# Example script: +# +# . setup.sh +# prepare_tests "html validation" +# run_test 'repo index' 'cgit_url "/" | tidy -e' +# run_test 'repo summary' 'cgit_url "/foo" | tidy -e' + + +mkrepo() { + name=$1 + count=$2 + dir=$PWD + test -d $name && return + printf "Creating testrepo %s\n" $name + mkdir -p $name + cd $name + git init + for ((n=1; n<=count; n++)) + do + echo $n >file-$n + git add file-$n + git commit -m "commit $n" + done + cd $dir +} + +setup_repos() +{ + rm -rf trash/cache + mkdir -p trash/cache + mkrepo trash/repos/foo 5 >/dev/null + mkrepo trash/repos/bar 50 >/dev/null + cat >trash/cgitrc <test-output.log + res=$? + if test $res = 0 + then + printf " %s: ok - %s\n" $test_count "$desc" + else + ((test_failed++)) + printf " %s: fail - %s\n" $test_count "$desc" + fi +} + +cgit_query() +{ + CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit" +} + +cgit_url() +{ + CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit" +} + diff --git a/tests/t0010-validate-html.sh b/tests/t0010-validate-html.sh new file mode 100755 index 0000000..907a415 --- /dev/null +++ b/tests/t0010-validate-html.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +. ./setup.sh + + +test_url() +{ + tidy_opt="-eq" + test -z "$NO_TIDY_WARNINGS" || tidy_opt+=" --show-warnings no" + cgit_url "$1" | sed -e "1,4d" >trash/tidy-$test_count + tidy $tidy_opt trash/tidy-$test_count + rc=$? + if test $rc = 2 + then + false + else + : + fi +} + +prepare_tests 'Validate html with tidy' + +run_test 'index page' 'test_url ""' +run_test 'foo' 'test_url "foo"' +run_test 'foo/log' 'test_url "foo/log"' +run_test 'foo/tree' 'test_url "foo/tree"' +run_test 'foo/tree/file-1' 'test_url "foo/tree/file-1"' +run_test 'foo/commit' 'test_url "foo/commit"' +run_test 'foo/diff' 'test_url "foo/diff"' + +tests_done diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh new file mode 100755 index 0000000..12ed00c --- /dev/null +++ b/tests/t0101-index.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +. ./setup.sh + +prepare_tests "Check content on index page" + +run_test 'generate index page' 'cgit_url "" >trash/tmp' +run_test 'find foo repo' 'grep -e "foo" trash/tmp' +run_test 'find bar repo' 'grep -e "bar" trash/tmp' +run_test 'no tree-link' 'grep -ve "foo/tree" trash/tmp' +run_test 'no log-link' 'grep -ve "foo/log" trash/tmp' + +tests_done diff --git a/tests/t0102-summary.sh b/tests/t0102-summary.sh new file mode 100755 index 0000000..7edd675 --- /dev/null +++ b/tests/t0102-summary.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +. ./setup.sh + +prepare_tests "Check content on summary page" + +run_test 'generate foo summary' 'cgit_url "foo" >trash/tmp' +run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' +run_test 'find commit 5' 'grep -e "commit 5" trash/tmp' +run_test 'find branch master' 'grep -e "master" trash/tmp' +run_test 'no tags' 'grep -ve "tags" trash/tmp' + +run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp' +run_test 'no commit 45' 'grep -ve "commit 45" trash/tmp' +run_test 'find commit 46' 'grep -e "commit 46" trash/tmp' +run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' +run_test 'find branch master' 'grep -e "master" trash/tmp' +run_test 'no tags' 'grep -ve "tags" trash/tmp' + +tests_done diff --git a/tests/t0103-log.sh b/tests/t0103-log.sh new file mode 100755 index 0000000..b08cd29 --- /dev/null +++ b/tests/t0103-log.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. ./setup.sh + +prepare_tests "Check content on log page" + +run_test 'generate foo/log' 'cgit_url "foo/log" >trash/tmp' +run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' +run_test 'find commit 5' 'grep -e "commit 5" trash/tmp' + +run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp' +run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' +run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' + +tests_done diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh new file mode 100755 index 0000000..9c362ca --- /dev/null +++ b/tests/t0104-tree.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. ./setup.sh + +prepare_tests "Check content on tree page" + +run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp' +run_test 'find file-1' 'grep -e "file-1" trash/tmp' +run_test 'find file-50' 'grep -e "file-50" trash/tmp' + +run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp' +run_test 'find line 1' 'grep -e "1" trash/tmp' +run_test 'no line 2' 'grep -ve "2" trash/tmp' + +tests_done diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh new file mode 100755 index 0000000..7137751 --- /dev/null +++ b/tests/t0105-commit.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +. ./setup.sh + +prepare_tests "Check content on commit page" + +run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp' +run_test 'find tree link' 'grep -e "" trash/tmp' +run_test 'find parent link' 'grep -E "" trash/tmp' + +run_test 'find commit subject' ' + grep -e "
commit 5
" trash/tmp +' + +run_test 'find commit msg' 'grep -e "
" trash/tmp' +run_test 'find diffstat' 'grep -e "" trash/tmp' + +run_test 'find diff summary' ' + grep -e "1 files changed, 1 insertions, 0 deletions" trash/tmp +' + +tests_done diff --git a/tests/t0106-diff.sh b/tests/t0106-diff.sh new file mode 100755 index 0000000..e140bcc --- /dev/null +++ b/tests/t0106-diff.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +. ./setup.sh + +prepare_tests "Check content on diff page" + +run_test 'generate foo/diff' 'cgit_url "foo/diff" >trash/tmp' +run_test 'find diff header' 'grep -e "a/file-5 b/file-5" trash/tmp' +run_test 'find blob link' 'grep -e "@@ -0,0 +1 @@" trash/tmp +' + +run_test 'find added line' ' + grep -e "
+5
" trash/tmp +' + +tests_done diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh new file mode 100755 index 0000000..8e90e10 --- /dev/null +++ b/tests/t0107-snapshot.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +. ./setup.sh + +prepare_tests "Verify snapshot" + +run_test 'get foo/snapshot/test.tar.gz' ' + cgit_url "foo/snapshot/test.tar.gz" >trash/tmp +' + +run_test 'check html headers' ' + head -n 1 trash/tmp | + grep -e "Content-Type: application/x-tar" && + + head -n 2 trash/tmp | + grep -e "Content-Disposition: inline; filename=.test.tar.gz." +' + +run_test 'strip off the header lines' ' + tail -n +6 trash/tmp > trash/test.tar.gz +' + +run_test 'verify gzip format' 'gunzip --test trash/test.tar.gz' +run_test 'untar' 'tar -xf trash/test.tar.gz -C trash' + +run_test 'count files' ' + c=$(ls -1 trash/foo/ | wc -l) && + test $c = 5 +' + +run_test 'verify untarred file-5' ' + grep -e "^5$" trash/foo/file-5 && + test $(cat trash/foo/file-5 | wc -l) = 1 +' + +tests_done -- cgit 1.4.1-21-gabe81