MCPcopy Create free account
hub / github.com/github/gh-aw / TestMainFunctionExecutionPath

Function TestMainFunctionExecutionPath

cmd/gh-aw/main_entry_test.go:231–316  ·  view source on GitHub ↗

TestMainFunctionExecutionPath tests the main function execution path This covers the main() function at line 360

(t *testing.T)

Source from the content-addressed store, hash-verified

229// TestMainFunctionExecutionPath tests the main function execution path
230// This covers the main() function at line 360
231func TestMainFunctionExecutionPath(t *testing.T) {
232 // Test that we can build and run the main function successfully
233 t.Run("main function integration test", func(t *testing.T) {
234 // Only run this test if we're in development (has go)
235 if _, err := exec.LookPath("go"); err != nil {
236 t.Skip("go binary not available - skipping main function integration test")
237 }
238
239 // Test help command execution through main function
240 cmd := exec.Command("go", "run", ".", "--help")
241 cmd.Dir = "."
242
243 output, err := cmd.CombinedOutput() // Use CombinedOutput to capture stderr
244 require.NoError(t, err, "running main with --help should succeed")
245
246 outputStr := string(output)
247 assert.Contains(t, outputStr, "GitHub Agentic Workflows", "main help output should contain the product name")
248 assert.Contains(t, outputStr, "Usage:", "main help output should contain usage information")
249 })
250
251 t.Run("main function version command", func(t *testing.T) {
252 // Test version command execution through main function
253 cmd := exec.Command("go", "run", ".", "version")
254 cmd.Dir = "."
255
256 output, err := cmd.CombinedOutput() // Use CombinedOutput to capture both stdout and stderr
257 require.NoError(t, err, "running main with version command should succeed")
258
259 outputStr := string(output)
260 // Should produce some version output (even if it's "unknown")
261 assert.NotEmpty(t, strings.TrimSpace(outputStr), "main version command should produce output")
262 })
263
264 t.Run("main function error handling", func(t *testing.T) {
265 // Test error handling in main function
266 cmd := exec.Command("go", "run", ".", "invalid-command")
267 cmd.Dir = "."
268
269 _, err := cmd.Output()
270 require.Error(t, err, "main function should return a non-zero exit code for invalid command")
271
272 // Check that it's an ExitError (non-zero exit code)
273 exitError, ok := err.(*exec.ExitError)
274 require.True(t, ok, "invalid command should return an *exec.ExitError, got %T", err)
275 assert.NotZero(t, exitError.ExitCode(), "invalid command should return a non-zero exit code")
276 })
277
278 t.Run("main function version info setup", func(t *testing.T) {
279 // Test that SetVersionInfo is called in main()
280 // We can verify this by checking that the CLI package has version info
281
282 // Reset version info to simulate fresh start
283 originalVersion := cli.GetVersion()
284
285 // Set a test version
286 cli.SetVersionInfo("test-version")
287
288 // Verify it was set

Callers

nothing calls this directly

Calls 4

GetVersionFunction · 0.92
SetVersionInfoFunction · 0.92
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected