-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbash_snippets.go
44 lines (42 loc) · 950 Bytes
/
bash_snippets.go
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
package gobmock
const (
scriptStart = "\n# Gob\n%[1]s() {\n"
stubDefinition = `
# Stub
while read -r -t0.1; do
:
done
`
spyDefinition = `
# Spy
local in_lines=""
while read -r -t0.1; do
in_lines="${in_lines}${REPLY}
"
done
callCounter=$((callCounter + 1))
echo "<${callCounter}> %[1]s $*" > /dev/fd/2
if [ -n "${in_lines}" ]; then
in_lines=${in_lines::-1}
echo "<${callCounter} received> input:" > /dev/fd/2
echo -n "${in_lines}" > /dev/fd/2
echo "<${callCounter} end received>" > /dev/fd/2
fi
`
spyWithoutReadingDefinition = `
# Spy
callCounter=$((callCounter + 1))
echo "<${callCounter}> %[1]s $*" > /dev/fd/2
`
mockDefinition = "\n # Mock\n %[2]s\n"
scriptEnd = "\n }\n"
exportDefinition = "export -f %s\n"
callThroughDefinition = `
# Call through
if [ -n "${in_lines}" ]; then
echo -n "${in_lines}" | $(which %[1]s) "$@"
else
$(which %[1]s) "$@"
fi
`
)