-
Notifications
You must be signed in to change notification settings - Fork 758
/
helpers.bash.t
executable file
·87 lines (65 loc) · 1.26 KB
/
helpers.bash.t
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
#
# tests for helpers.bash
#
. $(dirname ${BASH_SOURCE})/helpers.bash
INDEX=1
RC=0
# t (true) : tests that should pass
function t() {
result=$(assert "$@" 2>&1)
status=$?
if [[ $status -eq 0 ]]; then
echo "ok $INDEX $*"
else
echo "not ok $INDEX $*"
echo "$result"
RC=1
fi
INDEX=$((INDEX + 1))
}
# f (false) : tests that should fail
function f() {
result=$(assert "$@" 2>&1)
status=$?
if [[ $status -ne 0 ]]; then
echo "ok $INDEX ! $*"
else
echo "not ok $INDEX ! $* [passed, should have failed]"
RC=1
fi
INDEX=$((INDEX + 1))
}
t "" = ""
t "a" != ""
t "" != "a"
t "a" = "a"
t "aa" == "aa"
t "a[b]{c}" = "a[b]{c}"
t "abcde" =~ "a"
t "abcde" =~ "b"
t "abcde" =~ "c"
t "abcde" =~ "d"
t "abcde" =~ "e"
t "abcde" =~ "ab"
t "abcde" =~ "abc"
t "abcde" =~ "abcd"
t "abcde" =~ "bcde"
t "abcde" =~ "cde"
t "abcde" =~ "de"
t "foo" =~ "foo"
t "foobar" =~ "foo"
t "barfoo" =~ "foo"
t 'a "AB \"CD": ef' = 'a "AB \"CD": ef'
t 'a "AB \"CD": ef' =~ 'a "AB \\"CD": ef'
t 'abcdef' !~ 'efg'
t 'abcdef' !~ 'x'
###########
f "a" = "b"
f "a" == "b"
f "abcde" =~ "x"
f "abcde" !~ "a"
f "abcde" !~ "ab"
f "abcde" !~ "abc"
f "" != ""
exit $RC