t/gitweb-lib.sh: Split gitweb output into headers and body
[alt-git.git] / t / gitweb-lib.sh
blob32b841dd2ea0325c31d8fb52e8fdb6a61fb3af3a
1 #!/bin/sh
3 # Copyright (c) 2007 Jakub Narebski
6 gitweb_init () {
7 safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
8 cat >gitweb_config.perl <<EOF
9 #!/usr/bin/perl
11 # gitweb configuration for tests
13 our \$version = 'current';
14 our \$GIT = 'git';
15 our \$projectroot = "$safe_pwd";
16 our \$project_maxdepth = 8;
17 our \$home_link_str = 'projects';
18 our \$site_name = '[localhost]';
19 our \$site_header = '';
20 our \$site_footer = '';
21 our \$home_text = 'indextext.html';
22 our @stylesheets = ('file:///$TEST_DIRECTORY/../gitweb/gitweb.css');
23 our \$logo = 'file:///$TEST_DIRECTORY/../gitweb/git-logo.png';
24 our \$favicon = 'file:///$TEST_DIRECTORY/../gitweb/git-favicon.png';
25 our \$projects_list = '';
26 our \$export_ok = '';
27 our \$strict_export = '';
29 EOF
31 cat >.git/description <<EOF
32 $0 test repository
33 EOF
36 gitweb_run () {
37 GATEWAY_INTERFACE='CGI/1.1'
38 HTTP_ACCEPT='*/*'
39 REQUEST_METHOD='GET'
40 SCRIPT_NAME="$TEST_DIRECTORY/../gitweb/gitweb.perl"
41 QUERY_STRING=""$1""
42 PATH_INFO=""$2""
43 export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
44 SCRIPT_NAME QUERY_STRING PATH_INFO
46 GITWEB_CONFIG=$(pwd)/gitweb_config.perl
47 export GITWEB_CONFIG
49 # some of git commands write to STDERR on error, but this is not
50 # written to web server logs, so we are not interested in that:
51 # we are interested only in properly formatted errors/warnings
52 rm -f gitweb.log &&
53 perl -- "$SCRIPT_NAME" \
54 >gitweb.output 2>gitweb.log &&
55 sed -e '/^\r$/q' <gitweb.output >gitweb.headers &&
56 sed -e '1,/^\r$/d' <gitweb.output >gitweb.body &&
57 if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi
59 # gitweb.log is left for debugging
60 # gitweb.output is used to parse HTTP output
61 # gitweb.headers contains only HTTP headers
62 # gitweb.body contains body of message, without headers
65 . ./test-lib.sh
67 if ! test_have_prereq PERL; then
68 say 'skipping gitweb tests, perl not available'
69 test_done
72 perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
73 say 'skipping gitweb tests, perl version is too old'
74 test_done
77 gitweb_init