Merge branch 'jc/exclusion-doc'
[alt-git.git] / t / gitweb-lib.sh
blobd5dab5a94f1d881b8b103f6290ba91e4ec596ec6
1 # Initialization and helpers for Gitweb tests, which source this
2 # shell library instead of test-lib.sh.
4 # Copyright (c) 2007 Jakub Narebski
7 gitweb_init () {
8 safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
9 cat >gitweb_config.perl <<EOF
10 #!/usr/bin/perl
12 # gitweb configuration for tests
14 our \$version = 'current';
15 our \$GIT = 'git';
16 our \$projectroot = "$safe_pwd";
17 our \$project_maxdepth = 8;
18 our \$home_link_str = 'projects';
19 our \$site_name = '[localhost]';
20 our \$site_html_head_string = '';
21 our \$site_header = '';
22 our \$site_footer = '';
23 our \$home_text = 'indextext.html';
24 our @stylesheets = ('file:///$GIT_BUILD_DIR/gitweb/static/gitweb.css');
25 our \$logo = 'file:///$GIT_BUILD_DIR/gitweb/static/git-logo.png';
26 our \$favicon = 'file:///$GIT_BUILD_DIR/gitweb/static/git-favicon.png';
27 our \$projects_list = '';
28 our \$export_ok = '';
29 our \$strict_export = '';
30 our \$maxload = undef;
32 EOF
34 cat >.git/description <<EOF
35 $0 test repository
36 EOF
38 # You can set the GITWEB_TEST_INSTALLED environment variable to
39 # the gitwebdir (the directory where gitweb is installed / deployed to)
40 # of an existing gitweb installation to test that installation,
41 # or simply to pathname of installed gitweb script.
42 if test -n "$GITWEB_TEST_INSTALLED" ; then
43 if test -d $GITWEB_TEST_INSTALLED; then
44 SCRIPT_NAME="$GITWEB_TEST_INSTALLED/gitweb.cgi"
45 else
46 SCRIPT_NAME="$GITWEB_TEST_INSTALLED"
48 test -f "$SCRIPT_NAME" ||
49 error "Cannot find gitweb at $GITWEB_TEST_INSTALLED."
50 say "# Testing $SCRIPT_NAME"
51 else # normal case, use source version of gitweb
52 SCRIPT_NAME="$GIT_BUILD_DIR/gitweb/gitweb.perl"
54 export SCRIPT_NAME
57 gitweb_run () {
58 GATEWAY_INTERFACE='CGI/1.1'
59 HTTP_ACCEPT='*/*'
60 REQUEST_METHOD='GET'
61 QUERY_STRING=""$1""
62 PATH_INFO=""$2""
63 export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
64 QUERY_STRING PATH_INFO
66 GITWEB_CONFIG=$(pwd)/gitweb_config.perl
67 export GITWEB_CONFIG
69 # some of git commands write to STDERR on error, but this is not
70 # written to web server logs, so we are not interested in that:
71 # we are interested only in properly formatted errors/warnings
72 rm -f gitweb.log &&
73 perl -- "$SCRIPT_NAME" \
74 >gitweb.output 2>gitweb.log &&
75 perl -w -e '
76 open O, ">gitweb.headers";
77 while (<>) {
78 print O;
79 last if (/^\r$/ || /^$/);
81 open O, ">gitweb.body";
82 while (<>) {
83 print O;
85 close O;
86 ' gitweb.output &&
87 if grep '^[[]' gitweb.log >/dev/null 2>&1; then
88 test_debug 'cat gitweb.log >&2' &&
89 false
90 else
91 true
94 # gitweb.log is left for debugging
95 # gitweb.output is used to parse HTTP output
96 # gitweb.headers contains only HTTP headers
97 # gitweb.body contains body of message, without headers
100 . ./test-lib.sh
102 if ! test_have_prereq PERL; then
103 skip_all='skipping gitweb tests, perl not available'
104 test_done
107 perl -MEncode -e '$e="";decode_utf8($e, Encode::FB_CROAK)' >/dev/null 2>&1 || {
108 skip_all='skipping gitweb tests, perl version is too old'
109 test_done
112 perl -MCGI -MCGI::Util -MCGI::Carp -e 0 >/dev/null 2>&1 || {
113 skip_all='skipping gitweb tests, CGI module unusable'
114 test_done
117 gitweb_init