forked from shellspec/shellspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21.intercept_spec.sh
36 lines (35 loc) · 1011 Bytes
/
21.intercept_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
#shellcheck shell=sh
Describe 'intercept example'
Intercept begin
__begin__() {
# Define stubs for cat
cat() {
if [ "${1:-}" = "/proc/cpuinfo" ];then
%text
#|processor : 0
#|vendor_id : GenuineIntel
#|cpu family : 6
#|model : 58
#|model name : Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
#|
#|processor : 1
#|vendor_id : GenuineIntel
#|cpu family : 6
#|model : 58
#|model name : Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
#|
#|processor : 2
#|vendor_id : GenuineIntel
#|cpu family : 6
#|model : 58
#|model name : Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
else
command cat "$@"
fi
}
}
Example 'test cpunum.sh with stubbed cat /cpu/info'
When run source ./count_cpus.sh
The stdout should eq 3
End
End