aboutsummaryrefslogtreecommitdiff
path: root/tests/lib.sh
blob: 251f314c99bbd532417fd32c039a935d6d0cda6c (plain) (blame)
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
#!/bin/sh

export XDG_DATA_HOME="$PWD/tests/test-profiles"
OUT=
ERR=
STATUS=

assert_status() {
	if [ "$STATUS" != "$1" ]; then
		printf '\nERR: Bad status.\n\nexpected: %s\ngot:      %s\n' \
			"$1" "$STATUS" >&2
		exit 1
	fi
}

assert_empty_stderr() {
	if [ "$(cat "$ERR")" != '' ]; then
		printf '\nERR: Expected STDERR (%s) to be empty, but has content:\n%s\n' \
			"$ERR" "$(cat "$ERR")" >&2
		exit 1
	fi
}

assert_stdout() {
	if [ "$(cat "$OUT")" != "$1" ]; then
		printf '\nERR: Bad STDOUT (%s)\n\nexpected: %s\ngot:      %s\n' \
			"$OUT" "$1" "$(cat "$OUT")" >&2
		exit 1
	fi
}

uuid() {
	# Taken from:
	# https://serverfault.com/a/799198
	od -x /dev/urandom | \
		head -1 | \
		awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
}

testing() {
	printf 'testing: %s...' "$1" >&2
}

test_ok() {
	printf ' OK.\n' >&2
}