1
0
mirror of https://github.com/golang/go synced 2024-11-25 13:27:57 -07:00

crypto,hash: add t.Helper calls to test helpers

Use t.Helper to make the reported failure lines more helpful.
This commit is contained in:
apocelipes 2024-08-12 19:13:40 +08:00
parent 18fc547b21
commit 2e020ea85c
7 changed files with 13 additions and 0 deletions

View File

@ -24,6 +24,7 @@ func testSignAndVerify(t *testing.T, i int, priv *PrivateKey) {
}
func testParameterGeneration(t *testing.T, sizes ParameterSizes, L, N int) {
t.Helper()
var priv PrivateKey
params := &priv.Parameters

View File

@ -19,6 +19,7 @@ import (
)
func mustDecodeHex(t *testing.T, in string) []byte {
t.Helper()
b, err := hex.DecodeString(in)
if err != nil {
t.Fatal(err)

View File

@ -163,6 +163,7 @@ func TestX509MixedKeyPair(t *testing.T) {
}
func newLocalListener(t testing.TB) net.Listener {
t.Helper()
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
ln, err = net.Listen("tcp6", "[::1]:0")

View File

@ -27,6 +27,7 @@ const (
)
func boringRSAKey(t *testing.T, size int) *rsa.PrivateKey {
t.Helper()
k, err := rsa.GenerateKey(rand.Reader, size)
if err != nil {
t.Fatal(err)
@ -35,6 +36,7 @@ func boringRSAKey(t *testing.T, size int) *rsa.PrivateKey {
}
func boringECDSAKey(t *testing.T, curve elliptic.Curve) *ecdsa.PrivateKey {
t.Helper()
k, err := ecdsa.GenerateKey(curve, rand.Reader)
if err != nil {
t.Fatal(err)

View File

@ -320,6 +320,7 @@ func BenchmarkOIDMarshalUnmarshalText(b *testing.B) {
}
func mustNewOIDFromInts(t testing.TB, ints []uint64) OID {
t.Helper()
oid, err := OIDFromInts(ints)
if err != nil {
t.Fatalf("OIDFromInts(%v) unexpected error: %v", ints, err)

View File

@ -1472,6 +1472,7 @@ func TestCreateCertificateRequest(t *testing.T) {
}
func marshalAndParseCSR(t *testing.T, template *CertificateRequest) *CertificateRequest {
t.Helper()
derBytes, err := CreateCertificateRequest(rand.Reader, template, testPrivateKey)
if err != nil {
t.Fatal(err)
@ -1636,6 +1637,7 @@ func TestCriticalFlagInCSRRequestedExtensions(t *testing.T) {
// serialiseAndParse generates a self-signed certificate from template and
// returns a parsed version of it.
func serialiseAndParse(t *testing.T, template *Certificate) *Certificate {
t.Helper()
derBytes, err := CreateCertificate(rand.Reader, template, template, &testPrivateKey.PublicKey, testPrivateKey)
if err != nil {
t.Fatalf("failed to create certificate: %s", err)

View File

@ -96,6 +96,7 @@ func (s *hashSet) addS_seed(x string, seed Seed) {
s.add(h.Sum64())
}
func (s *hashSet) check(t *testing.T) {
t.Helper()
list := s.list
slices.Sort(list)
@ -259,6 +260,7 @@ func TestSmhasherSparse(t *testing.T) {
sparse(t, h, 2048, 2)
}
func sparse(t *testing.T, h *hashSet, n int, k int) {
t.Helper()
b := make([]byte, n/8)
setbits(h, b, 0, k)
h.check(t)
@ -295,6 +297,7 @@ func TestSmhasherPermutation(t *testing.T) {
permutation(t, h, []uint32{0, 1, 2, 3, 4, 5, 6, 7, 1 << 29, 2 << 29, 3 << 29, 4 << 29, 5 << 29, 6 << 29, 7 << 29}, 6)
}
func permutation(t *testing.T, h *hashSet, s []uint32, n int) {
t.Helper()
b := make([]byte, n*4)
genPerm(h, b, s, 0)
h.check(t)
@ -362,6 +365,7 @@ func TestSmhasherAvalanche(t *testing.T) {
avalancheTest1(t, &bytesKey{make([]byte, 200)})
}
func avalancheTest1(t *testing.T, k key) {
t.Helper()
const REP = 100000
r := rand.New(rand.NewSource(1234))
n := k.bits()
@ -456,6 +460,7 @@ func TestSmhasherText(t *testing.T) {
text(t, h, "", "FooBar")
}
func text(t *testing.T, h *hashSet, prefix, suffix string) {
t.Helper()
const N = 4
const S = "ABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrst0123456789"
const L = len(S)