strings: don't assert on Replace's allocs for ASAN

CL 657935 caused failures on the ASAN builder.

Under ASAN, do not assert on the number of allocations incurred by Replace.

Fixes #72973

Change-Id: I61536be6def6f2489d2a026c943c6e232865b723
GitHub-Last-Rev: 4aee3c2560
GitHub-Pull-Request: golang/go#72975
Reviewed-on: https://go-review.googlesource.com/c/go/+/659696
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
This commit is contained in:
Julien Cretel 2025-03-20 20:33:46 +00:00 committed by Gopher Robot
parent b613d21ffd
commit 93fe8c0415

View file

@ -7,6 +7,7 @@ package strings_test
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"internal/asan"
"io" "io"
"iter" "iter"
"math" "math"
@ -1473,9 +1474,11 @@ var ReplaceTests = []struct {
func TestReplace(t *testing.T) { func TestReplace(t *testing.T) {
for _, tt := range ReplaceTests { for _, tt := range ReplaceTests {
allocs := testing.AllocsPerRun(10, func() { Replace(tt.in, tt.old, tt.new, tt.n) }) if !asan.Enabled { // See issue #72973.
if allocs > 1 { allocs := testing.AllocsPerRun(10, func() { Replace(tt.in, tt.old, tt.new, tt.n) })
t.Errorf("Replace(%q, %q, %q, %d) allocates %.2f objects", tt.in, tt.old, tt.new, tt.n, allocs) if allocs > 1 {
t.Errorf("Replace(%q, %q, %q, %d) allocates %.2f objects", tt.in, tt.old, tt.new, tt.n, allocs)
}
} }
if s := Replace(tt.in, tt.old, tt.new, tt.n); s != tt.out { if s := Replace(tt.in, tt.old, tt.new, tt.n); s != tt.out {
t.Errorf("Replace(%q, %q, %q, %d) = %q, want %q", tt.in, tt.old, tt.new, tt.n, s, tt.out) t.Errorf("Replace(%q, %q, %q, %d) = %q, want %q", tt.in, tt.old, tt.new, tt.n, s, tt.out)