From a577b018e81b9fcd89cf8163bd185bac52f8b76e Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Fri, 3 May 2019 19:08:37 +0200 Subject: [PATCH] facts: move relevant tests into facts package --- facts/facts_test.go | 15 +++++++++++++++ facts/testdata/src/Deprecated/Deprecated.go | 5 +++++ facts/testdata/src/Purity/CheckPureFunctions.go | 17 +++++++++++++++++ .../src/CheckDeprecated_go14/CheckDeprecated.go | 2 +- .../src/CheckDeprecated_go18/CheckDeprecated.go | 2 +- .../CheckPureFunctions/CheckPureFunctions.go | 2 +- 6 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 facts/facts_test.go create mode 100644 facts/testdata/src/Deprecated/Deprecated.go create mode 100644 facts/testdata/src/Purity/CheckPureFunctions.go diff --git a/facts/facts_test.go b/facts/facts_test.go new file mode 100644 index 000000000..6e7de1afa --- /dev/null +++ b/facts/facts_test.go @@ -0,0 +1,15 @@ +package facts + +import ( + "testing" + + "golang.org/x/tools/go/analysis/analysistest" +) + +func TestDeprecated(t *testing.T) { + analysistest.Run(t, analysistest.TestData(), Deprecated, "Deprecated") +} + +func TestPurity(t *testing.T) { + analysistest.Run(t, analysistest.TestData(), Purity, "Purity") +} diff --git a/facts/testdata/src/Deprecated/Deprecated.go b/facts/testdata/src/Deprecated/Deprecated.go new file mode 100644 index 000000000..14f463d85 --- /dev/null +++ b/facts/testdata/src/Deprecated/Deprecated.go @@ -0,0 +1,5 @@ +package pkg + +// Deprecated: Don't use this. +func fn2() { // want fn2:`Deprecated: Don't use this\.` +} diff --git a/facts/testdata/src/Purity/CheckPureFunctions.go b/facts/testdata/src/Purity/CheckPureFunctions.go new file mode 100644 index 000000000..b31f153e0 --- /dev/null +++ b/facts/testdata/src/Purity/CheckPureFunctions.go @@ -0,0 +1,17 @@ +package pkg + +func foo(a, b int) int { return a + b } // want foo:"is pure" +func bar(a, b int) int { + println(a + b) + return a + b +} + +func empty() {} +func stubPointer() *int { return nil } +func stubInt() int { return 0 } + +func fn3() { + empty() + stubPointer() + stubInt() +} diff --git a/staticcheck/testdata/src/CheckDeprecated_go14/CheckDeprecated.go b/staticcheck/testdata/src/CheckDeprecated_go14/CheckDeprecated.go index bd2420707..1e8c272ab 100644 --- a/staticcheck/testdata/src/CheckDeprecated_go14/CheckDeprecated.go +++ b/staticcheck/testdata/src/CheckDeprecated_go14/CheckDeprecated.go @@ -28,7 +28,7 @@ func fn1(err error) { } // Deprecated: Don't use this. -func fn2() { // want fn2:`Deprecated: Don't use this\.` +func fn2() { _ = syscall.StringByteSlice("") anon := func(x int) { diff --git a/staticcheck/testdata/src/CheckDeprecated_go18/CheckDeprecated.go b/staticcheck/testdata/src/CheckDeprecated_go18/CheckDeprecated.go index 06754df19..470d46bad 100644 --- a/staticcheck/testdata/src/CheckDeprecated_go18/CheckDeprecated.go +++ b/staticcheck/testdata/src/CheckDeprecated_go18/CheckDeprecated.go @@ -28,7 +28,7 @@ func fn1(err error) { } // Deprecated: Don't use this. -func fn2() { // want fn2:`Deprecated: Don't use this\.` +func fn2() { _ = syscall.StringByteSlice("") anon := func(x int) { diff --git a/staticcheck/testdata/src/CheckPureFunctions/CheckPureFunctions.go b/staticcheck/testdata/src/CheckPureFunctions/CheckPureFunctions.go index 5a269e829..a5fbd1444 100644 --- a/staticcheck/testdata/src/CheckPureFunctions/CheckPureFunctions.go +++ b/staticcheck/testdata/src/CheckPureFunctions/CheckPureFunctions.go @@ -17,7 +17,7 @@ func fn2() { r.WithContext(context.Background()) // want `is a pure function but its return value is ignored` } -func foo(a, b int) int { return a + b } // want foo:"IsPure" +func foo(a, b int) int { return a + b } func bar(a, b int) int { println(a + b) return a + b