blob: c1271d686372dfd46d640a84ebec3971933ed4f2 [file] [log] [blame]
Eric Wong36f5b1f2006-05-23 19:23:41 -07001. ./test-lib.sh
2
Eric Wong60d02cc2006-07-06 00:14:16 -07003if test -n "$NO_SVN_TESTS"
4then
Ævar Arnfjörð Bjarmasonfadb5152010-06-24 17:44:48 +00005 skip_all='skipping git svn tests, NO_SVN_TESTS defined'
Eric Wong60d02cc2006-07-06 00:14:16 -07006 test_done
Eric Wong60d02cc2006-07-06 00:14:16 -07007fi
Jeff King1b19ccd2009-04-03 15:33:59 -04008if ! test_have_prereq PERL; then
Ævar Arnfjörð Bjarmasonfadb5152010-06-24 17:44:48 +00009 skip_all='skipping git svn tests, perl not available'
Jeff King1b19ccd2009-04-03 15:33:59 -040010 test_done
11fi
Eric Wong60d02cc2006-07-06 00:14:16 -070012
Eric Wong36f5b1f2006-05-23 19:23:41 -070013GIT_DIR=$PWD/.git
Adam Brewster6f5748e2009-08-11 23:14:27 -040014GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
Eric Wonga5e0ced2006-06-12 15:23:48 -070015SVN_TREE=$GIT_SVN_DIR/svn-tree
SZEDER Gáborfa840582019-01-05 02:08:58 +010016test_set_port SVNSERVE_PORT
Eric Wong36f5b1f2006-05-23 19:23:41 -070017
Eric Wong36f5b1f2006-05-23 19:23:41 -070018svn >/dev/null 2>&1
Junio C Hamano4b832e82006-07-07 03:17:16 -070019if test $? -ne 1
Eric Wong36f5b1f2006-05-23 19:23:41 -070020then
Todd Zullinger78109772017-12-01 10:56:52 -050021 skip_all='skipping git svn tests, svn not found'
22 test_done
Eric Wong36f5b1f2006-05-23 19:23:41 -070023fi
24
25svnrepo=$PWD/svnrepo
Bryan Donlancdf3ec02008-05-04 01:37:57 -040026export svnrepo
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040027svnconf=$PWD/svnconf
28export svnconf
Eric Wong36f5b1f2006-05-23 19:23:41 -070029
Jeff King94221d22013-10-28 21:23:03 -040030perl -w -e "
Eric Wongc6d499a2006-12-31 21:49:45 -080031use SVN::Core;
32use SVN::Repos;
33\$SVN::Core::VERSION gt '1.1.0' or exit(42);
Bryan Donlancdf3ec02008-05-04 01:37:57 -040034system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
Shawn O. Pearce38434f22007-01-14 03:22:47 -050035" >&3 2>&4
Eric Wongc6d499a2006-12-31 21:49:45 -080036x=$?
37if test $x -ne 0
Eric Wongdc62e252006-06-28 03:07:14 -070038then
Eric Wongc6d499a2006-12-31 21:49:45 -080039 if test $x -eq 42; then
Ævar Arnfjörð Bjarmasone8344e82010-07-08 01:16:06 +000040 skip_all='Perl SVN libraries must be >= 1.1.0'
Eric Wonge66191f2007-01-13 02:47:53 -080041 elif test $x -eq 41; then
Ævar Arnfjörð Bjarmasone8344e82010-07-08 01:16:06 +000042 skip_all='svnadmin failed to create fsfs repository'
Eric Wongc6d499a2006-12-31 21:49:45 -080043 else
Ævar Arnfjörð Bjarmasone8344e82010-07-08 01:16:06 +000044 skip_all='Perl SVN libraries not found or unusable'
Eric Wongc6d499a2006-12-31 21:49:45 -080045 fi
Eric Wongc6d499a2006-12-31 21:49:45 -080046 test_done
Eric Wongdc62e252006-06-28 03:07:14 -070047fi
48
sam@vilain.net2edb9c52006-12-05 16:17:38 +110049rawsvnrepo="$svnrepo"
Eric Wonge1516112006-11-27 21:46:50 -080050svnrepo="file://$svnrepo"
Eric Wong36f5b1f2006-05-23 19:23:41 -070051
Michael Spang7b3fab82007-02-12 19:33:37 -050052poke() {
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +010053 test-tool chmtime +1 "$1"
Michael Spang7b3fab82007-02-12 19:33:37 -050054}
Eric Wong29633bb2007-07-15 21:53:50 -070055
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040056# We need this, because we should pass empty configuration directory to
57# the 'svn commit' to avoid automated property changes and other stuff
58# that could be set from user's configuration files in ~/.subversion.
59svn_cmd () {
60 [ -d "$svnconf" ] || mkdir "$svnconf"
61 orig_svncmd="$1"; shift
62 if [ -z "$orig_svncmd" ]; then
63 svn
64 return
65 fi
66 svn "$orig_svncmd" --config-dir "$svnconf" "$@"
67}
68
Eric Wonga8a5d252016-07-23 04:26:08 +000069maybe_start_httpd () {
70 loc=${1-svn}
Eric Wong29633bb2007-07-15 21:53:50 -070071
Eric Wonga8a5d252016-07-23 04:26:08 +000072 test_tristate GIT_SVN_TEST_HTTPD
73 case $GIT_SVN_TEST_HTTPD in
74 true)
75 . "$TEST_DIRECTORY"/lib-httpd.sh
76 LIB_HTTPD_SVN="$loc"
77 start_httpd
78 ;;
Eric Wonga8a5d252016-07-23 04:26:08 +000079 esac
Eric Wong29633bb2007-07-15 21:53:50 -070080}
Eric Wong060610c2007-12-08 23:27:41 -080081
82convert_to_rev_db () {
Jeff King94221d22013-10-28 21:23:03 -040083 perl -w -- - "$@" <<\EOF
Eric Wong060610c2007-12-08 23:27:41 -080084use strict;
David Aguilarb9784032013-02-24 14:48:39 -080085@ARGV == 2 or die "usage: convert_to_rev_db <input> <output>";
Eric Wong060610c2007-12-08 23:27:41 -080086open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
87open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
88my $size = (stat($rd))[7];
89($size % 24) == 0 or die "Inconsistent size: $size";
90while (sysread($rd, my $buf, 24) == 24) {
91 my ($r, $c) = unpack('NH40', $buf);
92 my $offset = $r * 41;
93 seek $wr, 0, 2 or die $!;
94 my $pos = tell $wr;
95 if ($pos < $offset) {
96 for (1 .. (($offset - $pos) / 41)) {
97 print $wr (('0' x 40),"\n") or die $!;
98 }
99 }
100 seek $wr, $offset, 0 or die $!;
101 print $wr $c,"\n" or die $!;
102}
103close $wr or die $!;
104close $rd or die $!;
105EOF
106}
Alec Berrymandd9da512008-09-14 17:14:15 -0400107
108require_svnserve () {
Todd Zullingerbf9d7df2017-12-01 10:56:53 -0500109 test_tristate GIT_TEST_SVNSERVE
110 if ! test "$GIT_TEST_SVNSERVE" = true
Todd Zullinger78109772017-12-01 10:56:52 -0500111 then
Todd Zullingerbf9d7df2017-12-01 10:56:53 -0500112 skip_all='skipping svnserve test. (set $GIT_TEST_SVNSERVE to enable)'
Todd Zullinger78109772017-12-01 10:56:52 -0500113 test_done
114 fi
Alec Berrymandd9da512008-09-14 17:14:15 -0400115}
116
117start_svnserve () {
Todd Zullinger78109772017-12-01 10:56:52 -0500118 svnserve --listen-port $SVNSERVE_PORT \
119 --root "$rawsvnrepo" \
120 --listen-once \
121 --listen-host 127.0.0.1 &
Alec Berrymandd9da512008-09-14 17:14:15 -0400122}
123
Eric Wong3df0d262016-02-22 02:17:51 +0000124prepare_a_utf8_locale () {
125 a_utf8_locale=$(locale -a | sed -n '/\.[uU][tT][fF]-*8$/{
126 p
127 q
128}')
129 if test -n "$a_utf8_locale"
130 then
131 test_set_prereq UTF8
132 else
133 say "# UTF-8 locale not available, some tests are skipped"
134 fi
135}