t / lib-git-svn.shon commit git svn: migrate tests to use lib-httpd (a8a5d25)
   1. ./test-lib.sh
   2
   3remotes_git_svn=remotes/git""-svn
   4git_svn_id=git""-svn-id
   5
   6if test -n "$NO_SVN_TESTS"
   7then
   8        skip_all='skipping git svn tests, NO_SVN_TESTS defined'
   9        test_done
  10fi
  11if ! test_have_prereq PERL; then
  12        skip_all='skipping git svn tests, perl not available'
  13        test_done
  14fi
  15
  16GIT_DIR=$PWD/.git
  17GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
  18SVN_TREE=$GIT_SVN_DIR/svn-tree
  19
  20svn >/dev/null 2>&1
  21if test $? -ne 1
  22then
  23    skip_all='skipping git svn tests, svn not found'
  24    test_done
  25fi
  26
  27svnrepo=$PWD/svnrepo
  28export svnrepo
  29svnconf=$PWD/svnconf
  30export svnconf
  31
  32perl -w -e "
  33use SVN::Core;
  34use SVN::Repos;
  35\$SVN::Core::VERSION gt '1.1.0' or exit(42);
  36system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
  37" >&3 2>&4
  38x=$?
  39if test $x -ne 0
  40then
  41        if test $x -eq 42; then
  42                skip_all='Perl SVN libraries must be >= 1.1.0'
  43        elif test $x -eq 41; then
  44                skip_all='svnadmin failed to create fsfs repository'
  45        else
  46                skip_all='Perl SVN libraries not found or unusable'
  47        fi
  48        test_done
  49fi
  50
  51rawsvnrepo="$svnrepo"
  52svnrepo="file://$svnrepo"
  53
  54poke() {
  55        test-chmtime +1 "$1"
  56}
  57
  58# We need this, because we should pass empty configuration directory to
  59# the 'svn commit' to avoid automated property changes and other stuff
  60# that could be set from user's configuration files in ~/.subversion.
  61svn_cmd () {
  62        [ -d "$svnconf" ] || mkdir "$svnconf"
  63        orig_svncmd="$1"; shift
  64        if [ -z "$orig_svncmd" ]; then
  65                svn
  66                return
  67        fi
  68        svn "$orig_svncmd" --config-dir "$svnconf" "$@"
  69}
  70
  71maybe_start_httpd () {
  72        loc=${1-svn}
  73
  74        test_tristate GIT_SVN_TEST_HTTPD
  75        case $GIT_SVN_TEST_HTTPD in
  76        true)
  77                . "$TEST_DIRECTORY"/lib-httpd.sh
  78                LIB_HTTPD_SVN="$loc"
  79                start_httpd
  80                ;;
  81        *)
  82                stop_httpd () {
  83                        : noop
  84                }
  85                ;;
  86        esac
  87}
  88
  89convert_to_rev_db () {
  90        perl -w -- - "$@" <<\EOF
  91use strict;
  92@ARGV == 2 or die "usage: convert_to_rev_db <input> <output>";
  93open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
  94open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
  95my $size = (stat($rd))[7];
  96($size % 24) == 0 or die "Inconsistent size: $size";
  97while (sysread($rd, my $buf, 24) == 24) {
  98        my ($r, $c) = unpack('NH40', $buf);
  99        my $offset = $r * 41;
 100        seek $wr, 0, 2 or die $!;
 101        my $pos = tell $wr;
 102        if ($pos < $offset) {
 103                for (1 .. (($offset - $pos) / 41)) {
 104                        print $wr (('0' x 40),"\n") or die $!;
 105                }
 106        }
 107        seek $wr, $offset, 0 or die $!;
 108        print $wr $c,"\n" or die $!;
 109}
 110close $wr or die $!;
 111close $rd or die $!;
 112EOF
 113}
 114
 115require_svnserve () {
 116    if test -z "$SVNSERVE_PORT"
 117    then
 118        skip_all='skipping svnserve test. (set $SVNSERVE_PORT to enable)'
 119        test_done
 120    fi
 121}
 122
 123start_svnserve () {
 124    svnserve --listen-port $SVNSERVE_PORT \
 125             --root "$rawsvnrepo" \
 126             --listen-once \
 127             --listen-host 127.0.0.1 &
 128}
 129
 130prepare_a_utf8_locale () {
 131        a_utf8_locale=$(locale -a | sed -n '/\.[uU][tT][fF]-*8$/{
 132        p
 133        q
 134}')
 135        if test -n "$a_utf8_locale"
 136        then
 137                test_set_prereq UTF8
 138        else
 139                say "# UTF-8 locale not available, some tests are skipped"
 140        fi
 141}