function cmd::test::run_cmd() {
  local desc="$1" expected="${2:-}"
  shift 2

  local tmp exit_code
  tmp=$(mktemp)

  set +e
  timeout 30 "$WGCTL_BINARY" "$@" > "$tmp" 2>&1
  exit_code=$?
  set -e

  # Reset terminal color in case command output left ANSI state dirty
  printf "\033[0m" >&2

  if [[ $exit_code -eq 124 ]]; then
    test::warn "${desc} (timed out after 30s)"
    rm -f "$tmp"
    return 1
  fi

  local clean
  clean=$(cmd::test::_strip_ansi < "$tmp")

  if [[ $exit_code -ne 0 ]]; then
    local msg="${desc}"
    [[ -n "$expected" ]] && msg="${desc} (expected '${expected}', command failed)"
    test::fail "$msg"
    if [[ "${WGCTL_TEST_VERBOSE:-false}" == "true" ]]; then
      printf "    Output: %s\n" "$(echo "$clean" | head -3 | tr '\n' ' ')"
    fi
    rm -f "$tmp"
    return 1
  fi

  if [[ -n "$expected" ]] && ! echo "$clean" | grep -qF "$expected"; then
    local actual
    actual=$(echo "$clean" | head -3 | tr '\n' ' ' | sed 's/  */ /g' | cut -c1-100)
    test::fail "${desc} (expected '${expected}', got: '${actual}')"
    rm -f "$tmp"
    return 1
  fi

  test::pass "$desc"
  rm -f "$tmp"
}