summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile5
-rw-r--r--cgit.css6
-rw-r--r--html.c2
-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.sh21
-rwxr-xr-xtests/t0105-commit.sh22
-rwxr-xr-xtests/t0106-diff.sh20
-rwxr-xr-xtests/t0107-snapshot.sh36
-rw-r--r--ui-commit.c6
-rw-r--r--ui-diff.c2
-rw-r--r--ui-log.c2
-rw-r--r--ui-repolist.c2
-rw-r--r--ui-shared.c24
-rw-r--r--ui-snapshot.c1
-rw-r--r--ui-summary.c2
-rw-r--r--ui-tree.c6
22 files changed, 334 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 685e662..72c189c 100644
--- a/Makefile
+++ b/Makefile
@@ -26,3 +26,3 @@ endif
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
@@ -56,2 +56,5 @@ git:
56 56
57test: all
58 $(MAKE) -C tests
59
57install: all 60install: all
diff --git a/cgit.css b/cgit.css
index f1003b4..565427f 100644
--- a/cgit.css
+++ b/cgit.css
@@ -113,3 +113,7 @@ div#sidebar div.infobox h1 {
113 font-weight: bold; 113 font-weight: bold;
114 margin: 0px; 114 margin: 8px 0px 0px 0px;
115}
116
117div#sidebar div.infobox h1.first {
118 margin-top: 0px;
115} 119}
diff --git a/html.c b/html.c
index 6c9cc8b..eb163d9 100644
--- a/html.c
+++ b/html.c
@@ -134,3 +134,3 @@ void html_option(char *value, char *text, char *selected_value)
134 if (selected_value && !strcmp(selected_value, value)) 134 if (selected_value && !strcmp(selected_value, value))
135 html(" selected"); 135 html(" selected='selected'");
136 html(">"); 136 html(">");
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 @@
1trash
2test-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
3T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
4
5all: $(T)
6
7$(T):
8 @$@
9
10clean:
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
19mkrepo() {
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
37setup_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
44virtual-root=/
45cache-root=$PWD/trash/cache
46
47nocache=0
48snapshots=tar.gz tar.bz zip
49enable-log-filecount=1
50enable-log-linecount=1
51summary-log=5
52summary-branches=5
53summary-tags=5
54
55repo.url=foo
56repo.path=$PWD/trash/repos/foo/.git
57repo.desc=the foo repo
58
59repo.url=bar
60repo.path=$PWD/trash/repos/bar/.git
61repo.desc=the bar repo
62EOF
63}
64
65prepare_tests()
66{
67 setup_repos
68 test_count=0
69 test_failed=0
70 echo "$@" "($0)"
71}
72
73tests_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
83run_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
99cgit_query()
100{
101 CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit"
102}
103
104cgit_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
6test_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
21prepare_tests 'Validate html with tidy'
22
23run_test 'index page' 'test_url ""'
24run_test 'foo' 'test_url "foo"'
25run_test 'foo/log' 'test_url "foo/log"'
26run_test 'foo/tree' 'test_url "foo/tree"'
27run_test 'foo/tree/file-1' 'test_url "foo/tree/file-1"'
28run_test 'foo/commit' 'test_url "foo/commit"'
29run_test 'foo/diff' 'test_url "foo/diff"'
30
31tests_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
5prepare_tests "Check content on index page"
6
7run_test 'generate index page' 'cgit_url "" >trash/tmp'
8run_test 'find foo repo' 'grep -e "foo" trash/tmp'
9run_test 'find bar repo' 'grep -e "bar" trash/tmp'
10run_test 'no tree-link' 'grep -ve "foo/tree" trash/tmp'
11run_test 'no log-link' 'grep -ve "foo/log" trash/tmp'
12
13tests_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
5prepare_tests "Check content on summary page"
6
7run_test 'generate foo summary' 'cgit_url "foo" >trash/tmp'
8run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
9run_test 'find commit 5' 'grep -e "commit 5" trash/tmp'
10run_test 'find branch master' 'grep -e "master" trash/tmp'
11run_test 'no tags' 'grep -ve "tags" trash/tmp'
12
13run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp'
14run_test 'no commit 45' 'grep -ve "commit 45" trash/tmp'
15run_test 'find commit 46' 'grep -e "commit 46" trash/tmp'
16run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
17run_test 'find branch master' 'grep -e "master" trash/tmp'
18run_test 'no tags' 'grep -ve "tags" trash/tmp'
19
20tests_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
5prepare_tests "Check content on log page"
6
7run_test 'generate foo/log' 'cgit_url "foo/log" >trash/tmp'
8run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
9run_test 'find commit 5' 'grep -e "commit 5" trash/tmp'
10
11run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp'
12run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
13run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
14
15tests_done
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh
new file mode 100755
index 0000000..2516c72
--- a/dev/null
+++ b/tests/t0104-tree.sh
@@ -0,0 +1,21 @@
1#!/bin/sh
2
3. ./setup.sh
4
5prepare_tests "Check content on tree page"
6
7run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp'
8run_test 'find file-1' 'grep -e "file-1" trash/tmp'
9run_test 'find file-50' 'grep -e "file-50" trash/tmp'
10
11run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp'
12
13run_test 'find line 1' '
14 grep -e "<a id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp
15'
16
17run_test 'no line 2' '
18 grep -e "<a id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
19'
20
21tests_done
diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh
new file mode 100755
index 0000000..aa2bf33
--- a/dev/null
+++ b/tests/t0105-commit.sh
@@ -0,0 +1,22 @@
1#!/bin/sh
2
3. ./setup.sh
4
5prepare_tests "Check content on commit page"
6
7run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp'
8run_test 'find tree link' 'grep -e "<a href=./foo/tree/.>" trash/tmp'
9run_test 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" trash/tmp'
10
11run_test 'find commit subject' '
12 grep -e "<div class=.commit-subject.>commit 5</div>" trash/tmp
13'
14
15run_test 'find commit msg' 'grep -e "<div class=.commit-msg.></div>" trash/tmp'
16run_test 'find diffstat' 'grep -e "<table summary=.diffstat. class=.diffstat.>" trash/tmp'
17
18run_test 'find diff summary' '
19 grep -e "1 files changed, 1 insertions, 0 deletions" trash/tmp
20'
21
22tests_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
5prepare_tests "Check content on diff page"
6
7run_test 'generate foo/diff' 'cgit_url "foo/diff" >trash/tmp'
8run_test 'find diff header' 'grep -e "a/file-5 b/file-5" trash/tmp'
9run_test 'find blob link' 'grep -e "<a href=./foo/tree/file-5?id=" trash/tmp'
10run_test 'find added file' 'grep -e "new file mode 100644" trash/tmp'
11
12run_test 'find hunk header' '
13 grep -e "<div class=.hunk.>@@ -0,0 +1 @@</div>" trash/tmp
14'
15
16run_test 'find added line' '
17 grep -e "<div class=.add.>+5</div>" trash/tmp
18'
19
20tests_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
5prepare_tests "Verify snapshot"
6
7run_test 'get foo/snapshot/test.tar.gz' '
8 cgit_url "foo/snapshot/test.tar.gz" >trash/tmp
9'
10
11run_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
19run_test 'strip off the header lines' '
20 tail -n +6 trash/tmp > trash/test.tar.gz
21'
22
23run_test 'verify gzip format' 'gunzip --test trash/test.tar.gz'
24run_test 'untar' 'tar -xf trash/test.tar.gz -C trash'
25
26run_test 'count files' '
27 c=$(ls -1 trash/foo/ | wc -l) &&
28 test $c = 5
29'
30
31run_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
36tests_done
diff --git a/ui-commit.c b/ui-commit.c
index 4ac8955..bd55a33 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -86,3 +86,3 @@ void print_fileinfo(struct fileinfo *info)
86 html("</td><td class='graph'>"); 86 html("</td><td class='graph'>");
87 htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); 87 htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes));
88 htmlf("<td class='add' style='width: %.1f%%;'/>", 88 htmlf("<td class='add' style='width: %.1f%%;'/>",
@@ -159,3 +159,3 @@ void cgit_print_commit(char *hex)
159 159
160 html("<table class='commit-info'>\n"); 160 html("<table summary='commit info' class='commit-info'>\n");
161 html("<tr><th>author</th><td>"); 161 html("<tr><th>author</th><td>");
@@ -211,3 +211,3 @@ void cgit_print_commit(char *hex)
211 html("<div class='diffstat-header'>Diffstat</div>"); 211 html("<div class='diffstat-header'>Diffstat</div>");
212 html("<table class='diffstat'>"); 212 html("<table summary='diffstat' class='diffstat'>");
213 max_changes = 0; 213 max_changes = 0;
diff --git a/ui-diff.c b/ui-diff.c
index ac9a3fa..4fcf852 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -143,3 +143,3 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
143 } 143 }
144 html("<table class='diff'>"); 144 html("<table summary='diff' class='diff'>");
145 html("<tr><td>"); 145 html("<tr><td>");
diff --git a/ui-log.c b/ui-log.c
index e5f3c57..a41d2b2 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -92,3 +92,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
92 92
93 html("<table class='list nowrap'>"); 93 html("<table summary='log' class='list nowrap'>");
94 html("<tr class='nohover'><th class='left'>Age</th>" 94 html("<tr class='nohover'><th class='left'>Age</th>"
diff --git a/ui-repolist.c b/ui-repolist.c
index 9aa5c1e..3e97ca9 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -55,3 +55,3 @@ void cgit_print_repolist(struct cacheitem *item)
55 55
56 html("<table class='list nowrap'>"); 56 html("<table summary='repository list' class='list nowrap'>");
57 if (cgit_index_header) { 57 if (cgit_index_header) {
diff --git a/ui-shared.c b/ui-shared.c
index 7c69f60..9ec646b 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -360,3 +360,3 @@ void cgit_print_docstart(char *title, struct cacheitem *item)
360 html(cgit_doctype); 360 html(cgit_doctype);
361 html("<html>\n"); 361 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
362 html("<head>\n"); 362 html("<head>\n");
@@ -375,3 +375,3 @@ void cgit_print_docend()
375{ 375{
376 html("</td>\n</tr>\n<table>\n</body>\n</html>\n"); 376 html("</td>\n</tr>\n</table>\n</body>\n</html>\n");
377} 377}
@@ -458,5 +458,5 @@ void cgit_print_pageheader(char *title, int show_search)
458 html("<div id='sidebar'>\n"); 458 html("<div id='sidebar'>\n");
459 html("<a href='"); 459 html("<div id='logo'><a href='");
460 html_attr(cgit_rooturl()); 460 html_attr(cgit_rooturl());
461 htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n", 461 htmlf("'><img src='%s' alt='cgit'/></a></div>\n",
462 cgit_logo); 462 cgit_logo);
@@ -464,3 +464,3 @@ void cgit_print_pageheader(char *title, int show_search)
464 if (cgit_query_repo) { 464 if (cgit_query_repo) {
465 html("<h1>"); 465 html("<h1 class='first'>");
466 html_txt(strrpart(cgit_repo->name, 20)); 466 html_txt(strrpart(cgit_repo->name, 20));
@@ -469,6 +469,6 @@ void cgit_print_pageheader(char *title, int show_search)
469 if (cgit_repo->owner) { 469 if (cgit_repo->owner) {
470 html("<p>\n<h1>owner</h1>\n"); 470 html("<h1>owner</h1>\n");
471 html_txt(cgit_repo->owner); 471 html_txt(cgit_repo->owner);
472 } 472 }
473 html("<p>\n<h1>navigate</h1>\n"); 473 html("<h1>navigate</h1>\n");
474 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, 474 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head,
@@ -486,6 +486,6 @@ void cgit_print_pageheader(char *title, int show_search)
486 486
487 html("<p>\n<h1>branch</h1>\n"); 487 html("<h1>branch</h1>\n");
488 html("<form method='get' action=''>\n"); 488 html("<form method='get' action=''>\n");
489 add_hidden_formfields(0, 1, cgit_query_page); 489 add_hidden_formfields(0, 1, cgit_query_page);
490 html("<table class='grid'><tr><td id='branch-dropdown-cell'>"); 490 html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
491 html("<select name='h' onchange='this.form.submit();'>\n"); 491 html("<select name='h' onchange='this.form.submit();'>\n");
@@ -494,3 +494,3 @@ void cgit_print_pageheader(char *title, int show_search)
494 html("</td><td>"); 494 html("</td><td>");
495 html("<noscript><input type='submit' id='switch-btn' value='..'></noscript>\n"); 495 html("<noscript><input type='submit' id='switch-btn' value='..'/></noscript>\n");
496 html("</td></tr></table>"); 496 html("</td></tr></table>");
@@ -498,3 +498,3 @@ void cgit_print_pageheader(char *title, int show_search)
498 498
499 html("<p>\n<h1>search</h1>\n"); 499 html("<h1>search</h1>\n");
500 html("<form method='get' action='"); 500 html("<form method='get' action='");
@@ -521,3 +521,3 @@ void cgit_print_pageheader(char *title, int show_search)
521 521
522 html("</div>\n<table class='grid'><tr><td id='content'>\n"); 522 html("</div>\n<table summary='page content' class='grid'><tr><td id='content'>\n");
523} 523}
diff --git a/ui-snapshot.c b/ui-snapshot.c
index bd34a28..4d1aa88 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -101,2 +101,3 @@ void cgit_print_snapshot(struct cacheitem *item, const char *head,
101 args.tree = commit->tree; 101 args.tree = commit->tree;
102 args.time = commit->date;
102 cgit_print_snapshot_start(sat->mimetype, filename, item); 103 cgit_print_snapshot_start(sat->mimetype, filename, item);
diff --git a/ui-summary.c b/ui-summary.c
index c856793..b96414e 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -192,3 +192,3 @@ void cgit_print_summary()
192 NULL, NULL, 0); 192 NULL, NULL, 0);
193 html("<table class='list nowrap'>"); 193 html("<table summary='repository info' class='list nowrap'>");
194 if (cgit_summary_log > 0) 194 if (cgit_summary_log > 0)
diff --git a/ui-tree.c b/ui-tree.c
index c22e30b..c138877 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -19,3 +19,3 @@ static void print_object(const unsigned char *sha1, char *path)
19 unsigned long size, lineno, start, idx; 19 unsigned long size, lineno, start, idx;
20 const char *linefmt = "<tr><td class='no'><a name='%1$d'>%1$d</a></td><td class='txt'>"; 20 const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>";
21 21
@@ -39,3 +39,3 @@ static void print_object(const unsigned char *sha1, char *path)
39 39
40 html("<table class='blob'>\n"); 40 html("<table summary='blob content' class='blob'>\n");
41 idx = 0; 41 idx = 0;
@@ -110,3 +110,3 @@ static void ls_head()
110{ 110{
111 html("<table class='list'>\n"); 111 html("<table summary='tree listing' class='list'>\n");
112 html("<tr class='nohover'>"); 112 html("<tr class='nohover'>");