cmake_minimum_required(VERSION 3.1)

set(CTEST_SITE                          "test-site")
set(CTEST_BUILD_NAME                    "test-build-name")
set(CTEST_SOURCE_DIRECTORY              "@RunCMake_BINARY_DIR@/@CASE_NAME@")
set(CTEST_BINARY_DIRECTORY              "@RunCMake_BINARY_DIR@/@CASE_NAME@-build")
set(CTEST_CMAKE_GENERATOR               "@RunCMake_GENERATOR@")
set(CTEST_CMAKE_GENERATOR_PLATFORM      "@RunCMake_GENERATOR_PLATFORM@")
set(CTEST_CMAKE_GENERATOR_TOOLSET       "@RunCMake_GENERATOR_TOOLSET@")
set(CTEST_BUILD_CONFIGURATION           "$ENV{CMAKE_CONFIG_TYPE}")
if(NOT "@CASE_NAME@" MATCHES "^NoStartTime")
  set(CTEST_NIGHTLY_START_TIME            "01:00:00 UTC")
endif()

function(setup_tests)
  ctest_start(${ctest_start_args})
endfunction()

if("@CASE_NAME@" MATCHES "^(No)?Append")
  if("@CASE_NAME@" MATCHES "^AppendNoMatchingTrack$")
    file(WRITE "${CTEST_BINARY_DIRECTORY}/Testing/TAG" "19551112-2204\nSomeWeirdTrackName\n")
  else()
    file(WRITE "${CTEST_BINARY_DIRECTORY}/Testing/TAG" "19551112-2204\nContinuousTrack\n")
  endif()
  if(NOT "@CASE_NAME@" MATCHES "^AppendOld")
    file(APPEND "${CTEST_BINARY_DIRECTORY}/Testing/TAG" "Continuous\n")
  endif()
endif()

set(ctest_start_args "@CASE_CTEST_START_ARGS@")
if("@CASE_NAME@" STREQUAL "FunctionScope")
  setup_tests()
else()
  ctest_start(${ctest_start_args})
endif()
