-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
100 lines (86 loc) · 2.19 KB
/
test
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
#!/bin/bash
#==================================================================================
# Unit tests for bash_spec
#
# Author: Dave Nicolette
# Date: 29 Jul 2014
#==================================================================================
. bash_spec
function equality_of_scalar_value {
it "reports two scalar values are equal"
one="1"
expect $one to_be 1
}
function nonequality_of_scalar_value {
it "reports two scalar values are unequal"
one="1"
expect $one not to_be 2
}
function string_matches_regex_pattern {
it "reports regex match"
str="one fine day"
expect "$str" to_match day$
}
function string_does_not_match_regex_pattern {
it "reports regex mismatch"
str="one fine night"
expect "$str" not to_match day$
}
function array_contains_value {
it "reports an array contains a given value"
declare -a arr=(1 2 3 4)
expect "${arr[@]}" to_contain 3
}
function array_does_not_contain_value {
it "reports an array does not contain a given value"
declare -a arr=(1 2 3 4)
expect "${arr[@]}" not to_contain 5
}
function file_exists {
it "reports a file exists"
echo 'test' > tempfile
expect tempfile to_exist
rm -f tempfile
}
function file_does_not_exist {
it "reports a file does not exist"
rm -f tempfile
expect tempfile not to_exist
}
function file_has_given_mode {
it "reports a file has the given mode"
touch tempfile
chmod u=rw,g=r,o=x tempfile
expect tempfile to_have_mode -rw-r----x
rm -f tempfile
}
function file_does_not_have_given_mode {
it "reports a file does not have the given mode"
touch tempfile
chmod u=rw,g=r,o=x tempfile
expect tempfile not to_have_mode -rw-rw-rwx
rm -f tempfile
}
function package_is_installed {
it "reports a given package is installed"
expect bash to_be_installed
}
function package_is_not_installed {
it "reports a given package is not installed"
expect bashx not to_be_installed
}
print_header bash_spec
equality_of_scalar_value
nonequality_of_scalar_value
string_matches_regex_pattern
string_does_not_match_regex_pattern
array_contains_value
array_does_not_contain_value
file_exists
file_does_not_exist
file_has_given_mode
file_does_not_have_given_mode
package_is_installed
package_is_not_installed
print_trailer
exit 0