@@ -774,6 +774,8 @@ def macro():
774774}
775775
776776func TestNativeShBinaryWarning (t * testing.T ) {
777+ defer setUpFileReader (nil )()
778+
777779 checkFindingsAndFix (t , "native-sh-binary" , `
778780"""My file"""
779781
@@ -799,6 +801,8 @@ sh_binary()
799801}
800802
801803func TestNativeShLibraryWarning (t * testing.T ) {
804+ defer setUpFileReader (nil )()
805+
802806 checkFindingsAndFix (t , "native-sh-library" , `
803807"""My file"""
804808
@@ -824,6 +828,8 @@ sh_library()
824828}
825829
826830func TestNativeShTestWarning (t * testing.T ) {
831+ defer setUpFileReader (nil )()
832+
827833 checkFindingsAndFix (t , "native-sh-test" , `
828834"""My file"""
829835
@@ -848,6 +854,68 @@ sh_test()
848854 scopeBzl | scopeBuild )
849855}
850856
857+ func TestNativeWarningLoadPlacedAfterFileDocstringWithComment (t * testing.T ) {
858+ defer setUpFileReader (nil )()
859+
860+ checkFindingsAndFix (t , "native-sh-binary,native-java-binary" , `
861+ # Copyright 2020 Google LLC
862+ #
863+ # Licensed under the Apache License, Version 2.0 (the "License");
864+ # you may not use this file except in compliance with the License.
865+ # You may obtain a copy of the License at
866+ #
867+ # https://www.apache.org/licenses/LICENSE-2.0
868+ #
869+ # Unless required by applicable law or agreed to in writing, software
870+ # distributed under the License is distributed on an "AS IS" BASIS,
871+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
872+ # See the License for the specific language governing permissions and
873+ # limitations under the License.
874+
875+ """My file"""
876+
877+ def macro():
878+ native.sh_binary()
879+ native.java_binary()
880+
881+ java_binary()
882+ sh_binary()
883+ ` , `
884+ # Copyright 2020 Google LLC
885+ #
886+ # Licensed under the Apache License, Version 2.0 (the "License");
887+ # you may not use this file except in compliance with the License.
888+ # You may obtain a copy of the License at
889+ #
890+ # https://www.apache.org/licenses/LICENSE-2.0
891+ #
892+ # Unless required by applicable law or agreed to in writing, software
893+ # distributed under the License is distributed on an "AS IS" BASIS,
894+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
895+ # See the License for the specific language governing permissions and
896+ # limitations under the License.
897+
898+ """My file"""
899+
900+ load("@rules_java//java:java_binary.bzl", "java_binary")
901+ load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
902+
903+ def macro():
904+ sh_binary()
905+ java_binary()
906+
907+ java_binary()
908+ sh_binary()
909+ ` ,
910+ []string {
911+ fmt .Sprintf (`:18: Function "sh_binary" is not global anymore and needs to be loaded from "@rules_shell//shell:sh_binary.bzl".` ),
912+ fmt .Sprintf (`:19: Function "java_binary" is not global anymore and needs to be loaded from "@rules_java//java:java_binary.bzl".` ),
913+ fmt .Sprintf (`:21: Function "java_binary" is not global anymore and needs to be loaded from "@rules_java//java:java_binary.bzl".` ),
914+ fmt .Sprintf (`:22: Function "sh_binary" is not global anymore and needs to be loaded from "@rules_shell//shell:sh_binary.bzl".` ),
915+ },
916+ scopeBzl | scopeBuild )
917+ }
918+
851919func TestKeywordParameters (t * testing.T ) {
852920 checkFindingsAndFix (t , "keyword-positional-params" , `
853921foo(key = value)
0 commit comments