summaryrefslogtreecommitdiffabout
authorRamsay Jones <ramsay@ramsay1.demon.co.uk>2008-11-04 19:23:41 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-11-06 18:18:09 (UTC)
commite4d2f2b042100182ff5b214fd6848b71d70fad7d (patch) (unidiff)
treebb5bfcf6e5f71a478e7586bd1d128aa94bfd7dbe
parentbdd4a56ad55720cde3b7b290b6b9fe4c57dc4f01 (diff)
downloadcgit-e4d2f2b042100182ff5b214fd6848b71d70fad7d.zip
cgit-e4d2f2b042100182ff5b214fd6848b71d70fad7d.tar.gz
cgit-e4d2f2b042100182ff5b214fd6848b71d70fad7d.tar.bz2
Fix tests to work on Ubuntu (dash)
The system shell (/bin/sh) on Ubuntu is dash, which aims to be a POSIX standard shell. In particular, dash does not implement any of the common extensions to the standard that, say, bash and ksh do. Replace some non-POSIX constructs in setup.sh with more portable and mundane code. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xtests/setup.sh6
1 files changed, 4 insertions, 2 deletions
diff --git a/tests/setup.sh b/tests/setup.sh
index 1457dd5..95acb54 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -1,127 +1,129 @@
1# This file should be sourced by all test-scripts 1# This file should be sourced by all test-scripts
2# 2#
3# Main functions: 3# Main functions:
4# prepare_tests(description) - setup for testing, i.e. create repos+config 4# prepare_tests(description) - setup for testing, i.e. create repos+config
5# run_test(description, script) - run one test, i.e. eval script 5# run_test(description, script) - run one test, i.e. eval script
6# 6#
7# Helper functions 7# Helper functions
8# cgit_query(querystring) - call cgit with the specified querystring 8# cgit_query(querystring) - call cgit with the specified querystring
9# cgit_url(url) - call cgit with the specified virtual url 9# cgit_url(url) - call cgit with the specified virtual url
10# 10#
11# Example script: 11# Example script:
12# 12#
13# . setup.sh 13# . setup.sh
14# prepare_tests "html validation" 14# prepare_tests "html validation"
15# run_test 'repo index' 'cgit_url "/" | tidy -e' 15# run_test 'repo index' 'cgit_url "/" | tidy -e'
16# run_test 'repo summary' 'cgit_url "/foo" | tidy -e' 16# run_test 'repo summary' 'cgit_url "/foo" | tidy -e'
17 17
18 18
19mkrepo() { 19mkrepo() {
20 name=$1 20 name=$1
21 count=$2 21 count=$2
22 dir=$PWD 22 dir=$PWD
23 test -d $name && return 23 test -d $name && return
24 printf "Creating testrepo %s\n" $name 24 printf "Creating testrepo %s\n" $name
25 mkdir -p $name 25 mkdir -p $name
26 cd $name 26 cd $name
27 git init 27 git init
28 for ((n=1; n<=count; n++)) 28 n=1
29 while test $n -le $count
29 do 30 do
30 echo $n >file-$n 31 echo $n >file-$n
31 git add file-$n 32 git add file-$n
32 git commit -m "commit $n" 33 git commit -m "commit $n"
34 n=$(expr $n + 1)
33 done 35 done
34 if test "$3" = "testplus" 36 if test "$3" = "testplus"
35 then 37 then
36 echo "hello" >a+b 38 echo "hello" >a+b
37 git add a+b 39 git add a+b
38 git commit -m "add a+b" 40 git commit -m "add a+b"
39 git branch "1+2" 41 git branch "1+2"
40 fi 42 fi
41 cd $dir 43 cd $dir
42} 44}
43 45
44setup_repos() 46setup_repos()
45{ 47{
46 rm -rf trash/cache 48 rm -rf trash/cache
47 mkdir -p trash/cache 49 mkdir -p trash/cache
48 mkrepo trash/repos/foo 5 >/dev/null 50 mkrepo trash/repos/foo 5 >/dev/null
49 mkrepo trash/repos/bar 50 >/dev/null 51 mkrepo trash/repos/bar 50 >/dev/null
50 mkrepo trash/repos/foo+bar 10 testplus >/dev/null 52 mkrepo trash/repos/foo+bar 10 testplus >/dev/null
51 cat >trash/cgitrc <<EOF 53 cat >trash/cgitrc <<EOF
52virtual-root=/ 54virtual-root=/
53cache-root=$PWD/trash/cache 55cache-root=$PWD/trash/cache
54 56
55cache-size=1021 57cache-size=1021
56snapshots=tar.gz tar.bz zip 58snapshots=tar.gz tar.bz zip
57enable-log-filecount=1 59enable-log-filecount=1
58enable-log-linecount=1 60enable-log-linecount=1
59summary-log=5 61summary-log=5
60summary-branches=5 62summary-branches=5
61summary-tags=5 63summary-tags=5
62 64
63repo.url=foo 65repo.url=foo
64repo.path=$PWD/trash/repos/foo/.git 66repo.path=$PWD/trash/repos/foo/.git
65# Do not specify a description for this repo, as it then will be assigned 67# Do not specify a description for this repo, as it then will be assigned
66# the constant value "[no description]" (which actually used to cause a 68# the constant value "[no description]" (which actually used to cause a
67# segfault). 69# segfault).
68 70
69repo.url=bar 71repo.url=bar
70repo.path=$PWD/trash/repos/bar/.git 72repo.path=$PWD/trash/repos/bar/.git
71repo.desc=the bar repo 73repo.desc=the bar repo
72 74
73repo.url=foo+bar 75repo.url=foo+bar
74repo.path=$PWD/trash/repos/foo+bar/.git 76repo.path=$PWD/trash/repos/foo+bar/.git
75repo.desc=the foo+bar repo 77repo.desc=the foo+bar repo
76EOF 78EOF
77} 79}
78 80
79prepare_tests() 81prepare_tests()
80{ 82{
81 setup_repos 83 setup_repos
82 rm -f test-output.log 2>/dev/null 84 rm -f test-output.log 2>/dev/null
83 test_count=0 85 test_count=0
84 test_failed=0 86 test_failed=0
85 echo "[$0]" "$@" >test-output.log 87 echo "[$0]" "$@" >test-output.log
86 echo "$@" "($0)" 88 echo "$@" "($0)"
87} 89}
88 90
89tests_done() 91tests_done()
90{ 92{
91 printf "\n" 93 printf "\n"
92 if test $test_failed -gt 0 94 if test $test_failed -gt 0
93 then 95 then
94 printf "test: *** %s failure(s), logfile=%s\n" \ 96 printf "test: *** %s failure(s), logfile=%s\n" \
95 $test_failed "$(pwd)/test-output.log" 97 $test_failed "$(pwd)/test-output.log"
96 false 98 false
97 fi 99 fi
98} 100}
99 101
100run_test() 102run_test()
101{ 103{
102 desc=$1 104 desc=$1
103 script=$2 105 script=$2
104 ((test_count++)) 106 test_count=$(expr $test_count + 1)
105 printf "\ntest %d: name='%s'\n" $test_count "$desc" >>test-output.log 107 printf "\ntest %d: name='%s'\n" $test_count "$desc" >>test-output.log
106 printf "test %d: eval='%s'\n" $test_count "$2" >>test-output.log 108 printf "test %d: eval='%s'\n" $test_count "$2" >>test-output.log
107 eval "$2" >>test-output.log 2>>test-output.log 109 eval "$2" >>test-output.log 2>>test-output.log
108 res=$? 110 res=$?
109 printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log 111 printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log
110 if test $res = 0 112 if test $res = 0
111 then 113 then
112 printf " %2d) %-60s [ok]\n" $test_count "$desc" 114 printf " %2d) %-60s [ok]\n" $test_count "$desc"
113 else 115 else
114 ((test_failed++)) 116 ((test_failed++))
115 printf " %2d) %-60s [failed]\n" $test_count "$desc" 117 printf " %2d) %-60s [failed]\n" $test_count "$desc"
116 fi 118 fi
117} 119}
118 120
119cgit_query() 121cgit_query()
120{ 122{
121 CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit" 123 CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit"
122} 124}
123 125
124cgit_url() 126cgit_url()
125{ 127{
126 CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit" 128 CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit"
127} 129}