Skip to content

Commit

Permalink
Ensure bzlmod example tests are run (#2371)
Browse files Browse the repository at this point in the history
A followup to
#2370 (comment)
  • Loading branch information
UebelAndre authored Dec 28, 2023
1 parent 0b0b5c0 commit 0a9e3b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,13 @@ tasks:
name: bzlmod BCR presubmit
platform: ubuntu2004
working_directory: examples/bzlmod/hello_world
build_targets:
test_targets:
- "//..."
macos_bzlmod_bcr:
name: bzlmod BCR presubmit
platform: macos
working_directory: examples/bzlmod/hello_world
build_targets:
test_targets:
- "//..."

buildifier:
Expand Down
2 changes: 1 addition & 1 deletion examples/bzlmod/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sh_test(
name = "hello_world_test",
srcs = ["hello_world_test.sh"],
args = [
"$(rootpath :hello_world)",
"$(rlocationpath :hello_world)",
],
data = [
":hello_world",
Expand Down
22 changes: 18 additions & 4 deletions examples/bzlmod/hello_world/hello_world_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/usr/bin/env bash

# --- begin runfiles.bash initialization v3 ---
# Copy-pasted from the Bazel Bash runfiles library v3.
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v3 ---


set -euo pipefail

# MARK - Functions

fail() {
Expand All @@ -12,10 +26,10 @@ fail() {
if [[ "$#" -ne 1 ]]; then
fail "Usage: $0 /path/to/hello_world"
fi
hello_world="$1"
HELLO_WORLD="$(rlocation "$1")"

# MARK - Test

output="$( "${hello_world}" )"
[[ "${output}" == "Hello, world!" ]] || \
fail 'Expected "Hello, world!", but was' "${output}"
OUTPUT="$("${HELLO_WORLD}")"
[[ "${OUTPUT}" == "Hello, world!" ]] ||
fail 'Expected "Hello, world!", but was' "${OUTPUT}"

0 comments on commit 0a9e3b1

Please sign in to comment.