Skip to content

Commit

Permalink
make sha256 test in crypto/sha256 package
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz834 committed Feb 13, 2025
1 parent d3d5a3b commit 68ee1cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
14 changes: 14 additions & 0 deletions src/crypto/sha256/sha256_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,17 @@ func BenchmarkHash1K(b *testing.B) {
func BenchmarkHash8K(b *testing.B) {
benchmarkSize(b, 8192)
}

func TestAllocatonsWithTypeAsserts(t *testing.T) {
cryptotest.SkipTestAllocations(t)
allocs := testing.AllocsPerRun(100, func() {
h := New()
h.Write([]byte{1, 2, 3})
marshaled, _ := h.(encoding.BinaryMarshaler).MarshalBinary()
marshaled, _ = h.(encoding.BinaryAppender).AppendBinary(marshaled[:0])
h.(encoding.BinaryUnmarshaler).UnmarshalBinary(marshaled)
})
if allocs != 0 {
t.Fatalf("allocs = %v; want = 0", allocs)
}
}
18 changes: 0 additions & 18 deletions test/escape_iface_with_devirt_type_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

package escape

import (
"crypto/sha256"
"encoding"
"hash"
"io"
)

type M interface{ M() }

type A interface{ A() }
Expand Down Expand Up @@ -138,14 +131,3 @@ func testInvalidAsserts() {
a.(any).(M).(*Impl).M() // ERROR "inlining"
}
}

func testSha256() {
h := sha256.New() // ERROR "inlining call" "does not escape"
h.Write(nil) // ERROR "devirtualizing"
h.(io.Writer).Write(nil) // ERROR "devirtualizing"
h.(hash.Hash).Write(nil) // ERROR "devirtualizing"
h.(encoding.BinaryUnmarshaler).UnmarshalBinary(nil) // ERROR "devirtualizing"

h2 := sha256.New() // ERROR "escapes" "inlining call"
h2.(M).M() // this will panic
}

0 comments on commit 68ee1cb

Please sign in to comment.