File: debcraft-tests.sh

package info (click to toggle)
debcraft 0.8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 360 kB
  • sloc: sh: 2,081; makefile: 47
file content (160 lines) | stat: -rwxr-xr-x 4,428 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash

# stop on any unhandled error
set -e

# @TODO: pipefail not in POSIX
set -o pipefail

# show commands (debug)
#set -x

# Get screen width from tput, pad with space and put '=' in with sed
SEPARATOR="$(printf "%$(tput cols)s" | sed 's/ /=/g')"

function debcraft_test() {
  COMMAND_TO_TEST="$1"
  EXPECTED_OUTPUT_LAST_LINE_START="$2"
  IGNORE_NONZERO_EXIT_CODE="$3"

  ((TEST_NUMBER=TEST_NUMBER+1))

  echo "$SEPARATOR"
  echo "Executing test number $TEST_NUMBER (debcraft $COMMAND_TO_TEST)..."
  echo

  eval "$DEBCRAFT_CMD $COMMAND_TO_TEST" | tee "$TEMPDIR/test-$TEST_NUMBER.log" || RET=$?

  # Reset exit code to zero if test should not fail on it
  if [ -n "$IGNORE_NONZERO_EXIT_CODE" ]
  then
    RET=''
  fi

  # Get last line and strip
  # 1. ANSI color codes
  # 2. OSC8 hyperlink start: ESC]8;;URL\7
  # 3. OSC8 hyperlink end: ESC]8;;\7
  TEST_OUTPUT_LAST_LINE="$(tail --lines=1 "$TEMPDIR/test-$TEST_NUMBER.log" \
    | sed -e 's/\x1b\[[0-9;]*[mK]//g' \
          -e 's/\x1b]8;;[^\x07]*\x07//g' \
          -e 's/\x1b]8;;\x07//g')"

  echo

  echo "Test number $TEST_NUMBER (debcraft $COMMAND_TO_TEST)"
  echo "completed with: $TEST_OUTPUT_LAST_LINE"
  echo "expected start: $EXPECTED_OUTPUT_LAST_LINE_START"

  # Note wildcard at end - the expected result only needs to match the start
  if [[ "$TEST_OUTPUT_LAST_LINE" == "$EXPECTED_OUTPUT_LAST_LINE_START"* ]] && \
     [ -z "$RET" ]
  then
    echo "TEST PASSED"
  else
    echo "ERROR: TEST FAILED (exit code $RET)"
    echo "For full test log see $TEMPDIR/test-$TEST_NUMBER.log"
    exit 1
  fi
}

TEST_CMD_PATH="$(readlink --canonicalize-existing --verbose "$0")"
DEBCRAFT_TEST_SRC_DIR="$(dirname "$TEST_CMD_PATH")"
DEBCRAFT_SRC_DIR="$(dirname "$DEBCRAFT_TEST_SRC_DIR")"
DEBCRAFT_CMD="$DEBCRAFT_SRC_DIR/debcraft.sh"

TEST_NUMBER=0

# Don't use any cache or compare to build logs from potential previous test runs
BUILD_DIRS_PATH="$(mktemp --directory)"
# Will be used inside debcraft.sh
export BUILD_DIRS_PATH

TEMPDIR="$(mktemp --directory)"

cd "$TEMPDIR" || exit 1

echo "Using directory $TEMPDIR for logs and artifacts in "

debcraft_test "help" "and www.debian.org/doc/debian-policy/" IGNORE_NONZERO_EXIT_CODE

# Prepare test git repository
# @TODO: Clone remote only if needed, otherwise reuse local clones
echo "$SEPARATOR" # Extra separator for test bed modifications

# Set TERM for tput in CI environments
if [ -z "${TERM:-}" ]
then
  export TERM=dumb
fi

gbp clone --pristine-tar --debian-branch=debian/latest https://salsa.debian.org/debian/entr.git
debcraft_test "build entr" "Artifacts at /"

cd entr

echo "$SEPARATOR" # Extra separator for test bed modifications
git clean -fdx

if [ -n "${CI:-}" ]
then
  debcraft_test "build" "Artifacts at"
else
  debcraft_test "build" "  browse /"
fi

echo "$SEPARATOR" # Extra separator for test bed modifications
git clean -fdx

if [ -n "${CI:-}" ]
then
  debcraft_test "build ." "Artifacts at"
else
  debcraft_test "build ." "  browse /"
fi

echo "$SEPARATOR" # Extra separator for test bed modifications
git reset --hard
git clean -fdx
rm --recursive --force --verbose .git
# Once git is deleted, there are no sources available for the build
debcraft_test "build --skip-sources" "Artifacts at /"

cd .. # exit 'entr' subdirectory

echo "$SEPARATOR" # Extra separator for test bed modifications
gbp clone https://salsa.debian.org/mariadb-team/galera-4.git
cd galera-4
export DEB_BUILD_OPTIONS="parallel=4 nocheck noautodbgsym"
debcraft_test "build --skip-sources --clean" "Cleaning and resetting"
export DEB_BUILD_OPTIONS=""
cd ..

# Skip remaining tests in GitLab CI
# These builds currently fail in the CI environment due to Docker-in-Docker
# bind mount limitations. They work locally but require follow-up fixes
# to properly handle source extraction in DinD setups.
if [ -n "${GITLAB_CI:-}" ]
then
  echo "Skipping tests affected by Docker-in-Docker mount issues in GitLab CI"
  exit 0
fi

mkdir hello-debhelper
cd hello-debhelper
for FILE in https://archive.debian.org/debian/pool/main/h/hello-debhelper/hello-debhelper_2.9.1.{tar.xz,dsc}
do
  curl -LO "$FILE"
done
debcraft_test "build hello-debhelper_2.9.1.dsc" "Artifacts at /"

# Run remaining tests from top-level
cd ..

debcraft_test "build molly-guard" "Artifacts at /"

debcraft_test "build https://salsa.debian.org/patryk/qnapi.git" "Artifacts at /"

echo "$SEPARATOR"
echo "Success! All $TEST_NUMBER Debcraft tests passed."
echo