#!/bin/bash

# Create a temporary standalone project directory to isolate from Bazel's own MODULE.bazel
TEST_DIR=$(mktemp -d)
trap 'rm -rf "$TEST_DIR"' EXIT

# Copy the C++ examples to the isolated test directory
mkdir -p "$TEST_DIR/examples/cpp"
cp examples/cpp/* "$TEST_DIR/examples/cpp/"

# Create a clean, minimal WORKSPACE and MODULE.bazel for the test project
touch "$TEST_DIR/WORKSPACE"
touch "$TEST_DIR/MODULE.bazel"

# Execute the test in the isolated directory
cd "$TEST_DIR"
bazel --batch test --define=distribution=debian --verbose_failures //examples/cpp:hello-fail_test

if [ $? -eq 3 ]; then
  exit 0
else
  exit 1
fi
