blob: da7934d16965fc9664b5a7a02e67e7bf752f2ff2 (
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
|
#!/bin/bash
cd $(dirname $0)
nft=../../src/nft
nft_opts="-nn -a --echo"
debug=false
debug_echo() {
$debug || return
echo "$@"
}
trap "$nft flush ruleset" EXIT
for testcase in testcases/*.t; do
echo "running tests from file $(basename $testcase)"
# files are like this:
#
# <input command>[;;<output regexp>]
$nft flush ruleset
while read line; do
[[ -z "$line" || "$line" == "#"* ]] && continue
# XXX: this only works if there is no semicolon in output
input="${line%;;*}"
output="${line##*;;}"
[[ -z $output ]] && output="$input"
debug_echo "calling '$nft $nft_opts $input'"
cmd_out=$($nft $nft_opts $input)
# strip trailing whitespace (happens when adding a named set)
cmd_out="${cmd_out% }"
debug_echo "got output '$cmd_out'"
[[ $cmd_out == $output ]] || {
echo "Warning: Output differs:"
echo "# nft $nft_opts $input"
echo "- $output"
echo "+ $cmd_out"
}
done <$testcase
done
|