path: sync test code from httprouter

This commit is contained in:
Andy Pan 2020-01-06 22:38:52 +08:00
parent 0de76a5d88
commit 2e59578867

View File

@ -6,7 +6,6 @@
package gin
import (
"runtime"
"testing"
"github.com/stretchr/testify/assert"
@ -77,13 +76,17 @@ func TestPathCleanMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Log("skipping AllocsPerRun checks; GOMAXPROCS>1")
return
}
for _, test := range cleanTests {
allocs := testing.AllocsPerRun(100, func() { cleanPath(test.result) })
assert.EqualValues(t, allocs, 0)
}
}
func BenchmarkPathClean(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, test := range cleanTests {
cleanPath(test.path)
}
}
}