-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.sh
executable file
·60 lines (46 loc) · 1.33 KB
/
test.sh
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
#!/bin/bash
# Initialize test framework
TEST_FAILURES=0
test_pass() {
:
}
test_fail() {
TEST_FAILURES=`expr $TEST_FAILURES + 1`
}
test_str_eq() {
if [ "$1" == "$2" ]; then
test_pass
else
test_fail
echo "Test failed: '$1' == '$2'"
fi
}
test_str_neq() {
if [ "$1" != "$2" ]; then
test_pass
else
test_fail
echo "Test failed: '$1' != '$2'"
fi
}
# Import test target
. ./sshfav.sh -h &> /dev/null
# Test cases
test_str_eq "`user_from_connection_spec 'example.com'`" ""
test_str_eq "`host_from_connection_spec 'example.com'`" "example.com"
test_str_eq "`port_from_connection_spec 'example.com'`" "22"
test_str_eq "`user_from_connection_spec '[email protected]'`" "user"
test_str_eq "`host_from_connection_spec '[email protected]'`" "example.com"
test_str_eq "`port_from_connection_spec '[email protected]'`" "22"
test_str_eq "`user_from_connection_spec 'example.com:1234'`" ""
test_str_eq "`host_from_connection_spec 'example.com:1234'`" "example.com"
test_str_eq "`port_from_connection_spec 'example.com:1234'`" "1234"
test_str_eq "`user_from_connection_spec '[email protected]:1234'`" "user"
test_str_eq "`host_from_connection_spec '[email protected]:1234'`" "example.com"
test_str_eq "`port_from_connection_spec '[email protected]:1234'`" "1234"
# Test summary
if [ $TEST_FAILURES -eq 0 ]; then
echo "All tests passed."
else
exit 1
fi