forked from shellspec/shellspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.matcher_spec.sh
118 lines (99 loc) · 2.77 KB
/
11.matcher_spec.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#shellcheck shell=sh
Describe 'matcher example'
Describe 'status matchers'
Describe 'be success matcher'
It 'checks if status is successful'
When call true
The status should be success # status is 0
End
End
Describe 'be failure matcher'
It 'checks if status is failed'
When call false
The status should be failure # status is 1-255
End
End
# If you want to check status number, use equal matcher.
End
Describe 'stat matchers'
Describe 'exists'
It 'checks if path exists'
The path 'data.txt' should exist
End
It 'checks if path is file'
The path 'data.txt' should be file
End
It 'checks if path is directory'
The path 'data.txt' should be directory
End
End
# There are many other stat matchers.
# be empty, be symlink, be pipe, be socket, be readable, be writable,
# be executable, be block_device, be character_device,
# has setgid, has setuid
End
Describe 'variable matchers'
Before 'prepare'
Describe 'be defined'
prepare() { var=''; }
It 'checks if variable is defined'
The value "$var" should be defined
End
End
Describe 'be undefined'
prepare() { unset var; }
It 'checks if variable is undefined'
The variable var should be undefined
End
End
Describe 'be present'
prepare() { var=123; }
It 'checks if variable is present'
The value "$var" should be present # non-zero length string
End
End
Describe 'be blank'
prepare() { var=""; }
It 'checks if variable is blank'
The value "$var" should be blank # unset or zero length string
End
End
End
Describe 'string matchers'
Describe 'equal'
It 'checks if subject equals specified string'
The value "foobarbaz" should equal "foobarbaz"
End
End
Describe 'start with'
It 'checks if subject start with specified string'
The value "foobarbaz" should start with "foo"
End
End
Describe 'end with'
It 'checks if subject end with specified string'
The value "foobarbaz" should end with "baz"
End
End
Describe 'include'
It 'checks if subject include specified string'
The value "foobarbaz" should include "bar"
End
End
Describe 'match'
It 'checks if subject match specified pattern'
# Using shell script's pattern matching
The value "foobarbaz" should match pattern "f??bar*"
End
End
End
Describe 'satisfy matcher'
formula() {
eval "value=${formula:?}"
[ $(($1)) -eq 1 ]
}
It 'checks if satisfy condition'
The value 10 should satisfy formula "value >= 5"
End
End
End