t / gitweb-lib.shon commit Merge branch 'nd/daemon-informative-errors-typofix' into maint (7fd90e0)
   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_html_head_string = '';
  20our \$site_header = '';
  21our \$site_footer = '';
  22our \$home_text = 'indextext.html';
  23our @stylesheets = ('file:///$GIT_BUILD_DIR/gitweb/static/gitweb.css');
  24our \$logo = 'file:///$GIT_BUILD_DIR/gitweb/static/git-logo.png';
  25our \$favicon = 'file:///$GIT_BUILD_DIR/gitweb/static/git-favicon.png';
  26our \$projects_list = '';
  27our \$export_ok = '';
  28our \$strict_export = '';
  29our \$maxload = undef;
  30
  31EOF
  32
  33        cat >.git/description <<EOF
  34$0 test repository
  35EOF
  36
  37        # You can set the GITWEB_TEST_INSTALLED environment variable to
  38        # the gitwebdir (the directory where gitweb is installed / deployed to)
  39        # of an existing gitweb installation to test that installation,
  40        # or simply to pathname of installed gitweb script.
  41        if test -n "$GITWEB_TEST_INSTALLED" ; then
  42                if test -d $GITWEB_TEST_INSTALLED; then
  43                        SCRIPT_NAME="$GITWEB_TEST_INSTALLED/gitweb.cgi"
  44                else
  45                        SCRIPT_NAME="$GITWEB_TEST_INSTALLED"
  46                fi
  47                test -f "$SCRIPT_NAME" ||
  48                error "Cannot find gitweb at $GITWEB_TEST_INSTALLED."
  49                say "# Testing $SCRIPT_NAME"
  50        else # normal case, use source version of gitweb
  51                SCRIPT_NAME="$GIT_BUILD_DIR/gitweb/gitweb.perl"
  52        fi
  53        export SCRIPT_NAME
  54}
  55
  56gitweb_run () {
  57        GATEWAY_INTERFACE='CGI/1.1'
  58        HTTP_ACCEPT='*/*'
  59        REQUEST_METHOD='GET'
  60        QUERY_STRING=""$1""
  61        PATH_INFO=""$2""
  62        export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
  63                QUERY_STRING PATH_INFO
  64
  65        GITWEB_CONFIG=$(pwd)/gitweb_config.perl
  66        export GITWEB_CONFIG
  67
  68        # some of git commands write to STDERR on error, but this is not
  69        # written to web server logs, so we are not interested in that:
  70        # we are interested only in properly formatted errors/warnings
  71        rm -f gitweb.log &&
  72        perl -- "$SCRIPT_NAME" \
  73                >gitweb.output 2>gitweb.log &&
  74        perl -w -e '
  75                open O, ">gitweb.headers";
  76                while (<>) {
  77                        print O;
  78                        last if (/^\r$/ || /^$/);
  79                }
  80                open O, ">gitweb.body";
  81                while (<>) {
  82                        print O;
  83                }
  84                close O;
  85        ' gitweb.output &&
  86        if grep '^[[]' gitweb.log >/dev/null 2>&1; then
  87                test_debug 'cat gitweb.log >&2' &&
  88                false
  89        else
  90                true
  91        fi
  92
  93        # gitweb.log is left for debugging
  94        # gitweb.output is used to parse HTTP output
  95        # gitweb.headers contains only HTTP headers
  96        # gitweb.body contains body of message, without headers
  97}
  98
  99. ./test-lib.sh
 100
 101if ! test_have_prereq PERL; then
 102        skip_all='skipping gitweb tests, perl not available'
 103        test_done
 104fi
 105
 106perl -MEncode -e '$e="";decode_utf8($e, Encode::FB_CROAK)' >/dev/null 2>&1 || {
 107        skip_all='skipping gitweb tests, perl version is too old'
 108        test_done
 109}
 110
 111perl -MCGI -MCGI::Util -MCGI::Carp -e 0 >/dev/null 2>&1 || {
 112        skip_all='skipping gitweb tests, CGI module unusable'
 113        test_done
 114}
 115
 116gitweb_init