Jonathan Nieder | c74c720 | 2013-11-25 13:03:06 -0800 | [diff] [blame] | 1 | # Initialization and helpers for Gitweb tests, which source this |
| 2 | # shell library instead of test-lib.sh. |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 3 | # |
| 4 | # Copyright (c) 2007 Jakub Narebski |
| 5 | # |
| 6 | |
| 7 | gitweb_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 | |
| 14 | our \$version = 'current'; |
| 15 | our \$GIT = 'git'; |
| 16 | our \$projectroot = "$safe_pwd"; |
| 17 | our \$project_maxdepth = 8; |
| 18 | our \$home_link_str = 'projects'; |
| 19 | our \$site_name = '[localhost]'; |
Lénaïc Huard | c1355b7 | 2011-10-21 09:09:29 +0200 | [diff] [blame] | 20 | our \$site_html_head_string = ''; |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 21 | our \$site_header = ''; |
| 22 | our \$site_footer = ''; |
| 23 | our \$home_text = 'indextext.html'; |
Jakub Narebski | b5d3450 | 2010-09-12 11:41:04 +0200 | [diff] [blame] | 24 | our @stylesheets = ('file:///$GIT_BUILD_DIR/gitweb/static/gitweb.css'); |
| 25 | our \$logo = 'file:///$GIT_BUILD_DIR/gitweb/static/git-logo.png'; |
| 26 | our \$favicon = 'file:///$GIT_BUILD_DIR/gitweb/static/git-favicon.png'; |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 27 | our \$projects_list = ''; |
| 28 | our \$export_ok = ''; |
| 29 | our \$strict_export = ''; |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 30 | our \$maxload = undef; |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 31 | |
| 32 | EOF |
| 33 | |
| 34 | cat >.git/description <<EOF |
| 35 | $0 test repository |
| 36 | EOF |
Jakub Narebski | 9299093 | 2010-09-26 15:02:25 +0200 | [diff] [blame] | 37 | |
| 38 | # You can set the GITWEB_TEST_INSTALLED environment variable to |
| 39 | # the gitwebdir (the directory where gitweb is installed / deployed to) |
Ondřej Bílka | 98e023d | 2013-07-29 10:18:21 +0200 | [diff] [blame] | 40 | # of an existing gitweb installation to test that installation, |
Jakub Narebski | 9299093 | 2010-09-26 15:02:25 +0200 | [diff] [blame] | 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 |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | gitweb_run () { |
| 58 | GATEWAY_INTERFACE='CGI/1.1' |
| 59 | HTTP_ACCEPT='*/*' |
| 60 | REQUEST_METHOD='GET' |
Jeff King | f28bcec | 2019-11-15 04:06:01 -0500 | [diff] [blame] | 61 | QUERY_STRING=$1 |
| 62 | PATH_INFO=$2 |
Jeff King | b178c20 | 2019-11-15 04:06:04 -0500 | [diff] [blame] | 63 | REQUEST_URI=/gitweb.cgi$PATH_INFO |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 64 | export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \ |
Jeff King | b178c20 | 2019-11-15 04:06:04 -0500 | [diff] [blame] | 65 | QUERY_STRING PATH_INFO REQUEST_URI |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 66 | |
| 67 | GITWEB_CONFIG=$(pwd)/gitweb_config.perl |
| 68 | export GITWEB_CONFIG |
| 69 | |
| 70 | # some of git commands write to STDERR on error, but this is not |
| 71 | # written to web server logs, so we are not interested in that: |
| 72 | # we are interested only in properly formatted errors/warnings |
| 73 | rm -f gitweb.log && |
Jeff King | 94221d2 | 2013-10-28 21:23:03 -0400 | [diff] [blame] | 74 | perl -- "$SCRIPT_NAME" \ |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 75 | >gitweb.output 2>gitweb.log && |
Brian Gernhardt | f74a83f | 2009-11-23 12:33:42 -0500 | [diff] [blame] | 76 | perl -w -e ' |
| 77 | open O, ">gitweb.headers"; |
| 78 | while (<>) { |
| 79 | print O; |
| 80 | last if (/^\r$/ || /^$/); |
| 81 | } |
| 82 | open O, ">gitweb.body"; |
| 83 | while (<>) { |
| 84 | print O; |
| 85 | } |
| 86 | close O; |
| 87 | ' gitweb.output && |
Ævar Arnfjörð Bjarmason | 49151d8 | 2011-02-19 19:16:19 +0100 | [diff] [blame] | 88 | if grep '^[[]' gitweb.log >/dev/null 2>&1; then |
| 89 | test_debug 'cat gitweb.log >&2' && |
| 90 | false |
| 91 | else |
| 92 | true |
| 93 | fi |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 94 | |
| 95 | # gitweb.log is left for debugging |
Jakub Narebski | 46e09f3 | 2009-10-29 23:07:41 +0100 | [diff] [blame] | 96 | # gitweb.output is used to parse HTTP output |
| 97 | # gitweb.headers contains only HTTP headers |
| 98 | # gitweb.body contains body of message, without headers |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | . ./test-lib.sh |
| 102 | |
| 103 | if ! test_have_prereq PERL; then |
Ævar Arnfjörð Bjarmason | e8344e8 | 2010-07-08 01:16:06 +0000 | [diff] [blame] | 104 | skip_all='skipping gitweb tests, perl not available' |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 105 | test_done |
| 106 | fi |
| 107 | |
Brian Gernhardt | 598df7b | 2010-10-20 01:57:11 -0400 | [diff] [blame] | 108 | perl -MEncode -e '$e="";decode_utf8($e, Encode::FB_CROAK)' >/dev/null 2>&1 || { |
Jakub Narebski | 89d1b5b | 2010-09-12 11:41:05 +0200 | [diff] [blame] | 109 | skip_all='skipping gitweb tests, perl version is too old' |
| 110 | test_done |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Junio C Hamano | b7d8780 | 2011-06-15 09:54:15 -0700 | [diff] [blame] | 113 | perl -MCGI -MCGI::Util -MCGI::Carp -e 0 >/dev/null 2>&1 || { |
Ævar Arnfjörð Bjarmason | 0b69e4f | 2017-03-01 21:15:39 +0000 | [diff] [blame] | 114 | skip_all='skipping gitweb tests, CGI & CGI::Util & CGI::Carp modules not available' |
Junio C Hamano | b7d8780 | 2011-06-15 09:54:15 -0700 | [diff] [blame] | 115 | test_done |
| 116 | } |
| 117 | |
Ævar Arnfjörð Bjarmason | c650748 | 2017-03-01 21:15:40 +0000 | [diff] [blame] | 118 | perl -mTime::HiRes -e 0 >/dev/null 2>&1 || { |
| 119 | skip_all='skipping gitweb tests, Time::HiRes module not available' |
| 120 | test_done |
| 121 | } |
| 122 | |
Mark Rada | 0552607 | 2009-08-27 22:07:07 -0400 | [diff] [blame] | 123 | gitweb_init |