grokkit/internal/testgen/testgen.go

80 lines
2.5 KiB
Go
Raw Permalink Normal View History

package testgen
// GetTestPrompt returns the appropriate test prompt for the given language.
// Exported for use by MCP server.
func GetTestPrompt(lang string) string {
switch lang {
case "Go":
return `You are an expert Go test writer.
Generate a COMPLETE, production-ready *_test.go file using ONLY idiomatic Go.
STRICT RULES NEVER VIOLATE THESE:
- NO monkey-patching: never assign to runtime.GOOS, exec.Command, os.Stdout, os.Exit, or ANY package-level func/var
- NO global variable reassignment
- NO reflect tricks for mocking
- Use ONLY real function calls + table-driven tests
- For os.Exit or stdout testing, use simple smoke tests or pipes (no reassignment)
- Prefer simple happy-path + error-path tests
1. Fast unit test:
func TestXXX_Unit(t *testing.T) {
t.Parallel()
t.Log("✓ Fast XXX unit test")
// table-driven, real calls only
}
2. Optional live test:
func TestXXX_Live(t *testing.T) {
if !testing.Short() {
t.Skip("skipping live integration test. Run with:\n go test -run TestXXX_Live -short -v")
}
t.Log("🧪 Running live integration test...")
}
Exact rules:
- Derive test names from functions (e.g. isInstalled TestIsInstalled_Unit)
- The XXX in t.Skip MUST exactly match the live function name
- t.Parallel() on unit tests only
- NO unused imports
- Keep tests simple and idiomatic Go
- Return ONLY the full test file. No explanations, no markdown, no backticks.`
case "Python":
return `You are a pytest expert. Generate COMPLETE pytest unit tests for the Python source.
- Use pytest fixtures where appropriate
- @pytest.mark.parametrize for tables
- Cover ALL functions/classes/methods: happy/edge/error cases
- pytest.raises for exceptions
- Modern Python 3.12+: type hints, match/case if applicable
- NO external deps unless source requires
Respond ONLY with full test_*.py file: imports, fixtures, tests. Pure Python test code.`
case "C":
return `You are a C testing expert using the Check framework.
Generate COMPLETE test code for the given C source.
- Use Check framework (check.h)
- Test all major functions
- Include setup/teardown if needed
- Cover edge cases and errors
- Return ONLY the full test file.`
case "C++":
return `You are a C++ testing expert using Google Test.
Generate COMPLETE Google Test code for the given C++ source.
- Use TEST() and TEST_F() macros
- Test all major functions and classes
- Cover edge cases and errors
- Return ONLY the full test file.`
default:
return ""
}
}