-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | tests/.gitignore | 2 | ||||
-rw-r--r-- | tests/Makefile | 13 | ||||
-rwxr-xr-x | tests/setup.sh | 108 | ||||
-rwxr-xr-x | tests/t0010-validate-html.sh | 31 | ||||
-rwxr-xr-x | tests/t0101-index.sh | 13 | ||||
-rwxr-xr-x | tests/t0102-summary.sh | 20 | ||||
-rwxr-xr-x | tests/t0103-log.sh | 15 | ||||
-rwxr-xr-x | tests/t0104-tree.sh | 15 | ||||
-rwxr-xr-x | tests/t0105-commit.sh | 22 | ||||
-rwxr-xr-x | tests/t0106-diff.sh | 20 | ||||
-rwxr-xr-x | tests/t0107-snapshot.sh | 36 |
12 files changed, 299 insertions, 1 deletions
@@ -1,80 +1,83 @@ | |||
1 | CGIT_VERSION = v0.7.1 | 1 | CGIT_VERSION = v0.7.1 |
2 | CGIT_SCRIPT_NAME = cgit.cgi | 2 | CGIT_SCRIPT_NAME = cgit.cgi |
3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit | 3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit |
4 | CGIT_CONFIG = /etc/cgitrc | 4 | CGIT_CONFIG = /etc/cgitrc |
5 | CACHE_ROOT = /var/cache/cgit | 5 | CACHE_ROOT = /var/cache/cgit |
6 | SHA1_HEADER = <openssl/sha.h> | 6 | SHA1_HEADER = <openssl/sha.h> |
7 | GIT_VER = 1.5.3.5 | 7 | GIT_VER = 1.5.3.5 |
8 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | 8 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 |
9 | 9 | ||
10 | # | 10 | # |
11 | # Let the user override the above settings. | 11 | # Let the user override the above settings. |
12 | # | 12 | # |
13 | -include cgit.conf | 13 | -include cgit.conf |
14 | 14 | ||
15 | 15 | ||
16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto |
17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ | 18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ |
19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o | 19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o |
20 | 20 | ||
21 | 21 | ||
22 | ifdef NEEDS_LIBICONV | 22 | ifdef NEEDS_LIBICONV |
23 | EXTLIBS += -liconv | 23 | EXTLIBS += -liconv |
24 | endif | 24 | endif |
25 | 25 | ||
26 | 26 | ||
27 | .PHONY: all git install clean distclean emptycache force-version get-git | 27 | .PHONY: all git test install clean distclean emptycache force-version get-git |
28 | 28 | ||
29 | all: cgit git | 29 | all: cgit git |
30 | 30 | ||
31 | VERSION: force-version | 31 | VERSION: force-version |
32 | @./gen-version.sh "$(CGIT_VERSION)" | 32 | @./gen-version.sh "$(CGIT_VERSION)" |
33 | -include VERSION | 33 | -include VERSION |
34 | 34 | ||
35 | 35 | ||
36 | CFLAGS += -g -Wall -Igit | 36 | CFLAGS += -g -Wall -Igit |
37 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 37 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
38 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 38 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
39 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 39 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
40 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 40 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
42 | 42 | ||
43 | 43 | ||
44 | cgit: cgit.c $(OBJECTS) | 44 | cgit: cgit.c $(OBJECTS) |
45 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) | 45 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) |
46 | 46 | ||
47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION | 47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION |
48 | 48 | ||
49 | git/xdiff/lib.a: | git | 49 | git/xdiff/lib.a: | git |
50 | 50 | ||
51 | git/libgit.a: | git | 51 | git/libgit.a: | git |
52 | 52 | ||
53 | git: | 53 | git: |
54 | cd git && $(MAKE) xdiff/lib.a | 54 | cd git && $(MAKE) xdiff/lib.a |
55 | cd git && $(MAKE) libgit.a | 55 | cd git && $(MAKE) libgit.a |
56 | 56 | ||
57 | test: all | ||
58 | $(MAKE) -C tests | ||
59 | |||
57 | install: all | 60 | install: all |
58 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) | 61 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) |
59 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 62 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
60 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css | 63 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css |
61 | install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png | 64 | install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png |
62 | 65 | ||
63 | uninstall: | 66 | uninstall: |
64 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 67 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
65 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css | 68 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css |
66 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png | 69 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png |
67 | 70 | ||
68 | clean: | 71 | clean: |
69 | rm -f cgit VERSION *.o | 72 | rm -f cgit VERSION *.o |
70 | cd git && $(MAKE) clean | 73 | cd git && $(MAKE) clean |
71 | 74 | ||
72 | distclean: clean | 75 | distclean: clean |
73 | git clean -d -x | 76 | git clean -d -x |
74 | cd git && git clean -d -x | 77 | cd git && git clean -d -x |
75 | 78 | ||
76 | emptycache: | 79 | emptycache: |
77 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* | 80 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* |
78 | 81 | ||
79 | get-git: | 82 | get-git: |
80 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git | 83 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git |
diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..c1c1c0b --- a/dev/null +++ b/tests/.gitignore | |||
@@ -0,0 +1,2 @@ | |||
1 | trash | ||
2 | test-output.log | ||
diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..697e5a1 --- a/dev/null +++ b/tests/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | |||
2 | |||
3 | T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) | ||
4 | |||
5 | all: $(T) | ||
6 | |||
7 | $(T): | ||
8 | @$@ | ||
9 | |||
10 | clean: | ||
11 | $(RM) -rf trash | ||
12 | |||
13 | .PHONY: $(T) clean | ||
diff --git a/tests/setup.sh b/tests/setup.sh new file mode 100755 index 0000000..51d5a75 --- a/dev/null +++ b/tests/setup.sh | |||
@@ -0,0 +1,108 @@ | |||
1 | # This file should be sourced by all test-scripts | ||
2 | # | ||
3 | # Main functions: | ||
4 | # prepare_tests(description) - setup for testing, i.e. create repos+config | ||
5 | # run_test(description, script) - run one test, i.e. eval script | ||
6 | # | ||
7 | # Helper functions | ||
8 | # cgit_query(querystring) - call cgit with the specified querystring | ||
9 | # cgit_url(url) - call cgit with the specified virtual url | ||
10 | # | ||
11 | # Example script: | ||
12 | # | ||
13 | # . setup.sh | ||
14 | # prepare_tests "html validation" | ||
15 | # run_test 'repo index' 'cgit_url "/" | tidy -e' | ||
16 | # run_test 'repo summary' 'cgit_url "/foo" | tidy -e' | ||
17 | |||
18 | |||
19 | mkrepo() { | ||
20 | name=$1 | ||
21 | count=$2 | ||
22 | dir=$PWD | ||
23 | test -d $name && return | ||
24 | printf "Creating testrepo %s\n" $name | ||
25 | mkdir -p $name | ||
26 | cd $name | ||
27 | git init | ||
28 | for ((n=1; n<=count; n++)) | ||
29 | do | ||
30 | echo $n >file-$n | ||
31 | git add file-$n | ||
32 | git commit -m "commit $n" | ||
33 | done | ||
34 | cd $dir | ||
35 | } | ||
36 | |||
37 | setup_repos() | ||
38 | { | ||
39 | rm -rf trash/cache | ||
40 | mkdir -p trash/cache | ||
41 | mkrepo trash/repos/foo 5 >/dev/null | ||
42 | mkrepo trash/repos/bar 50 >/dev/null | ||
43 | cat >trash/cgitrc <<EOF | ||
44 | virtual-root=/ | ||
45 | cache-root=$PWD/trash/cache | ||
46 | |||
47 | nocache=0 | ||
48 | snapshots=tar.gz tar.bz zip | ||
49 | enable-log-filecount=1 | ||
50 | enable-log-linecount=1 | ||
51 | summary-log=5 | ||
52 | summary-branches=5 | ||
53 | summary-tags=5 | ||
54 | |||
55 | repo.url=foo | ||
56 | repo.path=$PWD/trash/repos/foo/.git | ||
57 | repo.desc=the foo repo | ||
58 | |||
59 | repo.url=bar | ||
60 | repo.path=$PWD/trash/repos/bar/.git | ||
61 | repo.desc=the bar repo | ||
62 | EOF | ||
63 | } | ||
64 | |||
65 | prepare_tests() | ||
66 | { | ||
67 | setup_repos | ||
68 | test_count=0 | ||
69 | test_failed=0 | ||
70 | echo "$@" "($0)" | ||
71 | } | ||
72 | |||
73 | tests_done() | ||
74 | { | ||
75 | printf "\n" | ||
76 | if test $test_failed -gt 0 | ||
77 | then | ||
78 | printf "[%s of %s tests failed]\n" $test_failed $test_count | ||
79 | false | ||
80 | fi | ||
81 | } | ||
82 | |||
83 | run_test() | ||
84 | { | ||
85 | desc=$1 | ||
86 | script=$2 | ||
87 | ((test_count++)) | ||
88 | eval "$2" >test-output.log | ||
89 | res=$? | ||
90 | if test $res = 0 | ||
91 | then | ||
92 | printf " %s: ok - %s\n" $test_count "$desc" | ||
93 | else | ||
94 | ((test_failed++)) | ||
95 | printf " %s: fail - %s\n" $test_count "$desc" | ||
96 | fi | ||
97 | } | ||
98 | |||
99 | cgit_query() | ||
100 | { | ||
101 | CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit" | ||
102 | } | ||
103 | |||
104 | cgit_url() | ||
105 | { | ||
106 | CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit" | ||
107 | } | ||
108 | |||
diff --git a/tests/t0010-validate-html.sh b/tests/t0010-validate-html.sh new file mode 100755 index 0000000..907a415 --- a/dev/null +++ b/tests/t0010-validate-html.sh | |||
@@ -0,0 +1,31 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | |||
6 | test_url() | ||
7 | { | ||
8 | tidy_opt="-eq" | ||
9 | test -z "$NO_TIDY_WARNINGS" || tidy_opt+=" --show-warnings no" | ||
10 | cgit_url "$1" | sed -e "1,4d" >trash/tidy-$test_count | ||
11 | tidy $tidy_opt trash/tidy-$test_count | ||
12 | rc=$? | ||
13 | if test $rc = 2 | ||
14 | then | ||
15 | false | ||
16 | else | ||
17 | : | ||
18 | fi | ||
19 | } | ||
20 | |||
21 | prepare_tests 'Validate html with tidy' | ||
22 | |||
23 | run_test 'index page' 'test_url ""' | ||
24 | run_test 'foo' 'test_url "foo"' | ||
25 | run_test 'foo/log' 'test_url "foo/log"' | ||
26 | run_test 'foo/tree' 'test_url "foo/tree"' | ||
27 | run_test 'foo/tree/file-1' 'test_url "foo/tree/file-1"' | ||
28 | run_test 'foo/commit' 'test_url "foo/commit"' | ||
29 | run_test 'foo/diff' 'test_url "foo/diff"' | ||
30 | |||
31 | tests_done | ||
diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh new file mode 100755 index 0000000..12ed00c --- a/dev/null +++ b/tests/t0101-index.sh | |||
@@ -0,0 +1,13 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on index page" | ||
6 | |||
7 | run_test 'generate index page' 'cgit_url "" >trash/tmp' | ||
8 | run_test 'find foo repo' 'grep -e "foo" trash/tmp' | ||
9 | run_test 'find bar repo' 'grep -e "bar" trash/tmp' | ||
10 | run_test 'no tree-link' 'grep -ve "foo/tree" trash/tmp' | ||
11 | run_test 'no log-link' 'grep -ve "foo/log" trash/tmp' | ||
12 | |||
13 | tests_done | ||
diff --git a/tests/t0102-summary.sh b/tests/t0102-summary.sh new file mode 100755 index 0000000..7edd675 --- a/dev/null +++ b/tests/t0102-summary.sh | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on summary page" | ||
6 | |||
7 | run_test 'generate foo summary' 'cgit_url "foo" >trash/tmp' | ||
8 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
9 | run_test 'find commit 5' 'grep -e "commit 5" trash/tmp' | ||
10 | run_test 'find branch master' 'grep -e "master" trash/tmp' | ||
11 | run_test 'no tags' 'grep -ve "tags" trash/tmp' | ||
12 | |||
13 | run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp' | ||
14 | run_test 'no commit 45' 'grep -ve "commit 45" trash/tmp' | ||
15 | run_test 'find commit 46' 'grep -e "commit 46" trash/tmp' | ||
16 | run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' | ||
17 | run_test 'find branch master' 'grep -e "master" trash/tmp' | ||
18 | run_test 'no tags' 'grep -ve "tags" trash/tmp' | ||
19 | |||
20 | tests_done | ||
diff --git a/tests/t0103-log.sh b/tests/t0103-log.sh new file mode 100755 index 0000000..b08cd29 --- a/dev/null +++ b/tests/t0103-log.sh | |||
@@ -0,0 +1,15 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on log page" | ||
6 | |||
7 | run_test 'generate foo/log' 'cgit_url "foo/log" >trash/tmp' | ||
8 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
9 | run_test 'find commit 5' 'grep -e "commit 5" trash/tmp' | ||
10 | |||
11 | run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp' | ||
12 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
13 | run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' | ||
14 | |||
15 | tests_done | ||
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh new file mode 100755 index 0000000..9c362ca --- a/dev/null +++ b/tests/t0104-tree.sh | |||
@@ -0,0 +1,15 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on tree page" | ||
6 | |||
7 | run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp' | ||
8 | run_test 'find file-1' 'grep -e "file-1" trash/tmp' | ||
9 | run_test 'find file-50' 'grep -e "file-50" trash/tmp' | ||
10 | |||
11 | run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp' | ||
12 | run_test 'find line 1' 'grep -e "<a name=.1.>1</a>" trash/tmp' | ||
13 | run_test 'no line 2' 'grep -ve "<a name=.2.>2</a>" trash/tmp' | ||
14 | |||
15 | tests_done | ||
diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh new file mode 100755 index 0000000..7137751 --- a/dev/null +++ b/tests/t0105-commit.sh | |||
@@ -0,0 +1,22 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on commit page" | ||
6 | |||
7 | run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp' | ||
8 | run_test 'find tree link' 'grep -e "<a href=./foo/tree/.>" trash/tmp' | ||
9 | run_test 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" trash/tmp' | ||
10 | |||
11 | run_test 'find commit subject' ' | ||
12 | grep -e "<div class=.commit-subject.>commit 5</div>" trash/tmp | ||
13 | ' | ||
14 | |||
15 | run_test 'find commit msg' 'grep -e "<div class=.commit-msg.></div>" trash/tmp' | ||
16 | run_test 'find diffstat' 'grep -e "<table class=.diffstat.>" trash/tmp' | ||
17 | |||
18 | run_test 'find diff summary' ' | ||
19 | grep -e "1 files changed, 1 insertions, 0 deletions" trash/tmp | ||
20 | ' | ||
21 | |||
22 | tests_done | ||
diff --git a/tests/t0106-diff.sh b/tests/t0106-diff.sh new file mode 100755 index 0000000..e140bcc --- a/dev/null +++ b/tests/t0106-diff.sh | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on diff page" | ||
6 | |||
7 | run_test 'generate foo/diff' 'cgit_url "foo/diff" >trash/tmp' | ||
8 | run_test 'find diff header' 'grep -e "a/file-5 b/file-5" trash/tmp' | ||
9 | run_test 'find blob link' 'grep -e "<a href=./foo/tree/file-5?id=" trash/tmp' | ||
10 | run_test 'find added file' 'grep -e "new file mode 100644" trash/tmp' | ||
11 | |||
12 | run_test 'find hunk header' ' | ||
13 | grep -e "<div class=.hunk.>@@ -0,0 +1 @@</div>" trash/tmp | ||
14 | ' | ||
15 | |||
16 | run_test 'find added line' ' | ||
17 | grep -e "<div class=.add.>+5</div>" trash/tmp | ||
18 | ' | ||
19 | |||
20 | tests_done | ||
diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh new file mode 100755 index 0000000..8e90e10 --- a/dev/null +++ b/tests/t0107-snapshot.sh | |||
@@ -0,0 +1,36 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Verify snapshot" | ||
6 | |||
7 | run_test 'get foo/snapshot/test.tar.gz' ' | ||
8 | cgit_url "foo/snapshot/test.tar.gz" >trash/tmp | ||
9 | ' | ||
10 | |||
11 | run_test 'check html headers' ' | ||
12 | head -n 1 trash/tmp | | ||
13 | grep -e "Content-Type: application/x-tar" && | ||
14 | |||
15 | head -n 2 trash/tmp | | ||
16 | grep -e "Content-Disposition: inline; filename=.test.tar.gz." | ||
17 | ' | ||
18 | |||
19 | run_test 'strip off the header lines' ' | ||
20 | tail -n +6 trash/tmp > trash/test.tar.gz | ||
21 | ' | ||
22 | |||
23 | run_test 'verify gzip format' 'gunzip --test trash/test.tar.gz' | ||
24 | run_test 'untar' 'tar -xf trash/test.tar.gz -C trash' | ||
25 | |||
26 | run_test 'count files' ' | ||
27 | c=$(ls -1 trash/foo/ | wc -l) && | ||
28 | test $c = 5 | ||
29 | ' | ||
30 | |||
31 | run_test 'verify untarred file-5' ' | ||
32 | grep -e "^5$" trash/foo/file-5 && | ||
33 | test $(cat trash/foo/file-5 | wc -l) = 1 | ||
34 | ' | ||
35 | |||
36 | tests_done | ||