#!/bin/zsh
set -eu
cd "${0:A:h:h}"
if [[ -z "${DEVELOPER_DIR:-}" ]]; then
  if [[ -d /Applications/Xcode-beta.app/Contents/Developer ]]; then
    export DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer
  else
    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
  fi
fi
simulator_id="${RIDEFORM_WATCH_SIMULATOR_ID:-98D915DA-1045-4968-834B-9FA4CFD62A5A}"
if [[ $# -gt 0 && "$1" != -* ]]; then
  simulator_id="$1"
  shift
fi
exec xcodebuild -project RideForm.xcodeproj -scheme RideFormWatch \
  -destination "platform=watchOS Simulator,id=$simulator_id" \
  -derivedDataPath "${RIDEFORM_WATCH_BUILD:-/tmp/rideform-watch-build}" \
  -parallel-testing-enabled NO test "$@"
