summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Hjemli <hjemli@gmail.com>2007-11-10 23:40:58 +0000
committerLars Hjemli <hjemli@gmail.com>2007-11-11 11:00:13 +0000
commitb4649fc90597910c89c3f37a6aec9af54d9f416b (patch)
treec4542a13f9509ebd92baf4f26548ddc72ac1f05f
parentab21082c21867e035cd925a06d6d55fb3143d883 (diff)
downloadcgit-b4649fc90597910c89c3f37a6aec9af54d9f416b.tar
cgit-b4649fc90597910c89c3f37a6aec9af54d9f416b.tar.gz
cgit-b4649fc90597910c89c3f37a6aec9af54d9f416b.zip
Create initial testsuite
This creates a simple testsuite, heavily inspired by the testsuite in git. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r--Makefile5
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/Makefile13
-rwxr-xr-xtests/setup.sh108
-rwxr-xr-xtests/t0010-validate-html.sh31
-rwxr-xr-xtests/t0101-index.sh13
-rwxr-xr-xtests/t0102-summary.sh20
-rwxr-xr-xtests/t0103-log.sh15
-rwxr-xr-xtests/t0104-tree.sh15
-rwxr-xr-xtests/t0105-commit.sh22
-rwxr-xr-xtests/t0106-diff.sh20
-rwxr-xr-xtests/t0107-snapshot.sh36
12 files changed, 299 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 685e662..72c189c 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ ifdef NEEDS_LIBICONV
endif
-.PHONY: all git install clean distclean emptycache force-version get-git
+.PHONY: all git test install clean distclean emptycache force-version get-git
all: cgit git
@@ -54,6 +54,9 @@ git:
cd git && $(MAKE) xdiff/lib.a
cd git && $(MAKE) libgit.a
+test: all
+ $(MAKE) -C tests
+
install: all
mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
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 <<EOF
+virtual-root=/
+cache-root=$PWD/trash/cache
+
+nocache=0
+snapshots=tar.gz tar.bz zip
+enable-log-filecount=1
+enable-log-linecount=1
+summary-log=5
+summary-branches=5
+summary-tags=5
+
+repo.url=foo
+repo.path=$PWD/trash/repos/foo/.git
+repo.desc=the foo repo
+
+repo.url=bar
+repo.path=$PWD/trash/repos/bar/.git
+repo.desc=the bar repo
+EOF
+}
+
+prepare_tests()
+{
+ setup_repos
+ test_count=0
+ test_failed=0
+ echo "$@" "($0)"
+}
+
+tests_done()
+{
+ printf "\n"
+ if test $test_failed -gt 0
+ then
+ printf "[%s of %s tests failed]\n" $test_failed $test_count
+ false
+ fi
+}
+
+run_test()
+{
+ desc=$1
+ script=$2
+ ((test_count++))
+ eval "$2" >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 "<a name=.1.>1</a>" trash/tmp'
+run_test 'no line 2' 'grep -ve "<a name=.2.>2</a>" 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 "<a href=./foo/tree/.>" trash/tmp'
+run_test 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" trash/tmp'
+
+run_test 'find commit subject' '
+ grep -e "<div class=.commit-subject.>commit 5</div>" trash/tmp
+'
+
+run_test 'find commit msg' 'grep -e "<div class=.commit-msg.></div>" trash/tmp'
+run_test 'find diffstat' 'grep -e "<table class=.diffstat.>" 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 "<a href=./foo/tree/file-5?id=" trash/tmp'
+run_test 'find added file' 'grep -e "new file mode 100644" trash/tmp'
+
+run_test 'find hunk header' '
+ grep -e "<div class=.hunk.>@@ -0,0 +1 @@</div>" trash/tmp
+'
+
+run_test 'find added line' '
+ grep -e "<div class=.add.>+5</div>" 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