git svn: migrate tests to use lib-httpd
[git] / t / lib-git-svn.sh
1 . ./test-lib.sh
2
3 remotes_git_svn=remotes/git""-svn
4 git_svn_id=git""-svn-id
5
6 if test -n "$NO_SVN_TESTS"
7 then
8         skip_all='skipping git svn tests, NO_SVN_TESTS defined'
9         test_done
10 fi
11 if ! test_have_prereq PERL; then
12         skip_all='skipping git svn tests, perl not available'
13         test_done
14 fi
15
16 GIT_DIR=$PWD/.git
17 GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
18 SVN_TREE=$GIT_SVN_DIR/svn-tree
19
20 svn >/dev/null 2>&1
21 if test $? -ne 1
22 then
23     skip_all='skipping git svn tests, svn not found'
24     test_done
25 fi
26
27 svnrepo=$PWD/svnrepo
28 export svnrepo
29 svnconf=$PWD/svnconf
30 export svnconf
31
32 perl -w -e "
33 use SVN::Core;
34 use SVN::Repos;
35 \$SVN::Core::VERSION gt '1.1.0' or exit(42);
36 system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
37 " >&3 2>&4
38 x=$?
39 if test $x -ne 0
40 then
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
49 fi
50
51 rawsvnrepo="$svnrepo"
52 svnrepo="file://$svnrepo"
53
54 poke() {
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.
61 svn_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
71 maybe_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
89 convert_to_rev_db () {
90         perl -w -- - "$@" <<\EOF
91 use strict;
92 @ARGV == 2 or die "usage: convert_to_rev_db <input> <output>";
93 open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
94 open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
95 my $size = (stat($rd))[7];
96 ($size % 24) == 0 or die "Inconsistent size: $size";
97 while (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 }
110 close $wr or die $!;
111 close $rd or die $!;
112 EOF
113 }
114
115 require_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
123 start_svnserve () {
124     svnserve --listen-port $SVNSERVE_PORT \
125              --root "$rawsvnrepo" \
126              --listen-once \
127              --listen-host 127.0.0.1 &
128 }
129
130 prepare_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 }