File: run-tests

package info (click to toggle)
debputy 0.1.81
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,748 kB
  • sloc: python: 66,966; sh: 164; perl: 155; makefile: 43; ansic: 5
file content (75 lines) | stat: -rwxr-xr-x 2,355 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/sh

set -e

TEST_SOURCE_ROOT_DIR="$(readlink -f "$(dirname "$0")")"
ARG="$1"
if [ x"${ARG}" = xinstalled ]; then
    INSTALLED=yes
    DEBPUTY_SRC_ROOT_DIR=""
    DEBPUTY_CMD="debputy"
elif [ -d "${ARG}" ]; then
    INSTALLED=no
    DEBPUTY_SRC_ROOT_DIR="${ARG}"
    DEBPUTY_CMD="${DEBPUTY_SRC_ROOT_DIR}/debputy.sh"
else
    echo "Usage: $0 [installed | <path/to/debputy-src-dir>]" >&2
    exit 1
fi

if ! "${DEBPUTY_CMD}" --help > /dev/null ; then
    echo "Cannot run ${DEBPUTY_CMD} --help - the test" >&2
    exit 1
fi

echo "Running end-to-end build tests"


TEST_BUILD_ROOT_DIR="$(mktemp -d --suffix=debputy.e2e)"

run() {
    echo "Running: $@"
    "$@"
}

if [ "${INSTALLED}" != "yes" ]; then
    if [ x"${PERL5LIB}" = x ]; then
        PERL5LIB="${DEBPUTY_SRC_ROOT_DIR}/lib"
    else
        PERL5LIB="${DEBPUTY_SRC_ROOT_DIR}/lib:${PERL5LIB}"
    fi
    export PERL5LIB="${PERL5LIB}"
    mkdir "${TEST_BUILD_ROOT_DIR}/_path"
    ln -s "${DEBPUTY_CMD}" "${TEST_BUILD_ROOT_DIR}/_path/debputy"
    ln -s "${DEBPUTY_SRC_ROOT_DIR}/dh_installdebputy" "${TEST_BUILD_ROOT_DIR}/_path/dh_installdebputy"
    ln -s "${DEBPUTY_SRC_ROOT_DIR}/dh_debputy" "${TEST_BUILD_ROOT_DIR}/_path/dh_debputy"
    echo "Tweaked PERL5LIB and PATH"
    export PATH="${TEST_BUILD_ROOT_DIR}/_path:${PATH}"
fi


for test_src_dir in "${TEST_SOURCE_ROOT_DIR}"/*/; do
  testname="$(basename "${test_src_dir}")"
  trootdir="${TEST_BUILD_ROOT_DIR}/${testname}"
  tdir="${TEST_BUILD_ROOT_DIR}/${testname}/unpacked-source"
  run mkdir "${trootdir}"
  run cp -a "${test_src_dir}" "${tdir}"
  if [ -f "${tdir}/debian/rules" ]; then
      # Replace `d/rules` with a symlink to the real file. This little hack makes the e2e work when
      # TMPDIR is mounted `noexec` (and the test does not call any scripts).
      rm -f "${tdir}/debian/rules"
      ln -s "${test_src_dir}/debian/rules" "${tdir}/debian/rules"
  fi
  T_RC=0
  (run env -C "${tdir}" dpkg-buildpackage -us -uc -b -d > "${tdir}/../output.log" 2>&1) || T_RC=$?
  if [ ${T_RC} != 0 ]; then
    tail -n 100 "${tdir}/../output.log"
    echo "ERROR: ${testname}. Test dir at ${tdir} for debugging (full output in ${tdir}/../output.log)" >&2
    exit 1
  fi
  rm -fr "${trootdir}"
  echo "OK: ${testname}."
done
rm -fr "${TEST_BUILD_ROOT_DIR}/_path"
rmdir "${TEST_BUILD_ROOT_DIR}"
echo "All end-to-end tests successful"