File tree Expand file tree Collapse file tree 7 files changed +157
-0
lines changed Expand file tree Collapse file tree 7 files changed +157
-0
lines changed Original file line number Diff line number Diff line change 11# This package aids testing the 'copy_directory' rule.
22
33load ("//rules:copy_directory.bzl" , "copy_directory" )
4+ load ("//tests/copy_directory:mnemonic_test.bzl" , "copy_directory_mnemonic_test" )
45load (":empty_directory.bzl" , "empty_directory" )
56
67licenses (["notice" ])
@@ -41,3 +42,16 @@ sh_test(
4142 ],
4243 deps = ["@bazel_tools//tools/bash/runfiles" ],
4344)
45+
46+ copy_directory (
47+ name = "copy_directory_mnemonic_test_target" ,
48+ src = "dir_with_subdir" ,
49+ out = "copied_dir_with_subdir" ,
50+ mnemonic = "FooBar" ,
51+ tags = ["manual" ],
52+ )
53+
54+ copy_directory_mnemonic_test (
55+ name = "copy_directory_mnemonic_test" ,
56+ target_under_test = ":copy_directory_mnemonic_test_target" ,
57+ )
Original file line number Diff line number Diff line change 1+ # Copyright 2019 The Bazel Authors. All rights reserved.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ """Custom mnemonic tests for copy_directory.bzl"""
16+
17+ load ("//lib:unittest.bzl" , "analysistest" , "asserts" )
18+ load ("//rules:copy_directory.bzl" , "copy_directory" )
19+
20+ def _copy_directory_mnemonic_test_impl (ctx ):
21+ env = analysistest .begin (ctx )
22+
23+ expected_mmemonic = "FooBar"
24+ actual_mnemonic = analysistest .target_actions (env )[0 ].mnemonic
25+
26+ asserts .equals (env , expected_mmemonic , actual_mnemonic )
27+
28+ return analysistest .end (env )
29+
30+ copy_directory_mnemonic_test = analysistest .make (_copy_directory_mnemonic_test_impl )
Original file line number Diff line number Diff line change 3232# of it, so we assert that that field contains the output file of the rule
3333
3434load ("//rules:copy_file.bzl" , "copy_file" )
35+ load ("//tests/copy_file:mnemonic_test.bzl" , "copy_file_mnemonic_test" )
3536
3637licenses (["notice" ])
3738
@@ -171,3 +172,16 @@ genrule(
171172 outs = ["b.txt" ],
172173 cmd = "echo -e '#!/usr/bin/env bash\n echo potato' > $@" ,
173174)
175+
176+ copy_file (
177+ name = "copy_file_mnemonic_test_target" ,
178+ src = "foo.txt" ,
179+ out = "bar.txt" ,
180+ mnemonic = "FooBar" ,
181+ tags = ["manual" ],
182+ )
183+
184+ copy_file_mnemonic_test (
185+ name = "copy_file_mnemonic_test" ,
186+ target_under_test = ":copy_file_mnemonic_test_target" ,
187+ )
Original file line number Diff line number Diff line change 1+ # Copyright 2019 The Bazel Authors. All rights reserved.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ """Custom mnemonic tests for copy_file.bzl"""
16+
17+ load ("//lib:unittest.bzl" , "analysistest" , "asserts" )
18+ load ("//rules:copy_file.bzl" , "copy_file" )
19+
20+ def _copy_file_mnemonic_test_impl (ctx ):
21+ env = analysistest .begin (ctx )
22+
23+ expected_mmemonic = "FooBar"
24+ actual_mnemonic = analysistest .target_actions (env )[0 ].mnemonic
25+
26+ asserts .equals (env , expected_mmemonic , actual_mnemonic )
27+
28+ return analysistest .end (env )
29+
30+ copy_file_mnemonic_test = analysistest .make (_copy_file_mnemonic_test_impl )
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary")
22load ("//rules:diff_test.bzl" , "diff_test" )
33load ("//rules:run_binary.bzl" , "run_binary" )
44load ("//rules:write_file.bzl" , "write_file" )
5+ load ("//tests/run_binary:mnemonic_test.bzl" , "run_binary_mnemonic_test" )
56
67package (
78 default_testonly = 1 ,
@@ -165,3 +166,21 @@ cc_binary(
165166 name = "printargs" ,
166167 srcs = ["printargs.cc" ],
167168)
169+
170+ cc_binary (
171+ name = "hello" ,
172+ srcs = ["hello.cc" ],
173+ )
174+
175+ run_binary (
176+ name = "run_binary_test_target" ,
177+ outs = ["hello.out" ],
178+ mnemonic = "FooBar" ,
179+ tags = ["manual" ],
180+ tool = ":hello" ,
181+ )
182+
183+ run_binary_mnemonic_test (
184+ name = "run_binary_mnemonic_test" ,
185+ target_under_test = ":run_binary_test_target" ,
186+ )
Original file line number Diff line number Diff line change 1+ // Copyright 2019 The Bazel Authors. All rights reserved.
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ #include < stdio.h>
16+
17+ int main () {
18+ printf (" Hello, world!" );
19+ return 0 ;
20+ }
Original file line number Diff line number Diff line change 1+ # Copyright 2019 The Bazel Authors. All rights reserved.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ """Custom mnemonic tests for run_binary.bzl"""
16+
17+ load ("//lib:unittest.bzl" , "analysistest" , "asserts" )
18+ load ("//rules:run_binary.bzl" , "run_binary" )
19+
20+ def _run_binary_mnemonic_test_impl (ctx ):
21+ env = analysistest .begin (ctx )
22+
23+ expected_mmemonic = "FooBar"
24+ actual_mnemonic = analysistest .target_actions (env )[0 ].mnemonic
25+
26+ asserts .equals (env , expected_mmemonic , actual_mnemonic )
27+
28+ return analysistest .end (env )
29+
30+ run_binary_mnemonic_test = analysistest .make (_run_binary_mnemonic_test_impl )
You can’t perform that action at this time.
0 commit comments