]> git.ipfire.org Git - thirdparty/git.git/blame - t/lib-git-p4.sh
git-submodule.sh: fix filename in comment.
[thirdparty/git.git] / t / lib-git-p4.sh
CommitLineData
fc002330 1#
6ab1d76c 2# Library code for git p4 tests
fc002330
PW
3#
4
5. ./test-lib.sh
6
7if ! test_have_prereq PYTHON; then
6ab1d76c 8 skip_all='skipping git p4 tests; python not available'
fc002330
PW
9 test_done
10fi
11( p4 -h && p4d -h ) >/dev/null 2>&1 || {
6ab1d76c 12 skip_all='skipping git p4 tests; no p4 or p4d'
fc002330
PW
13 test_done
14}
15
fc002330
PW
16# Try to pick a unique port: guess a large number, then hope
17# no more than one of each test is running.
18#
19# This does not handle the case where somebody else is running the
20# same tests and has chosen the same ports.
21testid=${this_test#t}
22git_p4_test_start=9800
23P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
24
25export P4PORT=localhost:$P4DPORT
26export P4CLIENT=client
1e3e7180 27export P4EDITOR=:
fc002330
PW
28
29db="$TRASH_DIRECTORY/db"
30cli="$TRASH_DIRECTORY/cli"
31git="$TRASH_DIRECTORY/git"
32pidfile="$TRASH_DIRECTORY/p4d.pid"
33
34start_p4d() {
35 mkdir -p "$db" "$cli" "$git" &&
36 (
37 p4d -q -r "$db" -p $P4DPORT &
38 echo $! >"$pidfile"
39 ) &&
40 for i in 1 2 3 4 5 ; do
41 p4 info >/dev/null 2>&1 && break || true &&
42 echo waiting for p4d to start &&
43 sleep 1
44 done &&
45 # complain if it never started
46 p4 info >/dev/null &&
47 (
48 cd "$cli" &&
49 p4 client -i <<-EOF
50 Client: client
51 Description: client
52 Root: $cli
53 View: //depot/... //client/...
54 EOF
55 )
56}
57
58kill_p4d() {
59 pid=$(cat "$pidfile")
60 # it had better exist for the first kill
61 kill $pid &&
62 for i in 1 2 3 4 5 ; do
63 kill $pid >/dev/null 2>&1 || break
64 sleep 1
65 done &&
66 # complain if it would not die
67 test_must_fail kill $pid >/dev/null 2>&1 &&
68 rm -rf "$db" "$cli" "$pidfile"
69}
70
71cleanup_git() {
72 rm -rf "$git"
73}