<commit_before>package govet

import (
	"fmt"
	"testing"

	"strings"

	"github.com/surullabs/statictest"
	"github.com/surullabs/statictest/testutil"
)

func testVetError(err error) error {
	skippable, ok := err.(*statictest.Error)
	if !ok {
		return fmt.Errorf("unexpected type of error: %v", err)
	}
	if len(skippable.Errors) != 2 {
		return fmt.Errorf("expected 2 errors, got: %v", err)
	}
	if !strings.HasSuffix(skippable.Errors[0], "unreachable code") {
		return err
	}
	if !strings.Contains(skippable.Errors[1], "result of fmt.Sprintf call not used") {
		return err
	}
	return nil
}

func TestGoVet(t *testing.T) {
	testutil.Test(t, "govettest", []testutil.StaticCheckTest{
		{
			Checker: Check{},
			Content: []byte(`package govettest
import (
	"fmt"
)

// TestFunc is a test function
func TestFunc() {
	fmt.Println("This is a properly formatted file")
}
`),
			Validate: testutil.NoError,
		},
		{
			Checker: Check{},
			Content: []byte(`package govettest

import (
	"fmt"
)
sfsff

func TestFunc() {
	fmt.Println("undocumented")
}
`),
			Validate: testutil.Contains("expected declaration, found 'IDENT' sfsff"),
		},
		{
			Checker: Check{},
			Content: []byte(`package gofmttest

import (
	"fmt"
)

func TestFunc() {
    a := "test"
    b := a
    fmt.Sprintf("test")
    return
    fmt.Println("This is a poorly formatted file", b)
}
`),
			Validate: testVetError,
		},
		{
			Checker: Shadow,
			Content: []byte(`package gofmttest

import (
	"fmt"
)

func TestFunc() (err error) {
    err = fmt.Println("another")
    if err != nil {
    	err := fmt.Errorf("some error: %v", err)
    }
    return err
}
`),
			Validate: testutil.Contains(`declaration of "err" shadows declaration at`),
		},
	})

}
<commit_msg>Fix the govet test<commit_after>package govet

import (
	"fmt"
	"testing"

	"strings"

	"github.com/surullabs/statictest/testutil"
)

func testVetError(err error) error {
	type errors interface {
		Errors() []string
	}
	skippable, ok := err.(errors)
	if !ok {
		return fmt.Errorf("unexpected type of error: %v", err)
	}
	errs := skippable.Errors()
	if len(errs) != 2 {
		return fmt.Errorf("expected 2 errors, got: %v", err)
	}
	if !strings.HasSuffix(errs[0], "unreachable code") {
		return err
	}
	if !strings.Contains(errs[1], "result of fmt.Sprintf call not used") {
		return err
	}
	return nil
}

func TestGoVet(t *testing.T) {
	testutil.Test(t, "govettest", []testutil.StaticCheckTest{
		{
			Checker: Check{},
			Content: []byte(`package govettest
import (
	"fmt"
)

// TestFunc is a test function
func TestFunc() {
	fmt.Println("This is a properly formatted file")
}
`),
			Validate: testutil.NoError,
		},
		{
			Checker: Check{},
			Content: []byte(`package govettest

import (
	"fmt"
)
sfsff

func TestFunc() {
	fmt.Println("undocumented")
}
`),
			Validate: testutil.Contains("expected declaration, found 'IDENT' sfsff"),
		},
		{
			Checker: Check{},
			Content: []byte(`package gofmttest

import (
	"fmt"
)

func TestFunc() {
    a := "test"
    b := a
    fmt.Sprintf("test")
    return
    fmt.Println("This is a poorly formatted file", b)
}
`),
			Validate: testVetError,
		},
		{
			Checker: Shadow,
			Content: []byte(`package gofmttest

import (
	"fmt"
)

func TestFunc() (err error) {
    err = fmt.Println("another")
    if err != nil {
    	err := fmt.Errorf("some error: %v", err)
    }
    return err
}
`),
			Validate: testutil.Contains(`declaration of "err" shadows declaration at`),
		},
	})

}

{'fraction_non_alphanumeric': 0.15654952076677317, 'fraction_numerical': 0.0023235550392099913, 'mean_word_length': 3.56158940397351, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2598325', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1295, 'n_words': 311}