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:
Radosław Kapka 2020-09-29 13:29:40 +02:00 committed by GitHub
parent bedb16cfb0
commit fe9921457c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 9 deletions

View 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/...`

View File

@ -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"
})
}

View File

@ -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
}

View File

@ -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."
}