@@ -99,11 +99,12 @@ func TestHelperProcess(t *testing.T) {
99
99
for _ , v := range os .Environ () {
100
100
fmt .Println (v )
101
101
}
102
+ os .Exit (0 )
102
103
case "exit-code" :
103
104
code , _ := strconv .Atoi (os .Args [4 ])
104
105
os .Exit (code )
105
106
}
106
- os .Exit (0 )
107
+ os .Exit (1 )
107
108
}
108
109
109
110
func (s * ExecutorSuite ) TestNotEnoughArgs (c * C ) {
@@ -139,6 +140,63 @@ func (s *ExecutorSuite) TestForwardExitCode(c *C) {
139
140
c .Assert ((& Executor {BinName : "php" , Args : []string {"php" }}).Execute (true ), Equals , 5 )
140
141
}
141
142
143
+ func (s * ExecutorSuite ) TestExecutorRunsPHP (c * C ) {
144
+ defer restoreExecCommand ()
145
+ execCommand = func (name string , arg ... string ) * exec.Cmd {
146
+ c .Assert (name , Equals , "../bin/php" )
147
+
148
+ cmd := exec .Command (os .Args [0 ], "-test.run=TestHelperProcess" , "--" , "exit-code" , "0" )
149
+ cmd .Env = []string {"GO_WANT_HELPER_PROCESS=1" }
150
+ // Set the working directory right now so that it can be changed by
151
+ // calling test case
152
+ cmd .Dir , _ = os .Getwd ()
153
+ return cmd
154
+ }
155
+
156
+ home , err := filepath .Abs ("testdata/executor" )
157
+ c .Assert (err , IsNil )
158
+
159
+ homedir .Reset ()
160
+ os .Setenv ("HOME" , home )
161
+ defer homedir .Reset ()
162
+
163
+ oldwd , _ := os .Getwd ()
164
+ defer os .Chdir (oldwd )
165
+ os .Chdir (filepath .Join (home , "project" ))
166
+ defer cleanupExecutorTempFiles ()
167
+
168
+ c .Assert ((& Executor {BinName : "php" , Args : []string {"php" }}).Execute (true ), Equals , 0 )
169
+
170
+ }
171
+
172
+ func (s * ExecutorSuite ) TestBinaryOtherThanPhp (c * C ) {
173
+ defer restoreExecCommand ()
174
+ execCommand = func (name string , arg ... string ) * exec.Cmd {
175
+ c .Assert (name , Equals , "not-php" )
176
+
177
+ cmd := exec .Command (os .Args [0 ], "-test.run=TestHelperProcess" , "--" , "exit-code" , "0" )
178
+ cmd .Env = []string {"GO_WANT_HELPER_PROCESS=1" }
179
+ // Set the working directory right now so that it can be changed by
180
+ // calling test case
181
+ cmd .Dir , _ = os .Getwd ()
182
+ return cmd
183
+ }
184
+
185
+ home , err := filepath .Abs ("testdata/executor" )
186
+ c .Assert (err , IsNil )
187
+
188
+ homedir .Reset ()
189
+ os .Setenv ("HOME" , home )
190
+ defer homedir .Reset ()
191
+
192
+ oldwd , _ := os .Getwd ()
193
+ defer os .Chdir (oldwd )
194
+ os .Chdir (filepath .Join (home , "project" ))
195
+ defer cleanupExecutorTempFiles ()
196
+
197
+ c .Assert ((& Executor {BinName : "php" , Args : []string {"not-php" }}).Execute (true ), Equals , 0 )
198
+ }
199
+
142
200
func (s * ExecutorSuite ) TestEnvInjection (c * C ) {
143
201
defer restoreExecCommand ()
144
202
fakeExecCommand ("dump-env" )
0 commit comments