| # Copyright 2025 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| # Description: |
| # This package provides reusable shell binaries and wrappers for common test |
| # scenarios, such as forcing a success or failure condition. |
| # Tests for these wrappers are in the 'tests' sibling directory. |
| |
| load("//tools/bazel/sh_wrapper:sh_wrapper.bzl", "sh_wrapper") |
| |
| package(default_visibility = ["//visibility:public"]) |
| |
| sh_binary( |
| name = "true", |
| srcs = ["true.sh"], |
| ) |
| |
| sh_binary( |
| name = "false", |
| srcs = ["false.sh"], |
| ) |
| |
| sh_wrapper( |
| name = "true_cmd", |
| executable = ":true", |
| position = "terminal", |
| ) |
| |
| sh_wrapper( |
| name = "false_cmd", |
| executable = ":false", |
| position = "terminal", |
| ) |
| |
| sh_binary( |
| name = "echo", |
| srcs = ["echo.sh"], |
| ) |
| |
| sh_wrapper( |
| name = "echo_cmd", |
| args = [ |
| "not-a-build-tool", |
| ], |
| executable = ":echo", |
| position = "terminal", |
| ) |
| |
| sh_binary( |
| name = "check_exit_code", |
| srcs = ["check_exit_code.sh"], |
| ) |
| |
| sh_wrapper( |
| name = "expect_success", |
| args = [ |
| "--expected_exit_code", |
| "0", |
| "--", |
| ], |
| executable = ":check_exit_code", |
| position = "nonterminal", |
| ) |
| |
| sh_wrapper( |
| name = "expect_failure_1", |
| args = [ |
| "--expected_exit_code", |
| "1", |
| "--", |
| ], |
| executable = ":check_exit_code", |
| position = "nonterminal", |
| ) |
| |
| # This wrapper should be placed at the beginning of a test chain to verify |
| # that the wrapped command exits with code 130 (interrupt). |
| # This is typically used in conjunction with the `send_sigint_wrapper`. |
| sh_wrapper( |
| name = "expect_interrupt", |
| args = [ |
| "--expected_exit_code", |
| "130", |
| "--", |
| ], |
| executable = ":check_exit_code", |
| position = "nonterminal", |
| ) |
| |
| sh_binary( |
| name = "sleepy_cat", |
| srcs = ["sleepy_cat.sh"], |
| ) |
| |
| sh_wrapper( |
| name = "sleepy_cat_cmd", |
| executable = ":sleepy_cat", |
| position = "terminal", |
| ) |
| |
| sh_binary( |
| name = "send_sigint", |
| srcs = ["send_sigint.sh"], |
| ) |
| |
| # This wrapper sends a SIGINT to its child process, and is useful for testing |
| # signal handling and graceful shutdown. It should be placed before the command |
| # that is intended to receive the signal. |
| # This is intended to be used with the `expect_interrupt` wrapper to verify |
| # the exit code. |
| sh_wrapper( |
| name = "send_sigint_wrapper", |
| executable = ":send_sigint", |
| position = "nonterminal", |
| ) |
| |
| sh_binary( |
| name = "set_glog_v", |
| srcs = ["set_glog_v.sh"], |
| ) |
| |
| sh_wrapper( |
| name = "set_glog_v_wrapper", |
| executable = ":set_glog_v", |
| position = "nonterminal", |
| ) |