Skip to content

Commit 0d90fcb

Browse files
committed
Adds a test for the template linter
1 parent 1876535 commit 0d90fcb

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

linters/template/linter_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package template_test
2+
3+
import (
4+
"errors"
5+
stdtesting "testing"
6+
7+
"github.com/bvobart/mllint/api"
8+
"github.com/bvobart/mllint/config"
9+
"github.com/bvobart/mllint/linters/template"
10+
"github.com/bvobart/mllint/linters/testutils"
11+
"github.com/bvobart/mllint/utils"
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
// This test serves as an example test for a linter.
16+
// When implementing a new linter, copy and edit this test to use the linter you're implementing,
17+
// and create a suite of integration tests that cover the functionality of the linter.
18+
//
19+
// You can use options on the suite or on the test in order to e.g. specify which Python files to set on the project,
20+
// supply a specific Config that will be passed to the linter if it implements api.Configurable,
21+
// or provide / auto-detect the dependency managers in the project.
22+
func TestTemplateLinter(t *stdtesting.T) {
23+
linter := template.NewLinter()
24+
require.Equal(t, "Linter Template", linter.Name())
25+
require.Equal(t, []*api.Rule{&template.RuleSomething}, linter.Rules())
26+
27+
suite := testutils.NewLinterTestSuite(linter, []testutils.LinterTest{
28+
{
29+
Name: "ExampleTest",
30+
Dir: ".",
31+
Options: testutils.NewOptions().WithConfig(config.Default()),
32+
Expect: func(report api.Report, err error) {
33+
require.Error(t, err, errors.New("not implemented"))
34+
require.EqualValues(t, 80, report.Scores[template.RuleSomething])
35+
},
36+
},
37+
})
38+
// use DefaultOptions to edit the options that will be applied to every test (unless overridden by test options)
39+
suite.DefaultOptions().UsePythonFiles(utils.Filenames{"example.py"})
40+
suite.RunAll(t)
41+
}

0 commit comments

Comments
 (0)