t / t9502-gitweb-standalone-parse-output.shon commit Merge branch 'tr/send-email-refuse-sending-unedited-cover-letter' (b886656)
   1#!/bin/sh
   2#
   3# Copyright (c) 2009 Mark Rada
   4#
   5
   6test_description='gitweb as standalone script (parsing script output).
   7
   8This test runs gitweb (git web interface) as a CGI script from the
   9commandline, and checks that it produces the correct output, either
  10in the HTTP header or the actual script output.'
  11
  12
  13. ./gitweb-lib.sh
  14
  15# ----------------------------------------------------------------------
  16# snapshot file name and prefix
  17
  18cat >>gitweb_config.perl <<\EOF
  19
  20$known_snapshot_formats{'tar'} = {
  21        'display' => 'tar',
  22        'type' => 'application/x-tar',
  23        'suffix' => '.tar',
  24        'format' => 'tar',
  25};
  26
  27$feature{'snapshot'}{'default'} = ['tar'];
  28EOF
  29
  30# Call check_snapshot with the arguments "<basename> [<prefix>]"
  31#
  32# This will check that gitweb HTTP header contains proposed filename
  33# as <basename> with '.tar' suffix added, and that generated tarfile
  34# (gitweb message body) has <prefix> as prefix for al files in tarfile
  35#
  36# <prefix> default to <basename>
  37check_snapshot () {
  38        basename=$1
  39        prefix=${2:-"$1"}
  40        echo "basename=$basename"
  41        grep "filename=.*$basename.tar" gitweb.headers >/dev/null 2>&1 &&
  42        "$TAR" tf gitweb.body >file_list &&
  43        ! grep -v "^$prefix/" file_list
  44}
  45
  46test_expect_success setup '
  47        test_commit first foo &&
  48        git branch xx/test &&
  49        FULL_ID=$(git rev-parse --verify HEAD) &&
  50        SHORT_ID=$(git rev-parse --verify --short=7 HEAD)
  51'
  52test_debug '
  53        echo "FULL_ID  = $FULL_ID"
  54        echo "SHORT_ID = $SHORT_ID"
  55'
  56
  57test_expect_success 'snapshot: full sha1' '
  58        gitweb_run "p=.git;a=snapshot;h=$FULL_ID;sf=tar" &&
  59        check_snapshot ".git-$SHORT_ID"
  60'
  61test_debug 'cat gitweb.headers && cat file_list'
  62
  63test_expect_success 'snapshot: shortened sha1' '
  64        gitweb_run "p=.git;a=snapshot;h=$SHORT_ID;sf=tar" &&
  65        check_snapshot ".git-$SHORT_ID"
  66'
  67test_debug 'cat gitweb.headers && cat file_list'
  68
  69test_expect_success 'snapshot: almost full sha1' '
  70        ID=$(git rev-parse --short=30 HEAD) &&
  71        gitweb_run "p=.git;a=snapshot;h=$ID;sf=tar" &&
  72        check_snapshot ".git-$SHORT_ID"
  73'
  74test_debug 'cat gitweb.headers && cat file_list'
  75
  76test_expect_success 'snapshot: HEAD' '
  77        gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tar" &&
  78        check_snapshot ".git-HEAD-$SHORT_ID"
  79'
  80test_debug 'cat gitweb.headers && cat file_list'
  81
  82test_expect_success 'snapshot: short branch name (master)' '
  83        gitweb_run "p=.git;a=snapshot;h=master;sf=tar" &&
  84        ID=$(git rev-parse --verify --short=7 master) &&
  85        check_snapshot ".git-master-$ID"
  86'
  87test_debug 'cat gitweb.headers && cat file_list'
  88
  89test_expect_success 'snapshot: short tag name (first)' '
  90        gitweb_run "p=.git;a=snapshot;h=first;sf=tar" &&
  91        ID=$(git rev-parse --verify --short=7 first) &&
  92        check_snapshot ".git-first-$ID"
  93'
  94test_debug 'cat gitweb.headers && cat file_list'
  95
  96test_expect_success 'snapshot: full branch name (refs/heads/master)' '
  97        gitweb_run "p=.git;a=snapshot;h=refs/heads/master;sf=tar" &&
  98        ID=$(git rev-parse --verify --short=7 master) &&
  99        check_snapshot ".git-master-$ID"
 100'
 101test_debug 'cat gitweb.headers && cat file_list'
 102
 103test_expect_success 'snapshot: full tag name (refs/tags/first)' '
 104        gitweb_run "p=.git;a=snapshot;h=refs/tags/first;sf=tar" &&
 105        check_snapshot ".git-first"
 106'
 107test_debug 'cat gitweb.headers && cat file_list'
 108
 109test_expect_success 'snapshot: hierarchical branch name (xx/test)' '
 110        gitweb_run "p=.git;a=snapshot;h=xx/test;sf=tar" &&
 111        ! grep "filename=.*/" gitweb.headers
 112'
 113test_debug 'cat gitweb.headers'
 114
 115test_done