#Test no log message:
# add_definitions(-DCAMITK_DISABLE_LOG)
camitk_application(NO_GUI)

#----------
# Testing
#----------
camitk_init_test(${APPLICATION_TARGET_NAME})
# should pass because testlogger run with no arguments shows usage and exit success
camitk_add_test(PROJECT_NAME ${APPLICATION_TARGET_NAME} 
                TEST_SUFFIX "-"
)

# should pass because invoking testlogger with wrong number of argument should show usage and exit success
camitk_add_test(EXECUTABLE_ARGS "-onlyOneArg" 
                PROJECT_NAME ${APPLICATION_TARGET_NAME}
                TEST_SUFFIX "-"
)

# should pass because invoking testlogger with a faulty arguments results in printing
# an "Argument error" message (and exit failure)
camitk_add_test(EXECUTABLE_ARGS "-error /test" 
                PASS_REGULAR_EXPRESSION "Argument errors: "
                PROJECT_NAME ${APPLICATION_TARGET_NAME}
                TEST_SUFFIX "-"
)

# should pass because invoking testlogger with an inexistent and impossible to create directory 
# results in printing an "Argument error" message (and exit failure)
if(WIN32) # this test fails on windows7 VM due to missing tweek for -debug
    set(BAD_DIRECTORY "C:/NUL/test")
else()
    set(BAD_DIRECTORY "/dev/null/test") # fails systematically on VM, docker and host 
endif()
camitk_add_test(EXECUTABLE_ARGS "-d ${BAD_DIRECTORY}" 
                PASS_REGULAR_EXPRESSION "Argument errors: "
                PROJECT_NAME ${APPLICATION_TARGET_NAME} TEST_SUFFIX "-")

# Last test should have the same output as log-default.log
camitk_add_test(EXECUTABLE_ARGS "-d ${CMAKE_CURRENT_BINARY_DIR}/testlogger"
                PASS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/log-default.log 
                PROJECT_NAME ${APPLICATION_TARGET_NAME} 
                TEST_SUFFIX "-"
)

camitk_tests_requirement(TESTS application-testloggercrash-5
                         REQUIRES "NOT WIN32"
                         REASON "On Windows with MSVC inside a CI container in Release mode, abort() may crash the application with the system not flushing the output buffer"
)
