#!/usr/bin/env Rscript

suppressPackageStartupMessages(library(testthat))

arguments <- commandArgs(trailingOnly = FALSE)
script_flag <- grep("^--file=", arguments, value = TRUE)
tests_directory <- if (length(script_flag) == 1L) {
  dirname(normalizePath(sub("^--file=", "", script_flag)))
} else {
  normalizePath(getwd())
}
app_directory <- normalizePath(file.path(tests_directory, ".."))
setwd(app_directory)
Sys.setenv(CASCADE_APP_DIR = app_directory)

test_dir(file.path(app_directory, "tests", "testthat"), reporter = "summary")
