4ce067f87c65c91d01f6e3e75deea25e92b30969
[git/jnareb-git.git] / t / gitweb-lib.sh
blob4ce067f87c65c91d01f6e3e75deea25e92b30969
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:///$GIT_BUILD_DIR/gitweb/static/gitweb.css');
23 our \$logo = 'file:///$GIT_BUILD_DIR/gitweb/static/git-logo.png';
24 our \$favicon = 'file:///$GIT_BUILD_DIR/gitweb/static/git-favicon.png';
25 our \$projects_list = '';
26 our \$export_ok = '';
27 our \$strict_export = '';
28 our \$maxload = undef;
30 EOF
32 cat >.git/description <<EOF
33 $0 test repository
34 EOF
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"
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"
52 export SCRIPT_NAME
55 gitweb_enable_caching () {
56 test_expect_success 'enable caching' '
57 cat >>gitweb_config.perl <<-\EOF &&
58 $caching_enabled = 1;
59 $cache_options{"expires_in"} = -1; # never expire cache for tests
60 $cache_options{"cache_root"} = "cache"; # to clear the right thing
61 EOF
62 rm -rf cache/
66 gitweb_run () {
67 GATEWAY_INTERFACE='CGI/1.1'
68 HTTP_ACCEPT='*/*'
69 REQUEST_METHOD='GET'
70 QUERY_STRING=""$1""
71 PATH_INFO=""$2""
72 export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
73 QUERY_STRING PATH_INFO
75 GITWEB_CONFIG=$(pwd)/gitweb_config.perl
76 export GITWEB_CONFIG
78 # some of git commands write to STDERR on error, but this is not
79 # written to web server logs, so we are not interested in that:
80 # we are interested only in properly formatted errors/warnings
81 rm -f gitweb.log &&
82 perl -- "$SCRIPT_NAME" \
83 >gitweb.output 2>gitweb.log &&
84 perl -w -e '
85 open O, ">gitweb.headers";
86 while (<>) {
87 print O;
88 last if (/^\r$/ || /^$/);
90 open O, ">gitweb.body";
91 while (<>) {
92 print O;
94 close O;
95 ' gitweb.output &&
96 if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi
98 # gitweb.log is left for debugging
99 # gitweb.output is used to parse HTTP output
100 # gitweb.headers contains only HTTP headers
101 # gitweb.body contains body of message, without headers
104 . ./test-lib.sh
106 if ! test_have_prereq PERL; then
107 skip_all='skipping gitweb tests, perl not available'
108 test_done
111 perl -MEncode -e '$e="";decode_utf8($e, Encode::FB_CROAK)' >/dev/null 2>&1 || {
112 skip_all='skipping gitweb tests, perl version is too old'
113 test_done
116 gitweb_init