pingcap / failpoint

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

code: add support for ast.IncDecStmt #23

Closed lonng closed 5 years ago

lonng commented 5 years ago

Signed-off-by: Lonng chris@lonng.org

What problem does this PR solve?

package rewriter_test

import (
    "fmt"

    "github.com/pingcap/failpoint"
)

func unittest() {
    type X struct {
        Y int
    }
    func() *X {
        failpoint.Inject("failpoint-name", func(val failpoint.Value) *X {
            return &X{Y: val.(int)}
        })
        return &X{Y: 100}
    }().Y++
}

Need to translate to:

package rewriter_test

import (
    "fmt"

    "github.com/pingcap/failpoint"
)

func unittest() {
    type X struct {
        Y int
    }
    func() *X {
        if ok, val := failpoint.Eval(_curpkg_("failpoint-name")); ok {
            return &X{Y: val.(int)}
        }
        return &X{Y: 100}
    }().Y++
}

What is changed and how it works?

Add support for it.

Check List

Tests

Side effects

Related changes

codecov[bot] commented 5 years ago

Codecov Report

Merging #23 into master will decrease coverage by 0.3545%. The diff coverage is 66.6666%.

@@               Coverage Diff                @@
##             master        #23        +/-   ##
================================================
- Coverage   87.2266%   86.8721%   -0.3546%     
================================================
  Files             7          7                
  Lines           869        876         +7     
================================================
+ Hits            758        761         +3     
- Misses           70         73         +3     
- Partials         41         42         +1
lonng commented 5 years ago

@amyangfei @kennytm PTAL