-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.bats
More file actions
executable file
·50 lines (43 loc) · 906 Bytes
/
add.bats
File metadata and controls
executable file
·50 lines (43 loc) · 906 Bytes
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
#!/usr/bin/env bats
#This function returns the sum of its command line
#arguments
add()
{
result=0
#go through the function arguments
for arg
do
#if the argument is a number then
#add it to the total
if [[ $arg =~ ^[[:digit:]+]$ ]]
then
let result=$result+$arg
fi
done
echo $result
return 0
}
#each of these are tests of the function
@test "add 1 2 3" {
#call the add function
#1 2 3 are the command line arguments
run add 1 2 3
#whatever output is produced by the function is
#in the variable $output
echo "output: $output"
[ "$output" = "6" ]
#whatever is returned by the function is
#in the variable $status
[ "$status" = "0" ]
}
@test "add 1 2 ab 3" {
run add 1 2 ab 3
[ "$output" = "6" ]
[ "$status" = "0" ]
}
@test "add a1 2 ab 3" {
run add a1 2 ab 3
echo $output
[ "$output" = "5" ]
[ "$status" = "0" ]
}