File: phpunit-autopkgtest

package info (click to toggle)
pkg-php-tools 1.49
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 528 kB
  • sloc: php: 1,737; sh: 501; perl: 444; xml: 184; makefile: 17
file content (92 lines) | stat: -rwxr-xr-x 2,828 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash

# we pass the autoloaders of all the binary packages shipped by the source
# package being tested to phpabtpl with --require-file to ensure we will load
# the installed version of the package.  then, we can pass the autoloaders of
# all build dependencies which are not also runtime dependencies with
# require-file as well. We do not need the autoloaders of the runtime
# dependencies because those are already contemplated by the tested binary
# package autoloaders.

set -eo pipefail

append_extra_requirements() {
  ret=
  for AUTOLOADER in "$@"; do
    ret=$(cat <<EOF
$ret \
--require-file $AUTOLOADER
EOF
)
  done
  echo "$ret"
}

TEST_DIR=tests

BINARY_PACKAGES=$(grep-dctrl -n -s Package -F Package -r '^.*$' debian/control)
SED_DEP_STR='/^\s*$/ d; /^debhelper/ d; /^phpunit$/ d; /^phpab$/ d; /^phpabtpl$/ d; /^pkg-php-tools$/ d; /^dh-sequence-phpcomposer$/ d; /^dh-sequence-phppear$/ d; s/\n/, /'

# parse d/control to get B-Ds and Ds and compare the diff
# we want things that are in B-D but not in D
builddeps=$(
  grep-dctrl -n -s Build-Depends -F Build-Depends -r . debian/control \
  | grep -v '^\s*#' \
  | sed -e 's/,\s*/\n/g; s/^\s*//' \
  | sed -e 's/\s*<[^)]*>\s*$//' \
  | cut -d ' ' -f1 \
  | sed "$SED_DEP_STR" \
  | sort -u
)

deps=
for pkg in ${BINARY_PACKAGES}; do
  deps+=$(
    dpkg-query -f '${Depends}\n' -W "$pkg" \
    | sed -e 's/,\s*/\n/g; s/^\s*//' \
    | sed -e 's/\s*<[^)]*>\s*$//' \
    | cut -d ' ' -f1 \
    | sed "$SED_DEP_STR" \
    | sort -u
  )
done
deps=$(echo "$deps" | sort -u)

# we only want the build deps which are not deps as well
dep_diff=$(comm -23 <(echo "$builddeps") <(echo "$deps"))

BINARY_PACKAGES+=" ${dep_diff}"

# parse d/control to get bin package names and find autoload.php files for the package(s) being tested
AUTOLOADERS=
for pkg in ${BINARY_PACKAGES}; do
    PKG_AUTOLOADERS=$(dpkg -L "$pkg" | grep -E '/usr/share/php/.+/autoload(er)?.php') || true
    if [ -z "$PKG_AUTOLOADERS" ]; then
        continue
    elif [ $(wc -w <<< "${PKG_AUTOLOADERS}") -ne 1 ]; then
        # This case may refer to examples or more complex packages. Let's skip them for now
        echo "Package ${pkg} has multiple autoloaders, which is not supported. Aborting."
        exit 1
    else
        if [ -n "${AUTOLOADERS}" ]; then
            AUTOLOADERS="${AUTOLOADERS} ${PKG_AUTOLOADERS}"
        else
            AUTOLOADERS="${PKG_AUTOLOADERS}"
        fi
    fi
done

if [ -z "$AUTOLOADERS" ]; then
    echo "ERROR: No autoload.php script found in binary packages: ${BINARY_PACKAGES}"
    exit 1
fi

mkdir -p vendor
phpabtpl \
  $(append_extra_requirements $AUTOLOADERS) \
  > debian/autoload.tests.php.tpl
phpab \
  --output vendor/autoload.php \
  --template debian/autoload.tests.php.tpl \
  ${TEST_DIR}
phpunit --bootstrap=vendor/autoload.php ${TEST_DIR}