aboutsummaryrefslogtreecommitdiff
blob: c031ae3a8c6343e9f4d719c3351af909ac9a82c2 (plain)
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
. @CONFIG_EPREFIX@lib/gentoo/functions.sh 2>/dev/null || :

# get the built q in PATH
PATH="@abs_top_builddir@:$PATH"

setup_env() {
	local a=${0%/*}
	[[ ${a} == "." ]] && a=${PWD}
	a=${a##*/}

	: ${b:=@builddir@}
	: ${s:=@srcdir@}
	: ${atb:=@abs_top_builddir@}
	: ${ats:=@abs_top_srcdir@}
	: ${ab:=${atb}/tests/${a}}
	: ${as:=${ats}/tests/${a}}

	if [[ -z ${GOOD} ]] && [[ -d ${ats}/.git ]] ; then
		eval $(eval_ecolors 2>/dev/null)
	fi
}
setup_env

# clean any random vars from the host system
unset ROOT PORTAGE_CONFIGROOT PORTAGE_QUIET
# but make sure we don't implicitly rely on user's setup
export PORTAGE_CONFIGROOT="${ab}/not/a/real/path"
# Always use UTC for timestamps to keep tests stable. #551806
export TZ='UTC 0'

# create symlinks for applets
q -i -q

tret=0
tpassed=0
tfailed=0

tfail() {
	echo "${BAD}FAIL:${NORMAL} $*"
	: $(( ++tfailed ))
	tret=1
	return 1
}
tpass() {
	echo "${GOOD}PASS:${NORMAL} $*"
	: $(( ++tpassed ))
	return 0
}
tend() {
	local r=$1; shift
	[[ $r -eq 0 ]] && tpass "$@" || tfail "$@"
	return $r
}

die() {
	tfail "$@"
	end
}

skip() {
	echo "${WARN}SKIPPED:${NORMAL} $*"
	exit 0
}

end() {
	echo "${HILITE}${PWD##*/}:${NORMAL} ${tpassed} passes / ${tfailed} fails"
	exit ${tret}
}

mktmpdir() {
	local d=${1:-${ab}/tmp}
	rm -rf "$d" && \
	mkdir -p "$d" && \
	pushd "$d" >/dev/null \
		|| fail "could not make tmp dir '$d'"
}
_cleantmpdir() {
	local cmd=$1; shift
	local d=${1:-${ab}/tmp}
	popd >/dev/null
	${cmd} "${d}" || fail "could not clean tmp dir '$d'"
}
cleantmpdir() { _cleantmpdir "rm -rf" "$@" ; }
trimtmpdir() { _cleantmpdir "rmdir" "$@" ; }

treedir() {
	local d=$1
	if ! tree "${d}" 2>/dev/null ; then
		ls -R "${d}"
	fi
}

mkportdir() {
	export PORTDIR=$1

	export PORTAGE_CONFIGROOT=${PWD}
	mkdir -p etc/portage/
	cat <<-EOF >etc/portage/repos.conf
	[DEFAULT]
	main-repo = utils-test
	[utils-test]
	location = ${PORTDIR}
	EOF
}