-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_script
More file actions
executable file
·64 lines (54 loc) · 1.51 KB
/
test_script
File metadata and controls
executable file
·64 lines (54 loc) · 1.51 KB
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
#!/bin/bash
#
# A simple framework for testing the bn scripts
#
# Returns the number of failed test cases.
#
# Format of a test:
# test 'command' expected_return_value 'stdin text' 'expected stdout' 'expected stder
##########################################
# EXAMPLE TEST CASES
##########################################
test() {
tc=tc+1
local COMMAND=$1
local RETURN=$2
local STDIN=$3
local STDOUT=$4
local STDERR=$5
# CHECK RETURN VALUE
$COMMAND <<< "$STDIN" >/dev/null 2>/dev/null
local A_RETURN=$?
if [[ "$A_RETURN" != "$RETURN" ]]; then
echo "Test $tc Failed"
echo " $COMMAND"
echo " Expected Return: $RETURN"
echo " Actual Return: $A_RETURN"
fails=$fails+1
return 1
fi
# CHECK STDOUT
local A_STDOUT=$($COMMAND <<< "$STDIN" 2>/dev/null)
if [[ "$STDOUT" != "$A_STDOUT" ]]; then
echo "Test $tc Failed"
echo " $COMMAND"
echo " Expected STDOUT: $STDOUT"
echo " Actual STDOUT: $A_STDOUT"
fails=$fails+1
return 2
fi
# CHECK STDERR
local A_STDERR=$($COMMAND <<< "$STDIN" 2>&1 >/dev/null)
if [[ "$STDERR" != "$A_STDERR" ]]; then
echo "Test $tc Failed"
echo " $COMMAND"
echo " Expected STDERR: $STDERR"
echo " Actual STDERR: $A_STDERR"
fails=$fails+1
return 3
fi
# SUCCESS
echo "Test $tc Passed"
return 0
}
test './bn 2022 m' 0 'Sam' '2022: Sam ranked 658 out of 14255 male names.' ''