#*******************************************************************************
#**  This file is part of Pecunia.                                           ***
#**                                                                          ***
#**  Copyright (C) 2017, 2018, 2019, 2020, 2021, 2023, 2024, 2025            ***
#**  John Schneiderman <Licencing _AT_ Schneiderman _DOT_ me>                ***
#**                                                                          ***
#**  This program is free software: you can redistribute it and/or modify it ***
#**  under the terms of the GNU Lesser General Public License as published   ***
#**  by the Free Software Foundation, either version 3 of the License, or    ***
#**  (at your option) any later version.                                     ***
#**                                                                          ***
#**  This program is distributed in the hope that it will be useful, but     ***
#**  WITHOUT ANY WARRANTY; without even the implied warranty of              ***
#**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    ***
#**  See the GNU Lesser General Public License for more details.             ***
#**                                                                          ***
#**  You should have received a copy of the GNU Lesser General Public License***
#**  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
#*******************************************************************************
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(pecunia-unit-tests)

find_package(Catch2 3 REQUIRED)
include(Catch)

macro(setUpTest testName)
	set(Test_Project_Name "${testName}-tests")
	set(Test_File_Name "${testName}-unit-tests")

	add_executable(${Test_Project_Name}
		${Test_File_Name}.cpp
		ExchangeRates.hpp
		ExchangeRates.cpp
	)
	# Adds the includes for the auto-generated files.
	target_include_directories(${Test_Project_Name}
		PRIVATE
			$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/.. # Allows for testing internal code.
			$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>/..
			$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>/../external
			$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>/../external/pecunia
	)
	target_link_libraries(${Test_Project_Name} PRIVATE pecunia)
	target_link_libraries(${Test_Project_Name} PRIVATE Catch2::Catch2WithMain)

	if (WIN32)
		add_test(
			NAME ${Test_Project_Name}
			COMMAND "${testName}-tests"
			WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
		)
	else ()
		catch_discover_tests(${Test_Project_Name}
			COMMAND "${testName}-tests"
			WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
		)
	endif ()
	configure_file(
		"${CMAKE_SOURCE_DIR}/src/project.vcxproj.user.in"
		${PROJECT_BINARY_DIR}/${Test_Project_Name}.vcxproj.user @ONLY
	)

	unset(Test_Project_Name)
	unset(Test_File_Name)
endmacro()

setUpTest(algorithm)
setUpTest(codes)
setUpTest(conversion)
setUpTest(Errors)
setUpTest(Expected)
setUpTest(FloatingPoint)
setUpTest(Information)
setUpTest(math)
setUpTest(Minor)
setUpTest(money)
setUpTest(MoneyParts)
setUpTest(rounders-currency)
setUpTest(rounders-floating-point)
setUpTest(Splitter)

# Internal library code cannot be tested on Windows.
if (NOT WIN32)
	setUpTest(Adjustments)
	setUpTest(SetUp)
	setUpTest(TraceCapture)
	setUpTest(verification)
endif ()
