File: is-1.7_test.go

package info (click to toggle)
golang-github-matryer-is 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 204 kB
  • sloc: makefile: 2
file content (53 lines) | stat: -rw-r--r-- 999 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// +build go1.7

package is

import (
	"bytes"
	"strings"
	"testing"
)

// TestSubtests ensures subtests work as expected.
// https://github.com/matryer/is/issues/1
func TestSubtests(t *testing.T) {
	t.Run("sub1", func(t *testing.T) {
		is := New(t)
		is.Equal(1+1, 2)
	})
}

func TestHelper(t *testing.T) {
	tests := []struct {
		name             string
		helper           bool
		expectedFilename string
	}{
		{
			name:             "without helper",
			helper:           false,
			expectedFilename: "is_helper_test.go",
		},
		{
			name:             "with helper",
			helper:           true,
			expectedFilename: "is-1.7_test.go",
		},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			tt := &mockT{}
			is := NewRelaxed(tt)

			var buf bytes.Buffer
			is.out = &buf
			helper(is, tc.helper)
			actual := buf.String()
			t.Log(actual)
			if !strings.Contains(actual, tc.expectedFilename) {
				t.Errorf("string does not contain correct filename: %s", actual)
			}
		})
	}
}