MCPcopy
hub / github.com/mikefarah/yq / TestMainFunctionIntegration

Function TestMainFunctionIntegration

yq_test.go:190–223  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

188}
189
190func TestMainFunctionIntegration(t *testing.T) {
191 // Integration test to verify the main function logic works end-to-end
192
193 cmd := command.New()
194 cmd.SetArgs([]string{"eval", "--help"})
195
196 // This should not crash (we can't test the actual execution due to os.Exit)
197 if cmd == nil {
198 t.Fatal("Command should not be nil")
199 }
200
201 cmd2 := command.New()
202 cmd2.SetArgs([]string{"invalid-command"})
203
204 // Simulate the main function logic
205 args := []string{"invalid-command"}
206 _, _, err := cmd2.Find(args)
207 if err != nil {
208 // This is what main() would do
209 newArgs := []string{"eval"}
210 cmd2.SetArgs(append(newArgs, args...))
211 }
212
213 // We can't directly access cmd.Args since it's a function, but we can test
214 // that SetArgs worked by ensuring the command is still functional
215 if cmd2 == nil {
216 t.Error("Command should not be nil after SetArgs")
217 }
218
219 _, _, err = cmd2.Find([]string{"eval"})
220 if err != nil {
221 t.Errorf("Should be able to find eval command after SetArgs: %v", err)
222 }
223}

Callers

nothing calls this directly

Calls 2

ErrorMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…