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