mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Fix failing static analyzer tests (#7363)
* add "want" expectations * add build step with analyzer tests * add colon to yml * Merge refs/heads/master into fix-analyzer-test-expectations * Merge refs/heads/master into fix-analyzer-test-expectations * Merge refs/heads/master into fix-analyzer-test-expectations * Merge refs/heads/master into fix-analyzer-test-expectations * remove tests from CI * readme file * change header size
This commit is contained in:
parent
bedb16cfb0
commit
fe9921457c
7
tools/analyzers/README.md
Normal file
7
tools/analyzers/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Running analyzer unit tests
|
||||
|
||||
Analyzers' unit tests are ignored in bazel's build files, and therefore are not being triggered as part of the CI
|
||||
pipeline. Because of this they should be invoked manually when writing a new analyzer or making changes to an existing
|
||||
one. Otherwise, any issues will go unnoticed during the CI build.
|
||||
|
||||
The easiest way to run all unit tests for all analyzers is `go test ./tools/analyzers/...`
|
@ -7,17 +7,19 @@ import (
|
||||
)
|
||||
|
||||
func UseRandNewCustomImport() {
|
||||
randGenerator := mathRand.New(mathRand.NewSource(time.Now().UnixNano()))
|
||||
source := mathRand.NewSource(time.Now().UnixNano()) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
randGenerator := mathRand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
start := uint64(randGenerator.Intn(32))
|
||||
_ = start
|
||||
|
||||
randGenerator = mathRand.New(mathRand.NewSource(time.Now().UnixNano()))
|
||||
source = mathRand.NewSource(time.Now().UnixNano()) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
randGenerator = mathRand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
}
|
||||
|
||||
func UseWithoutSeeCustomImportd() {
|
||||
assignedIndex := mathRand.Intn(128)
|
||||
assignedIndex := mathRand.Intn(128) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
_ = assignedIndex
|
||||
foobar.Shuffle(10, func(i, j int) {
|
||||
foobar.Shuffle(10, func(i, j int) { // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
|
||||
})
|
||||
}
|
||||
|
@ -7,14 +7,16 @@ import (
|
||||
)
|
||||
|
||||
func UseRandNew() {
|
||||
randGenerator := mathRand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
source := rand.NewSource(time.Now().UnixNano()) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
randGenerator := mathRand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
start := uint64(randGenerator.Intn(32))
|
||||
_ = start
|
||||
|
||||
randGenerator = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
source = rand.NewSource(time.Now().UnixNano()) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
randGenerator = rand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
}
|
||||
|
||||
func UseWithoutSeed() {
|
||||
assignedIndex := rand.Intn(128)
|
||||
assignedIndex := rand.Intn(128) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
|
||||
_ = assignedIndex
|
||||
}
|
||||
|
4
tools/analyzers/nop/testdata/no_op.go
vendored
4
tools/analyzers/nop/testdata/no_op.go
vendored
@ -5,10 +5,10 @@ type foo struct {
|
||||
|
||||
func AddressOfDereferencedValue() {
|
||||
x := &foo{}
|
||||
_ = &*x // want "Found a no-op instruction that can be safely removed. It might be a result of writing code that does not work as expected."
|
||||
_ = &*x // want "Found a no-op instruction that can be safely removed. It might be a result of writing code that does not do what was intended."
|
||||
}
|
||||
|
||||
func DereferencedAddressOfValue() {
|
||||
x := foo{}
|
||||
_ = *&x // want "Found a no-op instruction that can be safely removed. It might be a result of writing code that does not work as expected."
|
||||
_ = *&x // want "Found a no-op instruction that can be safely removed. It might be a result of writing code that does not do what was intended."
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user