github.com/julianthome/gore@v0.0.0-20231109011145-b3a6bbe6fe55/errfilter_test.go (about) 1 package gore 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestErrFilter(t *testing.T) { 11 testCases := []struct { 12 id, src, expected string 13 }{ 14 { 15 "simple", 16 "foobar", 17 "foobar", 18 }, 19 { 20 "new line", 21 "foobar\nbaz\nqux\n", 22 "foobar\nbaz\nqux\n", 23 }, 24 { 25 "command-line-arguments", 26 "# command-line-arguments foo\nbar\nbuild command-line-arguments: baz\nqux", 27 "bar\nbaz\nqux", 28 }, 29 { 30 "gore_session.go", 31 "/tmp/gore_session.go:10:24: undefined: foo", 32 "undefined: foo", 33 }, 34 { 35 "command-line-arguments and gore_session.go", 36 "# command-line-arguments foo\n/tmp/gore_session.go:10:24: undefined: foo", 37 "undefined: foo", 38 }, 39 { 40 "no module dependencies warning", 41 "warning: pattern \"all\" matched no module dependencies\nwarning: pattern \"all\" matched no module depend", 42 "warning: pattern \"all\" matched no module depend", 43 }, 44 } 45 for _, tc := range testCases { 46 t.Run(tc.id, func(t *testing.T) { 47 var out strings.Builder 48 w := newErrFilter(&out) 49 _, err := w.Write([]byte(tc.src)) 50 require.NoError(t, err) 51 err = w.Close() 52 require.NoError(t, err) 53 require.Equal(t, tc.expected, out.String()) 54 }) 55 } 56 }