File: cargo-auto-test

package info (click to toggle)
dh-cargo 24
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 52 kB
  • sloc: sh: 192; perl: 153; makefile: 2
file content (85 lines) | stat: -rwxr-xr-x 2,630 bytes parent folder | download | duplicates (3)
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
#!/bin/bash
# Run `cargo test` on an installed Debian crate, e.g. in an autopkgtest.
#
# Requires dev-dependencies to be installed. If you give extra flags such as
# "--all-features", then these features' dependencies must also be installed.
#
# This script also swallows some known false-positive test failures, so you
# don't have to set test_is_broken everywhere in your debcargo.toml configs.

set -e

pkg="$1"
ver="$2"

if [ -z "$pkg" -o -z "$ver" ]; then
	echo >&2 "Usage: $0 <crate> <version> [<extra test flags, e.g. --all-features>]"
	exit 2
fi
shift 2

pkgdir="/usr/share/cargo/registry/${pkg}-${ver}"
if [ ! -d "$pkgdir" ]; then
	echo >&2 "crate directory not found: $pkgdir"
	exit 1
fi
cd "$pkgdir"

rundir=$(mktemp -d)
# https://stackoverflow.com/a/14812383 inside "trap" avoids running handler twice
trap 'excode=$?; rm -rf "'"$rundir"'"; trap - EXIT' EXIT HUP INT QUIT PIPE TERM

# set envvars necessary for cargo-debian-wrapper

export DEB_CARGO_CRATE="${pkg}_${ver}"
export CARGO_HOME="$rundir/debian/cargo_home"
mkdir -p "$CARGO_HOME"
mkdir -p "$rundir/registry"

. <(dpkg-buildflags --export)
. <(dpkg-architecture -s)
RUST_TYPE="$(rustc --version --verbose | sed -ne 's/^host: //p')"
export DEB_HOST_RUST_TYPE="$RUST_TYPE"
export DEB_BUILD_RUST_TYPE="$RUST_TYPE"
export DEB_TARGET_RUST_TYPE="$RUST_TYPE"

export CARGO_TARGET_DIR="$rundir/target"
export PATH="/usr/share/cargo/bin:$PATH"

# run the test!

if [ -t 2 ]; then flags="--color=always"; export RUSTDOCFLAGS="--color=always"; fi

run_test() {
	local n="$1"
	shift
	{ cargo test $flags "$@" 2>&1; echo "$?" > "$rundir/run-$n.ec"; } | tee "$rundir/run-$n.log"
	sed -i -e 's/\x1b\[[0-9;]*m//g' "$rundir/run-$n.log" # rm ansi colour codes
	local x="$(< "$rundir/run-$n.ec")"
	if [ "$x" = "0" ]; then
		return 0
	fi
	local e="$(egrep -o '^error\[E[0-9]+\]' "$rundir/run-$n.log" | sort -u | tr '\n' ',')"
	# some crates like to update their old versions to depend on their new
	# versions, e.g. rand-core. unfortunately this breaks cargo test, see
	# https://github.com/rust-lang/cargo/issues/6819. so just ignore them.
	if [ "$e" = "error[E0463],error[E0465]," ]; then
		echo "cargo-auto-test: ignore test failure due to upstream #6819: $e"
		return 0
	fi
	return "$x"
}

set +e

cargo prepare-debian "$rundir/registry" --link-from-system

run_test 0 "$@"
x="$?"
if [ "$x" = "0" ]; then exit 0; fi
if ! egrep -q '^error\[E0554\]' "$rundir/run-0.log"; then exit "$x"; fi

echo
echo "----------------------------------------------------------------"
echo "cargo-auto-test: re-running test with RUSTC_BOOTSTRAP due to E0554"
RUSTC_BOOTSTRAP=1 run_test 1 "$@"