pingcap / failpoint

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

code: fix assign case in select rewrite #9

Closed amyangfei closed 5 years ago

amyangfei commented 5 years ago

What problem does this PR solve?

rewrite will fail if we have an assign statement in select case, such as the following code snippet

select {
case ch := <-func() chan bool {
    failpoint.Inject("fptest", func() {
        fmt.Printf("in fp test...\n")
    })
    return make(chan bool)
}():
    fmt.Printf("recv ch %v\n", ch)
}

What is changed and how it works?

  1. if *ast.CommClause.Comm is *ast.AssignStmt, apply rewriteAssign to it
  2. the right-hand statement of an AssignStmt can be an *ast.UnaryExpr, rewrite it as possible
  3. fix parameter sequence of c.Assert, as the function is declared as func (c *C) Assert(obtained interface{}, checker Checker, args ...interface{})

Check List

Tests

codecov[bot] commented 5 years ago

Codecov Report

Merging #9 into master will increase coverage by 0.0681%. The diff coverage is 69.2307%.

@@               Coverage Diff                @@
##             master         #9        +/-   ##
================================================
+ Coverage   54.5918%   54.6599%   +0.0681%     
================================================
  Files             8          8                
  Lines           784        794        +10     
================================================
+ Hits            428        434         +6     
- Misses          273        275         +2     
- Partials         83         85         +2