t / gitweb-lib.shon commit Merge branch 'nd/maint-relative' into maint (0bc6180)
   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';
  22our @stylesheets = ('file:///$TEST_DIRECTORY/../gitweb/static/gitweb.css');
  23our \$logo = 'file:///$TEST_DIRECTORY/../gitweb/static/git-logo.png';
  24our \$favicon = 'file:///$TEST_DIRECTORY/../gitweb/static/git-favicon.png';
  25our \$projects_list = '';
  26our \$export_ok = '';
  27our \$strict_export = '';
  28our \$maxload = undef;
  29
  30EOF
  31
  32        cat >.git/description <<EOF
  33$0 test repository
  34EOF
  35}
  36
  37gitweb_run () {
  38        GATEWAY_INTERFACE='CGI/1.1'
  39        HTTP_ACCEPT='*/*'
  40        REQUEST_METHOD='GET'
  41        SCRIPT_NAME="$TEST_DIRECTORY/../gitweb/gitweb.perl"
  42        QUERY_STRING=""$1""
  43        PATH_INFO=""$2""
  44        export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
  45                SCRIPT_NAME QUERY_STRING PATH_INFO
  46
  47        GITWEB_CONFIG=$(pwd)/gitweb_config.perl
  48        export GITWEB_CONFIG
  49
  50        # some of git commands write to STDERR on error, but this is not
  51        # written to web server logs, so we are not interested in that:
  52        # we are interested only in properly formatted errors/warnings
  53        rm -f gitweb.log &&
  54        perl -- "$SCRIPT_NAME" \
  55                >gitweb.output 2>gitweb.log &&
  56        perl -w -e '
  57                open O, ">gitweb.headers";
  58                while (<>) {
  59                        print O;
  60                        last if (/^\r$/ || /^$/);
  61                }
  62                open O, ">gitweb.body";
  63                while (<>) {
  64                        print O;
  65                }
  66                close O;
  67        ' gitweb.output &&
  68        if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi
  69
  70        # gitweb.log is left for debugging
  71        # gitweb.output is used to parse HTTP output
  72        # gitweb.headers contains only HTTP headers
  73        # gitweb.body contains body of message, without headers
  74}
  75
  76. ./test-lib.sh
  77
  78if ! test_have_prereq PERL; then
  79        skip_all='skipping gitweb tests, perl not available'
  80        test_done
  81fi
  82
  83perl -MEncode -e '$e="";decode_utf8($e, Encode::FB_CROAK)' >/dev/null 2>&1 || {
  84    skip_all='skipping gitweb tests, perl version is too old'
  85    test_done
  86}
  87
  88gitweb_init