forked from kalbhor/thirsty
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththirsty_test.sh
More file actions
executable file
·52 lines (42 loc) · 1.2 KB
/
thirsty_test.sh
File metadata and controls
executable file
·52 lines (42 loc) · 1.2 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
#!/bin/sh
# Override default water time
WATER_TIME=5
DRINK_WATER_CONF=$PWD/test.water
rm -f $DRINK_WATER_CONF
. ./thirsty.sh
echo "Running tests..."
# Test that drink_water returns nothing
out="$(drink_water)"
if [ -n "$out" ]; then
echo "drink_water error. Expected '', got '$out'"
exit 1
fi
sleep $(($WATER_TIME + 1))
# Test that drink_water tells us it's time for a drink
out="$(drink_water)"
expected="💧 You're thirsty"
if [ "$out" != "$expected" ]; then
echo "drink_water error. Expected '$expected', got '$out'"
exit 1
fi
# Test that not_thirsty sets a new time
before="$(cat $DRINK_WATER_CONF)"
out="$(not_thirsty)"
expected="Water is essential"
if [ "$out" != "$expected" ]; then
echo "not_thirsty error. Expected '$expected', got '$out'"
exit 1
fi
if [ "$before" = "$(cat $DRINK_WATER_CONF)" ]; then
echo "not_thirsty error. Last drink time was not updated"
exit 1
fi
# Test that next_drink outputs correctly
out="$(next_drink)"
expected="Next drink at $(date --date="@$(($(cat $DRINK_WATER_CONF) + $WATER_TIME))")"
if [ "$out" != "$expected" ]; then
echo "next_drink error. Expected '$expected', got '$out'"
exit 1
fi
rm -f $DRINK_WATER_CONF
echo "All tests passed"