summaryrefslogtreecommitdiffstats
path: root/tests/testlib.sh
blob: d3fe350facc3ec103b7f2d11e196577177209764 (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
assert()
{
	if ! t_out=$(eval 2>&1 "${@}"); then
		printf 'Assertion failed: %s\n' "${*}"
		printf '%s\n' "${t_out}" | sed 's/^/    /'
		t_fail='true'
	fi
}

test_nodes()
{
	t_dir="${1}"
	shift 1
	if [ ${#} -gt 0 ]; then
		printf "${t_dir}%s\n" "${@}" | sort >expected
	else
		>expected
	fi
	find "${t_dir}" -exec ls -dF '{}' ';' | sort >actual
	diff -u expected actual
	t_ret=${?}
	rm -f expected actual
	return ${t_ret}
}

test_non_dir_nodes()
{
	t_dir="${1}"
	shift 1
	if [ ${#} -gt 0 ]; then
		printf "${t_dir}%s\n" "${@}" | sort >expected
	else
		>expected
	fi
	find "${t_dir}" ! -type d | sort >actual
	diff -u expected actual
	t_ret=${?}
	rm -f expected actual
	return ${t_ret}
}