]> git.ipfire.org Git - thirdparty/git.git/blame - t/gitweb-lib.sh
t/gitweb-lib.sh: Ensure that errors are shown for --debug --immediate
[thirdparty/git.git] / t / gitweb-lib.sh
CommitLineData
05526071
MR
1#!/bin/sh
2#
3# Copyright (c) 2007 Jakub Narebski
4#
5
6gitweb_init () {
7 safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
8 cat >gitweb_config.perl <<EOF
9#!/usr/bin/perl
10
11# gitweb configuration for tests
12
13our \$version = 'current';
14our \$GIT = 'git';
15our \$projectroot = "$safe_pwd";
16our \$project_maxdepth = 8;
17our \$home_link_str = 'projects';
18our \$site_name = '[localhost]';
19our \$site_header = '';
20our \$site_footer = '';
21our \$home_text = 'indextext.html';
b5d3450c
JN
22our @stylesheets = ('file:///$GIT_BUILD_DIR/gitweb/static/gitweb.css');
23our \$logo = 'file:///$GIT_BUILD_DIR/gitweb/static/git-logo.png';
24our \$favicon = 'file:///$GIT_BUILD_DIR/gitweb/static/git-favicon.png';
05526071
MR
25our \$projects_list = '';
26our \$export_ok = '';
27our \$strict_export = '';
b62a1a98 28our \$maxload = undef;
05526071
MR
29
30EOF
31
32 cat >.git/description <<EOF
33$0 test repository
34EOF
92990937
JN
35
36 # You can set the GITWEB_TEST_INSTALLED environment variable to
37 # the gitwebdir (the directory where gitweb is installed / deployed to)
38 # of an existing gitweb instalation to test that installation,
39 # or simply to pathname of installed gitweb script.
40 if test -n "$GITWEB_TEST_INSTALLED" ; then
41 if test -d $GITWEB_TEST_INSTALLED; then
42 SCRIPT_NAME="$GITWEB_TEST_INSTALLED/gitweb.cgi"
43 else
44 SCRIPT_NAME="$GITWEB_TEST_INSTALLED"
45 fi
46 test -f "$SCRIPT_NAME" ||
47 error "Cannot find gitweb at $GITWEB_TEST_INSTALLED."
48 say "# Testing $SCRIPT_NAME"
49 else # normal case, use source version of gitweb
50 SCRIPT_NAME="$GIT_BUILD_DIR/gitweb/gitweb.perl"
51 fi
52 export SCRIPT_NAME
05526071
MR
53}
54
55gitweb_run () {
56 GATEWAY_INTERFACE='CGI/1.1'
57 HTTP_ACCEPT='*/*'
58 REQUEST_METHOD='GET'
05526071
MR
59 QUERY_STRING=""$1""
60 PATH_INFO=""$2""
61 export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
92990937 62 QUERY_STRING PATH_INFO
05526071
MR
63
64 GITWEB_CONFIG=$(pwd)/gitweb_config.perl
65 export GITWEB_CONFIG
66
67 # some of git commands write to STDERR on error, but this is not
68 # written to web server logs, so we are not interested in that:
69 # we are interested only in properly formatted errors/warnings
70 rm -f gitweb.log &&
71 perl -- "$SCRIPT_NAME" \
72 >gitweb.output 2>gitweb.log &&
f74a83fc
BG
73 perl -w -e '
74 open O, ">gitweb.headers";
75 while (<>) {
76 print O;
77 last if (/^\r$/ || /^$/);
78 }
79 open O, ">gitweb.body";
80 while (<>) {
81 print O;
82 }
83 close O;
84 ' gitweb.output &&
49151d8b
ÆAB
85 if grep '^[[]' gitweb.log >/dev/null 2>&1; then
86 test_debug 'cat gitweb.log >&2' &&
87 false
88 else
89 true
90 fi
05526071
MR
91
92 # gitweb.log is left for debugging
46e09f31
JN
93 # gitweb.output is used to parse HTTP output
94 # gitweb.headers contains only HTTP headers
95 # gitweb.body contains body of message, without headers
05526071
MR
96}
97
98. ./test-lib.sh
99
100if ! test_have_prereq PERL; then
e8344e86 101 skip_all='skipping gitweb tests, perl not available'
05526071
MR
102 test_done
103fi
104
598df7bc 105perl -MEncode -e '$e="";decode_utf8($e, Encode::FB_CROAK)' >/dev/null 2>&1 || {
89d1b5b8
JN
106 skip_all='skipping gitweb tests, perl version is too old'
107 test_done
05526071
MR
108}
109
110gitweb_init