File: show_error_test.go

package info (click to toggle)
elvish 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,372 kB
  • sloc: javascript: 236; sh: 130; python: 104; makefile: 88; xml: 9
file content (34 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package diag

import (
	"errors"
	"strings"
	"testing"
)

type showerError struct{}

func (showerError) Error() string { return "error" }

func (showerError) Show(_ string) string { return "show" }

var showErrorTests = []struct {
	name    string
	err     error
	wantBuf string
}{
	{"A Shower error", showerError{}, "show\n"},
	{"A errors.New error", errors.New("ERROR"), "\033[31;1mERROR\033[m\n"},
}

func TestShowError(t *testing.T) {
	for _, test := range showErrorTests {
		t.Run(test.name, func(t *testing.T) {
			sb := &strings.Builder{}
			ShowError(sb, test.err)
			if sb.String() != test.wantBuf {
				t.Errorf("Wrote %q, want %q", sb.String(), test.wantBuf)
			}
		})
	}
}