#!/usr/bin/env bash
set -e

[ -z "$ZOOX_WORKSPACE_ROOT" ] && \
    echo "Cannot find ZOOX_WORKSPACE_ROOT; please run zooxrc.sh" && \
    exit -1

TEST_TARGETS=(
    "//firmware/emu/trajectory_manager/test/..."
    "//vehicle/ai_monitor/trajectory_manager/test/..."
)

INCLUDE_PATHS=(
    "firmware/emu/trajectory_manager"
    "vehicle/ai_monitor/trajectory_manager/node"
)

EXCLUDE_PATHS=(
    ".*/mocks/.*"
    ".*/test/.*"
)

echo "Executing code coverage on Cinder ..."

# For more details, please visit: https://confluence.zooxlabs.com/display/SOFT/6.2+Code+Coverage
cd "$ZOOX_WORKSPACE_ROOT" && \
    ci/cinder/secrets_/run.sh bazel run //ci/cinder:schedule -- \
                              --scheduler pipedream Coverage \
                              --bazel-targets "${TEST_TARGETS[*]}" \
                              --include-paths "${INCLUDE_PATHS[*]}" \
                              --exclude-paths "${EXCLUDE_PATHS[*]}"

[ $? -eq 0 ] && echo "... done!"
