pingcap / failpoint

An implementation of failpoints for Golang.
Apache License 2.0
817 stars 63 forks source link

code: support rewrite ExprStmt Init in IfStmt #24

Closed amyangfei closed 5 years ago

amyangfei commented 5 years ago

What problem does this PR solve?

initialization statement in if statement could be an ast.ExprStmt, such as following code snippet

const success = 200

func Hello() {
        var i int
        if func(v *int) {
                failpoint.Inject("failpoint-name", func(val failpoint.Value) {
                        fmt.Println("unit-test", val)
                })
                *v = success
        }(&i); i == success {
                failpoint.Inject("failpoint-name", func(val failpoint.Value) {
                        fmt.Println("unit-test", val)
                })
                fmt.Printf("i = %d success!\n", i)
        }
}

What is changed and how it works?

add support to it

Check List

Tests

codecov[bot] commented 5 years ago

Codecov Report

Merging #24 into master will increase coverage by 0.0447%. The diff coverage is 100%.

@@               Coverage Diff                @@
##             master        #24        +/-   ##
================================================
+ Coverage   86.8721%   86.9169%   +0.0448%     
================================================
  Files             7          7                
  Lines           876        879         +3     
================================================
+ Hits            761        764         +3     
  Misses           73         73                
  Partials         42         42
amyangfei commented 5 years ago

PTAL @lonng @kennytm