-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtests.bats
More file actions
121 lines (97 loc) · 2.71 KB
/
tests.bats
File metadata and controls
121 lines (97 loc) · 2.71 KB
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
#!/usr/bin/env bats
# Run tests by using bats
# https://github.com/sstephenson/bats
ERR_FATAL=1
ERR_LOGIC=2
ERR_PARAMS=3
ERR_FILE_SYSTEM=4
ERR_CONNECTION=6 # failed test for connection
status=0
output=''
xdebug_ini_file=${XDEBUG_INI}
# reset status to "OFF"
echo ';zend_extension = '${XDEBUG_EXT} \
> ${xdebug_ini_file}
@test "Check short status." {
export BASH_NO_COLOR=1
run xd_swi stat
[ "${status}" -eq 0 ]
[ "${output}" -eq 0 ]
}
@test "Check long status." {
export BASH_NO_COLOR=1
run xd_swi status
[ "${status}" -eq 0 ]
[ "${output}" == 'XDebug is disabled' ]
}
@test "Enable with '1'." {
export BASH_NO_COLOR=1
run xd_swi 1
[ "${status}" -eq 0 ]
[ "${output}" == 'XDebug is enabled' ]
}
@test "Disable with '0'." {
export BASH_NO_COLOR=1
run xd_swi 0
[ "${status}" -eq 0 ]
[ "${output}" == 'XDebug is disabled' ]
}
@test "Enable with 'on'." {
export BASH_NO_COLOR=1
run xd_swi on
[ "${status}" -eq 0 ]
[ "${output}" == 'XDebug is enabled' ]
}
@test "Disable with 'off'." {
export BASH_NO_COLOR=1
run xd_swi off
[ "${status}" -eq 0 ]
[ "${output}" == 'XDebug is disabled' ]
}
@test "Read path to Xdebug INI file." {
export BASH_NO_COLOR=1
run xd_swi file
[ "${status}" -eq 0 ]
[ "${output}" == ${xdebug_ini_file} ]
}
@test "Trigger restart command." {
export BASH_NO_COLOR=1
rm -f /tmp/test-command.txt \
/usr/local/lib/xd_swi-restart-command
run xd_swi 0
echo 'echo 1 > /tmp/test-command.txt' > /tmp/test-run.sh
run xd_swi restart-command -- bash /tmp/test-run.sh /tmp/test-command.txt
run xd_swi
[ "${status}" -eq 0 ]
[ 'XDebug is enabled' == "${output:-}" ]
[ -f /usr/local/lib/xd_swi-restart-command ]
[ "$(cat /tmp/test-command.txt)" == '1' ]
}
@test "Omitting restart command." {
export BASH_NO_COLOR=1
rm -f /tmp/test-command.txt \
/usr/local/lib/xd_swi-restart-command
run xd_swi 0
echo 'echo 1 > /tmp/test-command.txt' > /tmp/test-run.sh
run xd_swi restart-command -- bash /tmp/test-run.sh /tmp/test-command.txt
# it must not trigger "restart-command"
run xd_swi --no-restart
[ "${status}" -eq 0 ]
[ 'XDebug is enabled' == "${output:-}" ]
[ ! -f /tmp/test-command.txt ]
}
@test "Set Xdebug for the service only." {
export BASH_NO_COLOR=1
rm -f /tmp/test-command.txt \
/usr/local/lib/xd_swi-restart-command
run xd_swi 0
echo 'echo 1 > /tmp/test-command.txt' > /tmp/test-run.sh
run xd_swi restart-command -- bash /tmp/test-run.sh
# it must trigger "restart-command" and enable Xdebug for the service
# and return it back to OFF for CLI
run xd_swi web
[ "${status}" -eq 0 ]
[[ "${output:-}" =~ 'XDebug is enabled' ]]
[[ "${output:-}" =~ 'XDebug is disabled' ]]
[ -f /tmp/test-command.txt ]
}