From 7cd52a3c8be66090a25dd0feb4db5661a3ba2cb2 Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Mon, 27 Apr 2026 14:39:46 -0700 Subject: [PATCH] bazelisk.py supports bazeliskVersion Also add missing regression test of the Go implementation. --- bazelisk.py | 4 ++++ bazelisk_test.sh | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/bazelisk.py b/bazelisk.py index e182c643..d510f3a0 100755 --- a/bazelisk.py +++ b/bazelisk.py @@ -523,6 +523,10 @@ def main(argv=None): if argv is None: argv = sys.argv + if argv[1:] == ["bazeliskVersion"]: + print("Bazelisk version: Python") + return 0 + bazel_path = get_bazel_path() argv = argv[1:] diff --git a/bazelisk_test.sh b/bazelisk_test.sh index d5c9458e..d9ea9ba9 100755 --- a/bazelisk_test.sh +++ b/bazelisk_test.sh @@ -36,7 +36,7 @@ else fi # --- end runfiles.bash initialization --- -BAZELISK_VERSION=$1 +BAZELISK_TEST_LANG=$1 # One of "GO", "PY", or "PY3". shift 1 # TODO: only the Python version reads bazelbuild-releases.json since it uses @@ -65,7 +65,7 @@ function setup() { function bazelisk() { if [[ -n $(rlocation _main/bazelisk.py) ]]; then - if [[ $BAZELISK_VERSION == "PY3" ]]; then + if [[ $BAZELISK_TEST_LANG == "PY3" ]]; then echo "Running Bazelisk with $(python3 -V)..." python3 "$(rlocation _main/bazelisk.py)" "$@" else @@ -95,6 +95,16 @@ function bazelisk() { fi } +function test_bazelisk_version() { + setup + + BAZELISK_HOME="$BAZELISK_HOME" \ + bazelisk bazeliskVersion 2>&1 | tee log + + grep "Bazelisk version: " log || \ + (echo "FAIL: Expected to find 'Bazelisk version' in the output of 'bazelisk bazeliskVersion'"; exit 1) +} + function test_bazel_version_py() { setup @@ -517,6 +527,10 @@ function test_bazel_prepend_binary_directory_to_path_py() { (echo "FAIL: Expected PATH to contains bazel binary directory."; exit 1) } +echo "# test_bazelisk_version" +test_bazelisk_version +echo + echo "# test_bazel_version_from_environment" test_bazel_version_from_environment echo @@ -541,7 +555,7 @@ echo "# test_BAZELISK_NOJDK" test_BAZELISK_NOJDK echo -if [[ $BAZELISK_VERSION == "GO" ]]; then +if [[ $BAZELISK_TEST_LANG == "GO" ]]; then echo "# test_bazel_version_go" test_bazel_version_go echo