| 1 | // Copyright 2018 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package printf_test |
| 6 | |
| 7 | import ( |
| 8 | "path/filepath" |
| 9 | "testing" |
| 10 | |
| 11 | "golang.org/x/tools/go/analysis/analysistest" |
| 12 | "golang.org/x/tools/go/analysis/passes/printf" |
| 13 | "golang.org/x/tools/internal/testenv" |
| 14 | "golang.org/x/tools/internal/testfiles" |
| 15 | ) |
| 16 | |
| 17 | func Test(t *testing.T) { |
| 18 | testdata := analysistest.TestData() |
| 19 | printf.Analyzer.Flags.Set("funcs", "Warn,Warnf") |
| 20 | |
| 21 | analysistest.Run(t, testdata, printf.Analyzer, |
| 22 | "a", "b", "nofmt", "nonconst", "typeparams", "issue68744", "issue70572", "issue72850", "issue76616", "w") |
| 23 | } |
| 24 | |
| 25 | func TestNonConstantFmtString_Go123(t *testing.T) { |
| 26 | testenv.NeedsGo1Point(t, 23) |
| 27 | |
| 28 | dir := testfiles.ExtractTxtarFileToTmp(t, filepath.Join(analysistest.TestData(), "nonconst_go123.txtar")) |
| 29 | analysistest.RunWithSuggestedFixes(t, dir, printf.Analyzer, "example.com/nonconst") |
| 30 | } |
| 31 | |
| 32 | func TestNonConstantFmtString_Go124(t *testing.T) { |
| 33 | testenv.NeedsGo1Point(t, 24) |
| 34 | |
| 35 | dir := testfiles.ExtractTxtarFileToTmp(t, filepath.Join(analysistest.TestData(), "nonconst_go124.txtar")) |
| 36 | analysistest.RunWithSuggestedFixes(t, dir, printf.Analyzer, "example.com/nonconst") |
| 37 | } |