summaryrefslogtreecommitdiff
path: root/test/test-common.sh
blob: e8374984999e65f17de90f0b721e8b43f3d6a01f (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
#!/bin/bash

_before() {
	tmpdir="$(mktemp -d --tmpdir "test-$1.XXXXXXXXXXXX")"
	stat=0
}

_after() {
	if [[ $SUDO ]]; then
		sudo rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME"
	else
		rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME"
	fi
}

require() {
	local missing=()
	if libremessages in_array "network" "$@" && ! [[ $NETWORK ]]; then
		missing+=('networking')
	fi
	if libremessages in_array "sudo" "$@" && ! [[ $SUDO ]]; then
		missing+=('sudo')
	fi
	if (( ${#missing[@]} )); then
		libremessages warning "Next test requires %s; Skipping (passing)..." "$(echo "${missing[@]}"|sed 's/ /, /g')" &>/dev/tty
		return 1
	fi
	return 0;
}