Skip to content
Myr

print line number in go test failures

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Eric Paris · committed by Eric Paris · parent f576d29 · Browse files · 1 file+15 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+15 added−3 removed

  • other:+15 added−3 removed

1 file+15 added−3 removed

modified:cobra_test.go+15 added-3 removed
2 unmodified lines
3import (4 "bytes"5 "fmt"6 "os"7 "runtime"8 "strings"9 "testing"10)11
184 unmodified lines
196197 return resulter{err, output, c}198}199200func logErr(t *testing.T, found, expected string) {201 out := new(bytes.Buffer)202203 _, _, line, ok := runtime.Caller(2)204 if ok {205 fmt.Fprintf(out, "Line: %d ", line)206 }207 fmt.Fprintf(out, "Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)208 t.Errorf(out.String())209}210211func checkResultContains(t *testing.T, x resulter, check string) {212 if !strings.Contains(x.Output, check) {201 t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", check, x.Output)213 logErr(t, x.Output, check)214 }215}216217func checkResultOmits(t *testing.T, x resulter, check string) {218 if strings.Contains(x.Output, check) {207 t.Errorf("Unexpected response.\nExpecting to omit: \n %q\nGot:\n %q\n", check, x.Output)219 logErr(t, x.Output, check)220 }221}222223func checkOutputContains(t *testing.T, c *Command, check string) {
1 unmodified line
225 c.SetOutput(buf)226 c.Execute()227228 if !strings.Contains(buf.String(), check) {217 t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", check, buf.String())229 logErr(t, buf.String(), check)230 }231}232233func TestSingleCommand(t *testing.T) {
530 unmodified lines