mirror of
https://git.zx2c4.com/cgit
synced 2024-11-25 01:48:41 +00:00
Create initial testsuite
This creates a simple testsuite, heavily inspired by the testsuite in git. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
This commit is contained in:
parent
ab21082c21
commit
b4649fc905
5
Makefile
5
Makefile
@ -24,7 +24,7 @@ ifdef NEEDS_LIBICONV
|
|||||||
endif
|
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
|
all: cgit git
|
||||||
|
|
||||||
@ -54,6 +54,9 @@ git:
|
|||||||
cd git && $(MAKE) xdiff/lib.a
|
cd git && $(MAKE) xdiff/lib.a
|
||||||
cd git && $(MAKE) libgit.a
|
cd git && $(MAKE) libgit.a
|
||||||
|
|
||||||
|
test: all
|
||||||
|
$(MAKE) -C tests
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
|
mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
|
||||||
install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
|
install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
|
||||||
|
2
tests/.gitignore
vendored
Normal file
2
tests/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
trash
|
||||||
|
test-output.log
|
13
tests/Makefile
Normal file
13
tests/Makefile
Normal file
@ -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
|
108
tests/setup.sh
Executable file
108
tests/setup.sh
Executable file
@ -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"
|
||||||
|
}
|
||||||
|
|
31
tests/t0010-validate-html.sh
Executable file
31
tests/t0010-validate-html.sh
Executable file
@ -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
|
13
tests/t0101-index.sh
Executable file
13
tests/t0101-index.sh
Executable file
@ -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
|
20
tests/t0102-summary.sh
Executable file
20
tests/t0102-summary.sh
Executable file
@ -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
|
15
tests/t0103-log.sh
Executable file
15
tests/t0103-log.sh
Executable file
@ -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
|
15
tests/t0104-tree.sh
Executable file
15
tests/t0104-tree.sh
Executable file
@ -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
|
22
tests/t0105-commit.sh
Executable file
22
tests/t0105-commit.sh
Executable file
@ -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
|
20
tests/t0106-diff.sh
Executable file
20
tests/t0106-diff.sh
Executable file
@ -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
|
36
tests/t0107-snapshot.sh
Executable file
36
tests/t0107-snapshot.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user