...

Source file src/github.com/bazelbuild/buildtools/warn/warn_deprecated_test.go

Documentation: github.com/bazelbuild/buildtools/warn

     1  /*
     2  Copyright 2020 Google LLC
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      https://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    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