...
1
16
17 package warn
18
19 import "testing"
20
21 func TestDeprecatedFunction(t *testing.T) {
22 defer setUpFileReader(map[string]string{
23 "test/package/foo.bzl": `
24 def foo():
25 """
26 This is a function foo.
27
28 Please use it in favor of the
29 deprecated function bar
30 """
31 pass
32
33 def bar():
34 """
35 This is a function bar.
36
37 Deprecated:
38 please use foo instead.
39 """
40 pass
41 `,
42 "test/package/invalid.bzl": `
43 This is not a valid Starlark file
44 `,
45 })()
46
47 checkFindings(t, "deprecated-function", `
48 load(":foo.bzl", "foo", "bar", "baz")
49 load("//test/package:foo.bzl", "foo", "bar", "baz")
50 load(":invalid.bzl", "foo", "bar", "baz")
51 load(":nonexistent.bzl", "foo", "bar", "baz")
52 `,
53 []string{
54 `1: The function "bar" defined in "//test/package/foo.bzl" is deprecated.`,
55 `2: The function "bar" defined in "//test/package/foo.bzl" is deprecated.`,
56 },
57 scopeEverywhere)
58 }
59
60 func TestDeprecatedFunctionAnotherRepo(t *testing.T) {
61 defer setUpFileReader(map[string]string{
62 "test/package/foo.bzl": `
63 def foo():
64 """
65 This is a function foo.
66
67 Deprecated:
68 do not use.
69 """
70 pass
71 `,
72 })()
73
74 checkFindings(t, "deprecated-function", `
75 load("@another_repo//test/package:foo.bzl", "foo")
76 `,
77 []string{},
78 scopeEverywhere)
79 }
80
81 func TestDeprecatedFunctionNoReader(t *testing.T) {
82 checkFindings(t, "deprecated-function", `
83 load(":foo.bzl", "foo", "bar", "baz")
84 load("//test/package:foo.bzl", "foo", "bar", "baz")
85 load(":invalid.bzl", "foo", "bar", "baz")
86 load(":nonexistent.bzl", "foo", "bar", "baz")
87 `,
88 []string{},
89 scopeEverywhere)
90 }
91
View as plain text