forked from adoyle-h/lobash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhas.s.bats
141 lines (119 loc) · 2.4 KB
/
has.s.bats
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bats
setup_fixture
test_prepare has.s
load_module has.s
@test 'if [[ l.has.s == true ]]' {
test() {
if [[ $(l.has.s command cat) == true ]]; then
echo 1
else
echo 2
fi
}
run test
assert_success
assert_output 1
test() {
if [[ $(l.has.s command xxcat) == true ]]; then
echo 1
else
echo 2
fi
}
run test
assert_success
assert_output 2
}
@test "l.has.s the agti, which is an alias" {
shopt -s expand_aliases
alias gti='git'
result=$(l.has.s the gti)
assert_equal "$result" true
shopt -u expand_aliases
}
@test "l.has.s command cat, while cat is existed" {
run l.has.s command cat
assert_success
assert_output true
}
@test "l.has.s command xxx, which not defined" {
run l.has.s command xxx
assert_success
assert_output false
}
@test "l.has.s function bbb, which not defined" {
run l.has.s function bbb
assert_success
assert_output false
}
@test "l.has.s function bbb, which has been defined" {
bbb() { echo 1; }
run l.has.s function bbb
assert_success
assert_output true
}
@test "l.has.s builtin true" {
run l.has.s builtin true
assert_success
assert_output true
}
@test "l.has.s builtin xxx, which not defined" {
run l.has.s builtin xxx
assert_success
assert_output false
}
@test "l.has.s keyword function" {
run l.has.s keyword function
assert_success
assert_output true
}
@test "l.has.s keyword xxx, which not defined" {
run l.has.s keyword xxx
assert_success
assert_output false
}
@test "l.has.s alias xxx, which not defined" {
run l.has.s alias xxx
assert_success
assert_output false
}
@test "l.has.s the xxx, which not defined" {
run l.has.s the xxx
assert_success
assert_output false
}
@test "l.has.s the ls, which is command" {
run l.has.s the ls
assert_success
assert_output true
}
@test "l.has.s the function, which is keyword" {
run l.has.s the function
assert_success
assert_output true
}
@test "l.has.s the type, which is builtin" {
run l.has.s the type
assert_success
assert_output true
}
@test "l.has.s what type" {
run l.has.s what type
assert_failure 3
assert_output 'Invalid Condition: what'
}
@test "result=\$(l.has.s what type)" {
foo() {
set -e;
local r
r=$(l.has.s what type)
if [[ $r == true ]]; then
echo 4
else
echo 5
fi
}
run foo
assert_failure 3
assert_line -n 0 'Invalid Condition: what'
}