MCPcopy Create free account
hub / github.com/cli/cli / printDifferences

Function printDifferences

script/ghmock/report.go:292–374  ·  view source on GitHub ↗
(w io.Writer, base, other runResult, n int)

Source from the content-addressed store, hash-verified

290}
291
292func printDifferences(w io.Writer, base, other runResult, n int) {
293 fmt.Fprintf(w, "[%d] %s:\n", n, other.version)
294 same := true
295
296 if exitLabel(base) != exitLabel(other) {
297 same = false
298 fmt.Fprintf(w, " exit code: %s -> %s\n", exitLabel(base), exitLabel(other))
299 }
300 stdoutLabel := "stdout"
301 if base.terminal {
302 stdoutLabel = "final screen"
303 }
304 for _, out := range []struct{ label, a, b string }{
305 {stdoutLabel, base.stdout, other.stdout},
306 {"stderr", base.stderr, other.stderr},
307 {"terminal output", base.terminalOutput, other.terminalOutput},
308 } {
309 if out.a == out.b {
310 continue
311 }
312 same = false
313 fmt.Fprintf(w, " %s:\n", out.label)
314 for _, line := range lineDiff(showEscapes(out.a), showEscapes(out.b)) {
315 fmt.Fprintf(w, " %s\n", line)
316 }
317 }
318
319 if !slices.Equal(base.steps, other.steps) {
320 same = false
321 fmt.Fprintf(w, " prompt snapshots differ: %d in [1], %d in [%d]\n", len(base.steps), len(other.steps), n)
322 for i := 0; i < min(len(base.steps), len(other.steps)); i++ {
323 if base.steps[i] != other.steps[i] {
324 fmt.Fprintf(w, " prompt %d: %s -> %s\n", i+1, showEscapes(base.steps[i].Screen), showEscapes(other.steps[i].Screen))
325 }
326 }
327 }
328 if base.unusedKeys != other.unusedKeys {
329 same = false
330 fmt.Fprintf(w, " unused keys: %d -> %d\n", base.unusedKeys, other.unusedKeys)
331 }
332
333 baseCounts, otherCounts := countNames(base.requests), countNames(other.requests)
334 for _, name := range unionNames(base.requests, other.requests) {
335 if baseCounts[name] != otherCounts[name] {
336 same = false
337 fmt.Fprintf(w, " %s: %d in [1], %d in [%d]\n", name, baseCounts[name], otherCounts[name], n)
338 }
339 }
340
341 for _, name := range unionNames(base.requests, other.requests) {
342 a, b := askedFields(base.requests, name), askedFields(other.requests, name)
343 if a == nil || b == nil {
344 continue
345 }
346 onlyBase, onlyOther := onlyIn(a, b), onlyIn(b, a)
347 if len(onlyBase) == 0 && len(onlyOther) == 0 {
348 continue
349 }

Callers 1

printReportFunction · 0.85

Calls 12

exitLabelFunction · 0.85
lineDiffFunction · 0.85
showEscapesFunction · 0.85
countNamesFunction · 0.85
unionNamesFunction · 0.85
askedFieldsFunction · 0.85
onlyInFunction · 0.85
joinLimitedFunction · 0.85
requestPayloadsFunction · 0.85
truncateFunction · 0.85
formatPayloadsFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected