Skip to content

Commit ef61f1f

Browse files
committed
chore: add test of spies failing to fix on main
1 parent 1a6d915 commit ef61f1f

6 files changed

Lines changed: 71 additions & 0 deletions

tests/functional/doubles_test.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
function test_mock_ps_when_executing_a_script() {
4+
skip "The mock is not been able to cat the output of the cat"
5+
return
6+
mock ps cat ./tests/functional/fixtures/doubles_ps_output
7+
8+
assert_match_snapshot "$(./tests/functional/fixtures/doubles_script.sh)"
9+
}
10+
11+
function test_mock_ps_when_executing_a_sourced_function() {
12+
skip "The mock is not been able to cat the output of the cat"
13+
return
14+
source ./tests/functional/fixtures/doubles_function.sh
15+
mock ps cat ./tests/functional/fixtures/doubles_ps_output
16+
17+
assert_match_snapshot "$(top_mem)"
18+
}
19+
20+
function test_spy_commands_called_once_when_executing_a_script() {
21+
skip "not working while executing commands outside a function"
22+
return
23+
24+
spy ps
25+
spy awk
26+
spy head
27+
28+
./tests/functional/fixtures/doubles_script.sh
29+
30+
assert_have_been_called_times 1 ps
31+
assert_have_been_called_times 1 awk
32+
assert_have_been_called_times 1 head
33+
}
34+
35+
function test_spy_commands_called_once_when_executing_a_sourced_function() {
36+
skip "The spies can not spy inside the scope of the function"
37+
return
38+
39+
source ./tests/functional/fixtures/doubles_function.sh
40+
spy ps
41+
spy awk
42+
spy head
43+
44+
top_mem
45+
46+
assert_have_been_called_times 1 ps
47+
assert_have_been_called_times 1 awk
48+
assert_have_been_called_times 1 head
49+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
function top_mem() {
4+
ps -eo cmd,%mem --sort=-%mem | awk '$2 >= 1.0 {print $0}' | head -n 3
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CMD %MEM
2+
firefox 2.0
3+
Xorg 1.6
4+
jetbrains-toolbox 1.3
5+
vitepress 1.0
6+
bashunit 0.1
7+
bash 0.0
8+
ps 0.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
ps -eo cmd,%mem --sort=-%mem | awk '$2 >= 1.0 {print $0}' | head -n 3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
firefox 2.0
2+
Xorg 1.6
3+
jetbrains-toolbox 1.3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
firefox 2.0
2+
Xorg 1.6
3+
jetbrains-toolbox 1.3

0 commit comments

Comments
 (0)