]> git.ipfire.org Git - thirdparty/git.git/blame - t/gitweb-lib.sh
Merge branch 'wb/fsmonitor-bitmap-fix'
[thirdparty/git.git] / t / gitweb-lib.sh
CommitLineData
c74c7203
JN
1# Initialization and helpers for Gitweb tests, which source this
2# shell library instead of test-lib.sh.
05526071
MR
3#
4# Copyright (c) 2007 Jakub Narebski
5#
6
7gitweb_init () {
8 safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
9 cat >gitweb_config.perl <<EOF
10#!/usr/bin/perl
11
12# gitweb configuration for tests
13
14our \$version = 'current';
15our \$GIT = 'git';
16our \$projectroot = "$safe_pwd";
17our \$project_maxdepth = 8;
18our \$home_link_str = 'projects';
19our \$site_name = '[localhost]';
c1355b7f 20our \$site_html_head_string = '';
05526071
MR
21our \$site_header = '';
22our \$site_footer = '';
23our \$home_text = 'indextext.html';
b5d3450c
JN
24our @stylesheets = ('file:///$GIT_BUILD_DIR/gitweb/static/gitweb.css');
25our \$logo = 'file:///$GIT_BUILD_DIR/gitweb/static/git-logo.png';
26our \$favicon = 'file:///$GIT_BUILD_DIR/gitweb/static/git-favicon.png';
05526071
MR
27our \$projects_list = '';
28our \$export_ok = '';
29our \$strict_export = '';
b62a1a98 30our \$maxload = undef;
05526071
MR
31
32EOF
33
34 cat >.git/description <<EOF
35$0 test repository
36EOF
92990937
JN
37
38 # You can set the GITWEB_TEST_INSTALLED environment variable to
39 # the gitwebdir (the directory where gitweb is installed / deployed to)
98e023de 40 # of an existing gitweb installation to test that installation,
92990937
JN
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"
47 fi
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"
53 fi
54 export SCRIPT_NAME
05526071
MR
55}
56
57gitweb_run () {
58 GATEWAY_INTERFACE='CGI/1.1'
59 HTTP_ACCEPT='*/*'
60 REQUEST_METHOD='GET'
05526071
MR
61 QUERY_STRING=""$1""
62 PATH_INFO=""$2""
63 export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
92990937 64 QUERY_STRING PATH_INFO
05526071
MR
65
66 GITWEB_CONFIG=$(pwd)/gitweb_config.perl
67 export GITWEB_CONFIG
68
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 &&
94221d22 73 perl -- "$SCRIPT_NAME" \
05526071 74 >gitweb.output 2>gitweb.log &&
f74a83fc
BG
75 perl -w -e '
76 open O, ">gitweb.headers";
77 while (<>) {
78 print O;
79 last if (/^\r$/ || /^$/);
80 }
81 open O, ">gitweb.body";
82 while (<>) {
83 print O;
84 }
85 close O;
86 ' gitweb.output &&
49151d8b
ÆAB
87 if grep '^[[]' gitweb.log >/dev/null 2>&1; then
88 test_debug 'cat gitweb.log >&2' &&
89 false
90 else
91 true
92 fi
05526071
MR
93
94 # gitweb.log is left for debugging
46e09f31
JN
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
05526071
MR
98}
99
100. ./test-lib.sh
101
102if ! test_have_prereq PERL; then
e8344e86 103 skip_all='skipping gitweb tests, perl not available'
05526071
MR
104 test_done
105fi
106
598df7bc 107perl -MEncode -e '$e="";decode_utf8($e, Encode::FB_CROAK)' >/dev/null 2>&1 || {
89d1b5b8
JN
108 skip_all='skipping gitweb tests, perl version is too old'
109 test_done
05526071
MR
110}
111
b7d87807 112perl -MCGI -MCGI::Util -MCGI::Carp -e 0 >/dev/null 2>&1 || {
0b69e4fa 113 skip_all='skipping gitweb tests, CGI & CGI::Util & CGI::Carp modules not available'
b7d87807
JH
114 test_done
115}
116
c6507484
ÆAB
117perl -mTime::HiRes -e 0 >/dev/null 2>&1 || {
118 skip_all='skipping gitweb tests, Time::HiRes module not available'
119 test_done
120}
121
05526071 122gitweb_init