CodingGuidelines: mention "static" and "extern"
[git.git] / t / interop / interop-lib.sh
blob3e0a2911d4f9baa889eef85877a6332b27015dfc
1 # Interoperability testing framework. Each script should source
2 # this after setting default $VERSION_A and $VERSION_B variables.
4 . ../../GIT-BUILD-OPTIONS
5 INTEROP_ROOT=$(pwd)
6 BUILD_ROOT=$INTEROP_ROOT/build
8 build_version () {
9 if test -z "$1"
10 then
11 echo >&2 "error: test script did not set default versions"
12 return 1
15 if test "$1" = "."
16 then
17 git rev-parse --show-toplevel
18 return 0
21 sha1=$(git rev-parse "$1^{tree}") || return 1
22 dir=$BUILD_ROOT/$sha1
24 if test -e "$dir/.built"
25 then
26 echo "$dir"
27 return 0
30 echo >&2 "==> Building $1..."
32 mkdir -p "$dir" || return 1
34 (cd "$(git rev-parse --show-cdup)" && git archive --format=tar "$sha1") |
35 (cd "$dir" && tar x) ||
36 return 1
38 for config in config.mak config.mak.autogen config.status
40 if test -e "$INTEROP_ROOT/../../$config"
41 then
42 cp "$INTEROP_ROOT/../../$config" "$dir/" || return 1
44 done
47 cd "$dir" &&
48 make $GIT_INTEROP_MAKE_OPTS >&2 &&
49 touch .built
50 ) || return 1
52 echo "$dir"
55 # Old versions of git don't have bin-wrappers, so let's give a rough emulation.
56 wrap_git () {
57 write_script "$1" <<-EOF
58 GIT_EXEC_PATH="$2"
59 export GIT_EXEC_PATH
60 PATH="$2:\$PATH"
61 export GIT_EXEC_PATH
62 exec git "\$@"
63 EOF
66 generate_wrappers () {
67 mkdir -p .bin &&
68 wrap_git .bin/git.a "$DIR_A" &&
69 wrap_git .bin/git.b "$DIR_B" &&
70 write_script .bin/git <<-\EOF &&
71 echo >&2 fatal: test tried to run generic git
72 exit 1
73 EOF
74 PATH=$(pwd)/.bin:$PATH
77 VERSION_A=${GIT_TEST_VERSION_A:-$VERSION_A}
78 VERSION_B=${GIT_TEST_VERSION_B:-$VERSION_B}
80 if ! DIR_A=$(build_version "$VERSION_A") ||
81 ! DIR_B=$(build_version "$VERSION_B")
82 then
83 echo >&2 "fatal: unable to build git versions"
84 exit 1
87 TEST_DIRECTORY=$INTEROP_ROOT/..
88 TEST_OUTPUT_DIRECTORY=$INTEROP_ROOT
89 TEST_NO_CREATE_REPO=t
90 . "$TEST_DIRECTORY"/test-lib.sh
92 generate_wrappers || die "unable to set up interop test environment"