MCPcopy Create free account
hub / github.com/checkmake/checkmake / TestCheckmake_WithJSONOutput

Function TestCheckmake_WithJSONOutput

cmd/checkmake/main_test.go:213–256  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

211}
212
213func TestCheckmake_WithJSONOutput(t *testing.T) {
214 out := captureOutput(func() {
215 cmd := newRootCmd()
216 cmd.SilenceErrors = true
217 cmd.SetArgs([]string{
218 "-o", "json",
219 "../../fixtures/missing_phony.make",
220 })
221 _ = cmd.Execute()
222 })
223
224 t.Logf("JSON output:\n%s", out)
225
226 require.NotEmpty(t, out, "output should not be empty for JSON format")
227
228 // Verify it's valid JSON
229 var violations []struct {
230 Rule string `json:"rule"`
231 Violation string `json:"violation"`
232 FileName string `json:"file_name"`
233 LineNumber int `json:"line_number"`
234 }
235
236 err := json.Unmarshal([]byte(out), &violations)
237 require.NoError(t, err, "output should be valid JSON")
238
239 // Verify we have violations
240 assert.Greater(t, len(violations), 0, "should have at least one violation")
241
242 // Verify structure
243 for _, v := range violations {
244 assert.NotEmpty(t, v.Rule, "rule should not be empty")
245 assert.NotEmpty(t, v.Violation, "violation should not be empty")
246 assert.NotEmpty(t, v.FileName, "file_name should not be empty")
247 assert.Greater(t, v.LineNumber, 0, "line_number should be greater than 0")
248 }
249
250 // Verify specific violations are present
251 ruleNames := make(map[string]bool)
252 for _, v := range violations {
253 ruleNames[v.Rule] = true
254 }
255 assert.Contains(t, ruleNames, "phonydeclared", "should contain phonydeclared violation")
256}
257
258func TestCheckmake_WithJSONOutputFlag(t *testing.T) {
259 out := captureOutput(func() {

Callers

nothing calls this directly

Calls 2

captureOutputFunction · 0.85
newRootCmdFunction · 0.85

Tested by

no test coverage detected