tests: use Git's test framework

This allows tests to run in parallel as well as letting us use "prove"
or another TAP harness to run the tests.

Git's test framework requires Git to be fully built before letting any
tests run, so add a new target to the top-level Makefile which builds
all of Git instead of just libgit.a and make the "test" target depend on
that.

Signed-off-by: John Keeping <john@keeping.me.uk>
This commit is contained in:
John Keeping 2013-04-01 15:09:05 +01:00 committed by Jason A. Donenfeld
parent 8a92df033e
commit c95cc5ec56
13 changed files with 239 additions and 291 deletions

View File

@ -66,7 +66,10 @@ all:: cgit
cgit: cgit:
$(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit.mk ../cgit NO_CURL=1 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit.mk ../cgit NO_CURL=1
test: all git:
$(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1
test: all git
$(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all
install: all install: all
@ -145,7 +148,7 @@ get-git:
tags: tags:
$(QUIET_TAGS)find . -name '*.[ch]' | xargs ctags $(QUIET_TAGS)find . -name '*.[ch]' | xargs ctags
.PHONY: all cgit get-git .PHONY: all cgit git get-git
.PHONY: clean clean-doc cleanall .PHONY: clean clean-doc cleanall
.PHONY: doc doc-html doc-man doc-pdf .PHONY: doc doc-html doc-man doc-pdf
.PHONY: install install-doc install-html install-man install-pdf .PHONY: install install-doc install-html install-man install-pdf

View File

@ -15,17 +15,19 @@
# run_test 'repo index' 'cgit_url "/" | tidy -e' # run_test 'repo index' 'cgit_url "/" | tidy -e'
# run_test 'repo summary' 'cgit_url "/foo" | tidy -e' # run_test 'repo summary' 'cgit_url "/foo" | tidy -e'
unset CDPATH : ${TEST_DIRECTORY=$(pwd)/../git/t}
TEST_NO_CREATE_REPO=YesPlease
. "$TEST_DIRECTORY"/test-lib.sh
# Prepend the directory containing cgit to PATH.
PATH="$(pwd)/../..:$PATH"
mkrepo() { mkrepo() {
name=$1 name=$1
count=$2 count=$2
dir=$PWD test_create_repo "$name"
test -d "$name" && return (
printf "Creating testrepo %s\n" "$name"
mkdir -p "$name"
cd "$name" cd "$name"
git init
n=1 n=1
while test $n -le $count while test $n -le $count
do do
@ -41,20 +43,20 @@ mkrepo() {
git commit -m "add a+b" git commit -m "add a+b"
git branch "1+2" git branch "1+2"
fi fi
cd "$dir" )
} }
setup_repos() setup_repos()
{ {
rm -rf trash/cache rm -rf cache
mkdir -p trash/cache mkdir -p cache
mkrepo trash/repos/foo 5 >/dev/null mkrepo repos/foo 5 >/dev/null
mkrepo trash/repos/bar 50 >/dev/null mkrepo repos/bar 50 >/dev/null
mkrepo trash/repos/foo+bar 10 testplus >/dev/null mkrepo repos/foo+bar 10 testplus >/dev/null
mkrepo "trash/repos/with space" 2 >/dev/null mkrepo "repos/with space" 2 >/dev/null
cat >trash/cgitrc <<EOF cat >cgitrc <<EOF
virtual-root=/ virtual-root=/
cache-root=$PWD/trash/cache cache-root=$PWD/cache
cache-size=1021 cache-size=1021
snapshots=tar.gz tar.bz zip snapshots=tar.gz tar.bz zip
@ -66,83 +68,33 @@ summary-tags=5
clone-url=git://example.org/\$CGIT_REPO_URL.git clone-url=git://example.org/\$CGIT_REPO_URL.git
repo.url=foo repo.url=foo
repo.path=$PWD/trash/repos/foo/.git repo.path=$PWD/repos/foo/.git
# Do not specify a description for this repo, as it then will be assigned # Do not specify a description for this repo, as it then will be assigned
# the constant value "[no description]" (which actually used to cause a # the constant value "[no description]" (which actually used to cause a
# segfault). # segfault).
repo.url=bar repo.url=bar
repo.path=$PWD/trash/repos/bar/.git repo.path=$PWD/repos/bar/.git
repo.desc=the bar repo repo.desc=the bar repo
repo.url=foo+bar repo.url=foo+bar
repo.path=$PWD/trash/repos/foo+bar/.git repo.path=$PWD/repos/foo+bar/.git
repo.desc=the foo+bar repo repo.desc=the foo+bar repo
repo.url=with space repo.url=with space
repo.path=$PWD/trash/repos/with space/.git repo.path=$PWD/repos/with space/.git
repo.desc=spaced repo repo.desc=spaced repo
EOF EOF
} }
prepare_tests()
{
setup_repos
rm -f test-output.log 2>/dev/null
test_count=0
test_failed=0
echo "[$0]" "$@" >test-output.log
echo "$@" "($0)"
}
tests_done()
{
printf "\n"
if test $test_failed -gt 0
then
printf "test: *** %s failure(s), logfile=%s\n" \
$test_failed "$(pwd)/test-output.log"
false
fi
}
run_test()
{
bug=0
if test "$1" = "BUG"
then
bug=1
shift
fi
desc=$1
script=$2
test_count=$(expr $test_count + 1)
printf "\ntest %d: name='%s'\n" $test_count "$desc" >>test-output.log
printf "test %d: eval='%s'\n" $test_count "$2" >>test-output.log
eval "$2" >>test-output.log 2>>test-output.log
res=$?
printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log
if test $res = 0 -a $bug = 0
then
printf " %2d) %-60s [ok]\n" $test_count "$desc"
elif test $res = 0 -a $bug = 1
then
printf " %2d) %-60s [BUG FIXED]\n" $test_count "$desc"
elif test $bug = 1
then
printf " %2d) %-60s [KNOWN BUG]\n" $test_count "$desc"
else
test_failed=$(expr $test_failed + 1)
printf " %2d) %-60s [failed]\n" $test_count "$desc"
fi
}
cgit_query() cgit_query()
{ {
CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit" CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
} }
cgit_url() cgit_url()
{ {
CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit" CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
} }
test -z "$CGIT_TEST_NO_CREATE_REPOS" && setup_repos

View File

@ -1,36 +1,36 @@
#!/bin/sh #!/bin/sh
test_description='Check Git version is correct'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh . ./setup.sh
prepare_tests 'Check Git version is correct' test_expect_success 'extract Git version from Makefile' '
run_test 'extract Git version from Makefile' '
sed -n -e "/^GIT_VER[ ]*=/ { sed -n -e "/^GIT_VER[ ]*=/ {
s/^GIT_VER[ ]*=[ ]*// s/^GIT_VER[ ]*=[ ]*//
p p
}" ../Makefile >trash/makefile_version }" ../../Makefile >makefile_version
' '
run_test 'test Git version matches Makefile' ' test_expect_success 'test Git version matches Makefile' '
( cat ../git/GIT-VERSION-FILE || echo "No GIT-VERSION-FILE" ) | ( cat ../../git/GIT-VERSION-FILE || echo "No GIT-VERSION-FILE" ) |
sed -e "s/GIT_VERSION[ ]*=[ ]*//" >trash/git_version && sed -e "s/GIT_VERSION[ ]*=[ ]*//" >git_version &&
diff -u trash/git_version trash/makefile_version test_cmp git_version makefile_version
' '
run_test 'test submodule version matches Makefile' ' test_expect_success 'test submodule version matches Makefile' '
if ! test -e ../git/.git if ! test -e ../../git/.git
then then
echo "git/ is not a Git repository" >&2 echo "git/ is not a Git repository" >&2
else else
( (
cd .. && cd ../.. &&
sm_sha1=$(git ls-files --stage -- git | sm_sha1=$(git ls-files --stage -- git |
sed -e "s/^[0-9]* \\([0-9a-f]*\\) [0-9] .*$/\\1/") && sed -e "s/^[0-9]* \\([0-9a-f]*\\) [0-9] .*$/\\1/") &&
cd git && cd git &&
git describe --match "v[0-9]*" $sm_sha1 git describe --match "v[0-9]*" $sm_sha1
) | sed -e "s/^v//" >trash/sm_version && ) | sed -e "s/^v//" >sm_version &&
diff -u trash/sm_version trash/makefile_version test_cmp sm_version makefile_version
fi fi
' '
tests_done test_done

View File

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
test_description='Validate html with tidy'
. ./setup.sh . ./setup.sh
@ -7,9 +8,9 @@ test_url()
{ {
tidy_opt="-eq" tidy_opt="-eq"
test -z "$NO_TIDY_WARNINGS" || tidy_opt+=" --show-warnings no" test -z "$NO_TIDY_WARNINGS" || tidy_opt+=" --show-warnings no"
cgit_url "$1" >trash/tidy-$test_count || return cgit_url "$1" >tidy-$test_count || return
sed -ie "1,4d" trash/tidy-$test_count || return sed -ie "1,4d" tidy-$test_count || return
"$tidy" $tidy_opt trash/tidy-$test_count "$tidy" $tidy_opt tidy-$test_count
rc=$? rc=$?
# tidy returns with exitcode 1 on warnings, 2 on error # tidy returns with exitcode 1 on warnings, 2 on error
@ -21,21 +22,19 @@ test_url()
fi fi
} }
prepare_tests 'Validate html with tidy' tidy=`which tidy 2>/dev/null`
tidy=`which tidy`
test -n "$tidy" || { test -n "$tidy" || {
echo "Skipping tests: tidy not found" skip_all='Skipping html validation tests: tidy not found'
tests_done test_done
exit exit
} }
run_test 'index page' 'test_url ""' test_expect_success 'index page' 'test_url ""'
run_test 'foo' 'test_url "foo"' test_expect_success 'foo' 'test_url "foo"'
run_test 'foo/log' 'test_url "foo/log"' test_expect_success 'foo/log' 'test_url "foo/log"'
run_test 'foo/tree' 'test_url "foo/tree"' test_expect_success 'foo/tree' 'test_url "foo/tree"'
run_test 'foo/tree/file-1' 'test_url "foo/tree/file-1"' test_expect_success 'foo/tree/file-1' 'test_url "foo/tree/file-1"'
run_test 'foo/commit' 'test_url "foo/commit"' test_expect_success 'foo/commit' 'test_url "foo/commit"'
run_test 'foo/diff' 'test_url "foo/diff"' test_expect_success 'foo/diff' 'test_url "foo/diff"'
tests_done test_done

View File

@ -1,13 +1,12 @@
#!/bin/sh #!/bin/sh
test_description='Validate cache'
. ./setup.sh . ./setup.sh
prepare_tests 'Validate cache' test_expect_success 'verify cache-size=0' '
run_test 'verify cache-size=0' ' rm -f cache/* &&
sed -i -e "s/cache-size=1021$/cache-size=0/" cgitrc &&
rm -f trash/cache/* &&
sed -i -e "s/cache-size=1021$/cache-size=0/" trash/cgitrc &&
cgit_url "" && cgit_url "" &&
cgit_url "foo" && cgit_url "foo" &&
cgit_url "foo/refs" && cgit_url "foo/refs" &&
@ -21,13 +20,14 @@ run_test 'verify cache-size=0' '
cgit_url "bar/log" && cgit_url "bar/log" &&
cgit_url "bar/diff" && cgit_url "bar/diff" &&
cgit_url "bar/patch" && cgit_url "bar/patch" &&
test 0 -eq $(ls trash/cache | wc -l) ls cache >output &&
test_line_count = 0 output
' '
run_test 'verify cache-size=1' ' test_expect_success 'verify cache-size=1' '
rm -f trash/cache/* && rm -f cache/* &&
sed -i -e "s/cache-size=0$/cache-size=1/" trash/cgitrc && sed -i -e "s/cache-size=0$/cache-size=1/" cgitrc &&
cgit_url "" && cgit_url "" &&
cgit_url "foo" && cgit_url "foo" &&
cgit_url "foo/refs" && cgit_url "foo/refs" &&
@ -41,13 +41,14 @@ run_test 'verify cache-size=1' '
cgit_url "bar/log" && cgit_url "bar/log" &&
cgit_url "bar/diff" && cgit_url "bar/diff" &&
cgit_url "bar/patch" && cgit_url "bar/patch" &&
test 1 -eq $(ls trash/cache | wc -l) ls cache >output &&
test_line_count = 1 output
' '
run_test 'verify cache-size=1021' ' test_expect_success 'verify cache-size=1021' '
rm -f trash/cache/* && rm -f cache/* &&
sed -i -e "s/cache-size=1$/cache-size=1021/" trash/cgitrc && sed -i -e "s/cache-size=1$/cache-size=1021/" cgitrc &&
cgit_url "" && cgit_url "" &&
cgit_url "foo" && cgit_url "foo" &&
cgit_url "foo/refs" && cgit_url "foo/refs" &&
@ -61,7 +62,8 @@ run_test 'verify cache-size=1021' '
cgit_url "bar/log" && cgit_url "bar/log" &&
cgit_url "bar/diff" && cgit_url "bar/diff" &&
cgit_url "bar/patch" && cgit_url "bar/patch" &&
test 13 -eq $(ls trash/cache | wc -l) ls cache >output &&
test_line_count = 13 output
' '
tests_done test_done

View File

@ -1,18 +1,17 @@
#!/bin/sh #!/bin/sh
test_description='Check content on index page'
. ./setup.sh . ./setup.sh
prepare_tests "Check content on index page" test_expect_success 'generate index page' 'cgit_url "" >tmp'
test_expect_success 'find foo repo' 'grep "foo" tmp'
test_expect_success 'find foo description' 'grep "\[no description\]" tmp'
test_expect_success 'find bar repo' 'grep "bar" tmp'
test_expect_success 'find bar description' 'grep "the bar repo" tmp'
test_expect_success 'find foo+bar repo' 'grep ">foo+bar<" tmp'
test_expect_success 'verify foo+bar link' 'grep "/foo+bar/" tmp'
test_expect_success 'verify "with%20space" link' 'grep "/with%20space/" tmp'
test_expect_success 'no tree-link' '! grep "foo/tree" tmp'
test_expect_success 'no log-link' '! grep "foo/log" tmp'
run_test 'generate index page' 'cgit_url "" >trash/tmp' test_done
run_test 'find foo repo' 'grep "foo" trash/tmp'
run_test 'find foo description' 'grep "\[no description\]" trash/tmp'
run_test 'find bar repo' 'grep "bar" trash/tmp'
run_test 'find bar description' 'grep "the bar repo" trash/tmp'
run_test 'find foo+bar repo' 'grep ">foo+bar<" trash/tmp'
run_test 'verify foo+bar link' 'grep "/foo+bar/" trash/tmp'
run_test 'verify "with%20space" link' 'grep "/with%20space/" trash/tmp'
run_test 'no tree-link' '! grep "foo/tree" trash/tmp'
run_test 'no log-link' '! grep "foo/log" trash/tmp'
tests_done

View File

@ -1,26 +1,25 @@
#!/bin/sh #!/bin/sh
test_description='Check content on summary page'
. ./setup.sh . ./setup.sh
prepare_tests "Check content on summary page" test_expect_success 'generate foo summary' 'cgit_url "foo" >tmp'
test_expect_success 'find commit 1' 'grep "commit 1" tmp'
run_test 'generate foo summary' 'cgit_url "foo" >trash/tmp' test_expect_success 'find commit 5' 'grep "commit 5" tmp'
run_test 'find commit 1' 'grep "commit 1" trash/tmp' test_expect_success 'find branch master' 'grep "master" tmp'
run_test 'find commit 5' 'grep "commit 5" trash/tmp' test_expect_success 'no tags' '! grep "tags" tmp'
run_test 'find branch master' 'grep "master" trash/tmp' test_expect_success 'clone-url expanded correctly' '
run_test 'no tags' '! grep "tags" trash/tmp' grep "git://example.org/foo.git" tmp
run_test 'clone-url expanded correctly' '
grep "git://example.org/foo.git" trash/tmp
' '
run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp' test_expect_success 'generate bar summary' 'cgit_url "bar" >tmp'
run_test 'no commit 45' '! grep "commit 45" trash/tmp' test_expect_success 'no commit 45' '! grep "commit 45" tmp'
run_test 'find commit 46' 'grep "commit 46" trash/tmp' test_expect_success 'find commit 46' 'grep "commit 46" tmp'
run_test 'find commit 50' 'grep "commit 50" trash/tmp' test_expect_success 'find commit 50' 'grep "commit 50" tmp'
run_test 'find branch master' 'grep "master" trash/tmp' test_expect_success 'find branch master' 'grep "master" tmp'
run_test 'no tags' '! grep "tags" trash/tmp' test_expect_success 'no tags' '! grep "tags" tmp'
run_test 'clone-url expanded correctly' ' test_expect_success 'clone-url expanded correctly' '
grep "git://example.org/bar.git" trash/tmp grep "git://example.org/bar.git" tmp
' '
tests_done test_done

View File

@ -1,25 +1,24 @@
#!/bin/sh #!/bin/sh
test_description='Check content on log page'
. ./setup.sh . ./setup.sh
prepare_tests "Check content on log page" test_expect_success 'generate foo/log' 'cgit_url "foo/log" >tmp'
test_expect_success 'find commit 1' 'grep "commit 1" tmp'
test_expect_success 'find commit 5' 'grep "commit 5" tmp'
run_test 'generate foo/log' 'cgit_url "foo/log" >trash/tmp' test_expect_success 'generate bar/log' 'cgit_url "bar/log" >tmp'
run_test 'find commit 1' 'grep "commit 1" trash/tmp' test_expect_success 'find commit 1' 'grep "commit 1" tmp'
run_test 'find commit 5' 'grep "commit 5" trash/tmp' test_expect_success 'find commit 50' 'grep "commit 50" tmp'
run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp' test_expect_success 'generate "with%20space/log?qt=grep&q=commit+1"' '
run_test 'find commit 1' 'grep "commit 1" trash/tmp' cgit_url "with+space/log&qt=grep&q=commit+1" >tmp
run_test 'find commit 50' 'grep "commit 50" trash/tmp'
run_test 'generate "with%20space/log?qt=grep&q=commit+1"' '
cgit_url "with+space/log&qt=grep&q=commit+1" >trash/tmp
' '
run_test 'find commit 1' 'grep "commit 1" trash/tmp' test_expect_success 'find commit 1' 'grep "commit 1" tmp'
run_test 'find link with %20 in path' 'grep "/with%20space/log/?qt=grep" trash/tmp' test_expect_success 'find link with %20 in path' 'grep "/with%20space/log/?qt=grep" tmp'
run_test 'find link with + in arg' 'grep "/log/?qt=grep&amp;q=commit+1" trash/tmp' test_expect_success 'find link with + in arg' 'grep "/log/?qt=grep&amp;q=commit+1" tmp'
run_test 'no links with space in path' '! grep "href=./with space/" trash/tmp' test_expect_success 'no links with space in path' '! grep "href=./with space/" tmp'
run_test 'no links with space in arg' '! grep "q=commit 1" trash/tmp' test_expect_success 'no links with space in arg' '! grep "q=commit 1" tmp'
run_test 'commit 2 is not visible' '! grep "commit 2" trash/tmp' test_expect_success 'commit 2 is not visible' '! grep "commit 2" tmp'
tests_done test_done

View File

@ -1,33 +1,32 @@
#!/bin/sh #!/bin/sh
test_description='Check content on tree page'
. ./setup.sh . ./setup.sh
prepare_tests "Check content on tree page" test_expect_success 'generate bar/tree' 'cgit_url "bar/tree" >tmp'
test_expect_success 'find file-1' 'grep "file-1" tmp'
test_expect_success 'find file-50' 'grep "file-50" tmp'
run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp' test_expect_success 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >tmp'
run_test 'find file-1' 'grep "file-1" trash/tmp'
run_test 'find file-50' 'grep "file-50" trash/tmp'
run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp' test_expect_success 'find line 1' '
grep "<a class=.no. id=.n1. name=.n1. href=.#n1.>1</a>" tmp
run_test 'find line 1' '
grep "<a class=.no. id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp
' '
run_test 'no line 2' ' test_expect_success 'no line 2' '
! grep "<a class=.no. id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp ! grep "<a class=.no. id=.n2. name=.n2. href=.#n2.>2</a>" tmp
' '
run_test 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >trash/tmp' test_expect_success 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >tmp'
run_test 'verify a+b link' ' test_expect_success 'verify a+b link' '
grep "/foo+bar/tree/a+b" trash/tmp grep "/foo+bar/tree/a+b" tmp
' '
run_test 'generate foo+bar/tree?h=1+2' 'cgit_url "foo%2bbar/tree&h=1%2b2" >trash/tmp' test_expect_success 'generate foo+bar/tree?h=1+2' 'cgit_url "foo%2bbar/tree&h=1%2b2" >tmp'
run_test 'verify a+b?h=1+2 link' ' test_expect_success 'verify a+b?h=1+2 link' '
grep "/foo+bar/tree/a+b?h=1%2b2" trash/tmp grep "/foo+bar/tree/a+b?h=1%2b2" tmp
' '
tests_done test_done

View File

@ -1,37 +1,36 @@
#!/bin/sh #!/bin/sh
test_description='Check content on commit page'
. ./setup.sh . ./setup.sh
prepare_tests "Check content on commit page" test_expect_success 'generate foo/commit' 'cgit_url "foo/commit" >tmp'
test_expect_success 'find tree link' 'grep "<a href=./foo/tree/.>" tmp'
test_expect_success 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" tmp'
run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp' test_expect_success 'find commit subject' '
run_test 'find tree link' 'grep "<a href=./foo/tree/.>" trash/tmp' grep "<div class=.commit-subject.>commit 5<" tmp
run_test 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" trash/tmp'
run_test 'find commit subject' '
grep "<div class=.commit-subject.>commit 5<" trash/tmp
' '
run_test 'find commit msg' 'grep "<div class=.commit-msg.></div>" trash/tmp' test_expect_success 'find commit msg' 'grep "<div class=.commit-msg.></div>" tmp'
run_test 'find diffstat' 'grep "<table summary=.diffstat. class=.diffstat.>" trash/tmp' test_expect_success 'find diffstat' 'grep "<table summary=.diffstat. class=.diffstat.>" tmp'
run_test 'find diff summary' ' test_expect_success 'find diff summary' '
grep "1 files changed, 1 insertions, 0 deletions" trash/tmp grep "1 files changed, 1 insertions, 0 deletions" tmp
' '
run_test 'get root commit' ' test_expect_success 'get root commit' '
root=$(cd trash/repos/foo && git rev-list --reverse HEAD | head -1) && root=$(cd repos/foo && git rev-list --reverse HEAD | head -1) &&
cgit_url "foo/commit&id=$root" >trash/tmp && cgit_url "foo/commit&id=$root" >tmp &&
grep "</html>" trash/tmp grep "</html>" tmp
' '
run_test 'root commit contains diffstat' ' test_expect_success 'root commit contains diffstat' '
grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40\}.>file-1</a>" trash/tmp grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40\}.>file-1</a>" tmp
' '
run_test 'root commit contains diff' ' test_expect_success 'root commit contains diff' '
grep ">diff --git a/file-1 b/file-1<" trash/tmp && grep ">diff --git a/file-1 b/file-1<" tmp &&
grep "<div class=.add.>+1</div>" trash/tmp grep "<div class=.add.>+1</div>" tmp
' '
tests_done test_done

View File

@ -1,20 +1,19 @@
#!/bin/sh #!/bin/sh
test_description='Check content on diff page'
. ./setup.sh . ./setup.sh
prepare_tests "Check content on diff page" test_expect_success 'generate foo/diff' 'cgit_url "foo/diff" >tmp'
test_expect_success 'find diff header' 'grep "a/file-5 b/file-5" tmp'
test_expect_success 'find blob link' 'grep "<a href=./foo/tree/file-5?id=" tmp'
test_expect_success 'find added file' 'grep "new file mode 100644" tmp'
run_test 'generate foo/diff' 'cgit_url "foo/diff" >trash/tmp' test_expect_success 'find hunk header' '
run_test 'find diff header' 'grep "a/file-5 b/file-5" trash/tmp' grep "<div class=.hunk.>@@ -0,0 +1 @@</div>" tmp
run_test 'find blob link' 'grep "<a href=./foo/tree/file-5?id=" trash/tmp'
run_test 'find added file' 'grep "new file mode 100644" trash/tmp'
run_test 'find hunk header' '
grep "<div class=.hunk.>@@ -0,0 +1 @@</div>" trash/tmp
' '
run_test 'find added line' ' test_expect_success 'find added line' '
grep "<div class=.add.>+5</div>" trash/tmp grep "<div class=.add.>+5</div>" tmp
' '
tests_done test_done

View File

@ -1,77 +1,76 @@
#!/bin/sh #!/bin/sh
test_description='Verify snapshot'
. ./setup.sh . ./setup.sh
prepare_tests "Verify snapshot" test_expect_success 'get foo/snapshot/master.tar.gz' '
cgit_url "foo/snapshot/master.tar.gz" >tmp
run_test 'get foo/snapshot/master.tar.gz' '
cgit_url "foo/snapshot/master.tar.gz" >trash/tmp
' '
run_test 'check html headers' ' test_expect_success 'check html headers' '
head -n 1 trash/tmp | head -n 1 tmp |
grep "Content-Type: application/x-gzip" && grep "Content-Type: application/x-gzip" &&
head -n 2 trash/tmp | head -n 2 tmp |
grep "Content-Disposition: inline; filename=.master.tar.gz." grep "Content-Disposition: inline; filename=.master.tar.gz."
' '
run_test 'strip off the header lines' ' test_expect_success 'strip off the header lines' '
tail -n +6 trash/tmp > trash/master.tar.gz tail -n +6 tmp > master.tar.gz
' '
run_test 'verify gzip format' ' test_expect_success 'verify gzip format' '
gunzip --test trash/master.tar.gz gunzip --test master.tar.gz
' '
run_test 'untar' ' test_expect_success 'untar' '
rm -rf trash/master && rm -rf master &&
tar -xf trash/master.tar.gz -C trash tar -xf master.tar.gz
' '
run_test 'count files' ' test_expect_success 'count files' '
c=$(ls -1 trash/master/ | wc -l) && ls master/ >output &&
test $c = 5 test_line_count = 5 output
' '
run_test 'verify untarred file-5' ' test_expect_success 'verify untarred file-5' '
grep "^5$" trash/master/file-5 && grep "^5$" master/file-5 &&
test $(cat trash/master/file-5 | wc -l) = 1 test_line_count = 1 master/file-5
' '
run_test 'get foo/snapshot/master.zip' ' test_expect_success 'get foo/snapshot/master.zip' '
cgit_url "foo/snapshot/master.zip" >trash/tmp cgit_url "foo/snapshot/master.zip" >tmp
' '
run_test 'check HTML headers (zip)' ' test_expect_success 'check HTML headers (zip)' '
head -n 1 trash/tmp | head -n 1 tmp |
grep "Content-Type: application/x-zip" && grep "Content-Type: application/x-zip" &&
head -n 2 trash/tmp | head -n 2 tmp |
grep "Content-Disposition: inline; filename=.master.zip." grep "Content-Disposition: inline; filename=.master.zip."
' '
run_test 'strip off the header lines (zip)' ' test_expect_success 'strip off the header lines (zip)' '
tail -n +6 trash/tmp >trash/master.zip tail -n +6 tmp >master.zip
' '
run_test 'verify zip format' ' test_expect_success 'verify zip format' '
unzip -t trash/master.zip unzip -t master.zip
' '
run_test 'unzip' ' test_expect_success 'unzip' '
rm -rf trash/master && rm -rf master &&
unzip trash/master.zip -d trash unzip master.zip
' '
run_test 'count files (zip)' ' test_expect_success 'count files (zip)' '
c=$(ls -1 trash/master/ | wc -l) && ls master/ >output &&
test $c = 5 test_line_count = 5 output
' '
run_test 'verify unzipped file-5' ' test_expect_success 'verify unzipped file-5' '
grep "^5$" trash/master/file-5 && grep "^5$" master/file-5 &&
test $(cat trash/master/file-5 | wc -l) = 1 test_line_count = 1 master/file-5
' '
tests_done test_done

View File

@ -1,39 +1,38 @@
#!/bin/sh #!/bin/sh
test_description='Check content on patch page'
. ./setup.sh . ./setup.sh
prepare_tests "Check content on patch page" test_expect_success 'generate foo/patch' '
cgit_query "url=foo/patch" >tmp
run_test 'generate foo/patch' '
cgit_query "url=foo/patch" >trash/tmp
' '
run_test 'find `From:` line' ' test_expect_success 'find `From:` line' '
grep "^From: " trash/tmp grep "^From: " tmp
' '
run_test 'find `Date:` line' ' test_expect_success 'find `Date:` line' '
grep "^Date: " trash/tmp grep "^Date: " tmp
' '
run_test 'find `Subject:` line' ' test_expect_success 'find `Subject:` line' '
grep "^Subject: commit 5" trash/tmp grep "^Subject: commit 5" tmp
' '
run_test 'find `cgit` signature' ' test_expect_success 'find `cgit` signature' '
tail -1 trash/tmp | grep "^cgit" tail -1 tmp | grep "^cgit"
' '
run_test 'find initial commit' ' test_expect_success 'find initial commit' '
root=$(git --git-dir="$PWD/trash/repos/foo/.git" rev-list HEAD | tail -1) root=$(git --git-dir="$PWD/repos/foo/.git" rev-list HEAD | tail -1)
' '
run_test 'generate patch for initial commit' ' test_expect_success 'generate patch for initial commit' '
cgit_query "url=foo/patch&id=$root" >trash/tmp cgit_query "url=foo/patch&id=$root" >tmp
' '
run_test 'find `cgit` signature' ' test_expect_success 'find `cgit` signature' '
tail -1 trash/tmp | grep "^cgit" tail -1 tmp | grep "^cgit"
' '
tests_done test_done