github.com/inturn/pre-commit-gobuild@v1.0.12/internal/errchecker/testdata/main_test.go (about)

     1  package main
     2  
     3  import (
     4  	"bytes"
     5  	"crypto/sha256"
     6  	"io/ioutil"
     7  	"math/rand"
     8  	mrand "math/rand"
     9  	"testing"
    10  )
    11  
    12  func TestFunc(tt *testing.T) {
    13  	// Single error return
    14  	_ = a() // BLANK
    15  	a()     // UNCHECKED
    16  
    17  	// Return another value and an error
    18  	_, _ = b() // BLANK
    19  	b()        // UNCHECKED
    20  
    21  	// Return a custom error type
    22  	_ = customError() // BLANK
    23  	customError()     // UNCHECKED
    24  
    25  	// Return a custom concrete error type
    26  	_ = customConcreteError()         // BLANK
    27  	customConcreteError()             // UNCHECKED
    28  	_, _ = customConcreteErrorTuple() // BLANK
    29  	customConcreteErrorTuple()        // UNCHECKED
    30  
    31  	// Return a custom pointer error type
    32  	_ = customPointerError()         // BLANK
    33  	customPointerError()             // UNCHECKED
    34  	_, _ = customPointerErrorTuple() // BLANK
    35  	customPointerErrorTuple()        // UNCHECKED
    36  
    37  	// Method with a single error return
    38  	x := t{}
    39  	_ = x.a() // BLANK
    40  	x.a()     // UNCHECKED
    41  
    42  	// Method call on a struct member
    43  	y := u{x}
    44  	_ = y.t.a() // BLANK
    45  	y.t.a()     // UNCHECKED
    46  
    47  	m1 := map[string]func() error{"a": a}
    48  	_ = m1["a"]() // BLANK
    49  	m1["a"]()     // UNCHECKED
    50  
    51  	// Additional cases for assigning errors to blank identifier
    52  	z, _ := b()    // BLANK
    53  	_, w := a(), 5 // BLANK
    54  
    55  	// Assign non error to blank identifier
    56  	_ = c()
    57  
    58  	_ = z + w // Avoid complaints about unused variables
    59  
    60  	// Type assertions
    61  	var i interface{}
    62  	s1 := i.(string)    // ASSERT
    63  	s1 = i.(string)     // ASSERT
    64  	s2, _ := i.(string) // ASSERT
    65  	s2, _ = i.(string)  // ASSERT
    66  	s3, ok := i.(string)
    67  	s3, ok = i.(string)
    68  	switch s4 := i.(type) {
    69  	case string:
    70  		_ = s4
    71  	}
    72  	_, _, _, _ = s1, s2, s3, ok
    73  
    74  	// Goroutine
    75  	go a()    // UNCHECKED
    76  	defer a() // UNCHECKED
    77  
    78  	b1 := bytes.Buffer{}
    79  	b2 := &bytes.Buffer{}
    80  	b1.Write(nil)
    81  	b2.Write(nil)
    82  	rand.Read(nil)
    83  	mrand.Read(nil)
    84  	sha256.New().Write([]byte{})
    85  
    86  	ioutil.ReadFile("main.go") // UNCHECKED
    87  
    88  	var emiw ErrorMakerInterfaceWrapper
    89  	emiw.MakeNilError()
    90  }