#!/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
  elif [[ -d /Applications/Xcode.app/Contents/Developer ]]; then
    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
  fi
fi
simulator_id="${RIDEFORM_SIMULATOR_ID:-2315A3BD-AC4F-46A2-89E3-2C96AD7B1A37}"
if [[ $# -gt 0 && "$1" != -* ]]; then
  simulator_id="$1"
  shift
fi
exec xcodebuild -project RideForm.xcodeproj -scheme RideForm \
  -destination "platform=iOS Simulator,id=$simulator_id" \
  -derivedDataPath "${RIDEFORM_IOS_BUILD:-/tmp/rideform-ios-tests}" test "$@"
