-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test and fix check blanks in var declarations (#219)
- Loading branch information
Showing
3 changed files
with
131 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
package errcheck | ||
|
||
import ( | ||
"golang.org/x/tools/go/analysis/analysistest" | ||
"path/filepath" | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis/analysistest" | ||
) | ||
|
||
func TestAnalyzer(t *testing.T) { | ||
packageDir := filepath.Join(analysistest.TestData(), "src/a/") | ||
_ = analysistest.Run(t, packageDir, Analyzer) | ||
t.Run("default flags", func(t *testing.T) { | ||
packageDir := filepath.Join(analysistest.TestData(), "src/a/") | ||
_ = analysistest.Run(t, packageDir, Analyzer) | ||
}) | ||
|
||
t.Run("check blanks", func(t *testing.T) { | ||
packageDir := filepath.Join(analysistest.TestData(), "src/blank/") | ||
Analyzer.Flags.Set("blank", "true") | ||
_ = analysistest.Run(t, packageDir, Analyzer) | ||
Analyzer.Flags.Set("blank", "false") // reset it | ||
}) | ||
|
||
t.Run("check asserts", func(t *testing.T) { | ||
packageDir := filepath.Join(analysistest.TestData(), "src/assert/") | ||
Analyzer.Flags.Set("assert", "true") | ||
_ = analysistest.Run(t, packageDir, Analyzer) | ||
Analyzer.Flags.Set("assert", "false") // reset it | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,37 @@ | ||
package blank | ||
|
||
import "fmt" | ||
|
||
func a() error { | ||
return nil | ||
} | ||
|
||
func b() (string, error) { | ||
return "", nil | ||
} | ||
|
||
func c() string { | ||
return "" | ||
} | ||
|
||
func main() { | ||
_ = a() // want "unchecked error" | ||
a() // want "unchecked error" | ||
b() // want "unchecked error" | ||
c() // ignored, doesn't return an error | ||
|
||
{ | ||
r, err := b() // fine, we're checking the error | ||
fmt.Printf("r = %v, err = %v\n", r, err) | ||
} | ||
|
||
{ | ||
r, _ := b() // want "unchecked error" | ||
fmt.Printf("r = %v\n", r) | ||
} | ||
|
||
{ | ||
var r, _ = b() // want "unchecked error" | ||
fmt.Printf("r = %v\n", r) | ||
} | ||
} |