github.com/bazelbuild/rules_go@v0.47.2-0.20240515105122-e7ddb9ea474e/go/private/tools/lines_sorted_test.bzl (about) 1 # Copyright 2016 The Bazel Go Rules Authors. All rights reserved. 2 # Copyright 2016 The Closure Rules Authors. All rights reserved. 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 # http://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 load("//go/private/tools:files_equal_test.bzl", "files_equal_test") 17 18 def lines_sorted_test(name, file, cmd = "cat $< >$@", visibility = None, **kwargs): 19 """Tests that lines within a file are sorted.""" 20 21 native.genrule( 22 name = name + "_lines", 23 testonly = True, 24 srcs = [file], 25 outs = [name + "_lines.txt"], 26 cmd = cmd, 27 visibility = visibility, 28 ) 29 30 native.genrule( 31 name = name + "_lines_sorted", 32 testonly = True, 33 srcs = [name + "_lines.txt"], 34 outs = [name + "_lines_sorted.txt"], 35 cmd = "sort $< >$@", 36 visibility = visibility, 37 ) 38 39 files_equal_test( 40 name = name, 41 actual = name + "_lines.txt", 42 golden = name + "_lines_sorted.txt", 43 visibility = visibility, 44 **kwargs 45 )