Skip to content

Commit

Permalink
- added ctest support plus few tests for #7 #8
Browse files Browse the repository at this point in the history
  tests are always included in build, but runs on demand only
  cmake --build <build_dir> --target ReDefine.Test
- added mingw support, for internal use
  uses c++17 due to missing std::experimental::filesystem
  • Loading branch information
wipe2238 committed Apr 13, 2020
1 parent ed448ab commit 3ab3389
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto eol=lf

*.bat text eol=crlf
*.cmd text eol=crlf
4 changes: 4 additions & 0 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ jobs:
cp ${{ matrix.cfg.redefine }} ReDefine
shell: bash

- name: Test
run: cmake --build Build --target ReDefine.Test
shell: bash

- name: Artifact
if: matrix.cfg.artifact != 'none'
uses: actions/upload-artifact@v1
Expand Down
9 changes: 7 additions & 2 deletions Build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,13 @@ elseif( UNIX )
set( BUILD_GENERATOR "Unix Makefiles" )
# set( BUILD_TOOL "Linux32" )
elseif( WIN32 )
set( BUILD_FILE "ReDefine.sln" )
set( BUILD_GENERATOR "Visual Studio 15 2017" )
if( MINGW )
set( BUILD_FILE "Makefile" )
set( BUILD_GENERATOR "MinGW Makefiles" )
else()
set( BUILD_FILE "ReDefine.sln" )
set( BUILD_GENERATOR "Visual Studio 15 2017" )
endif()
endif()

FormatSource( "Source/Defines.cpp" )
Expand Down
9 changes: 8 additions & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
cmake_minimum_required( VERSION 3.7.2 FATAL_ERROR ) # cannot go higher due to nuremberg setup

set( CMAKE_CONFIGURATION_TYPES "Release" )
set( CMAKE_CXX_STANDARD 14 )
set( CMAKE_CXX_STANDARD_REQUIRED YES )
set( CMAKE_SKIP_INSTALL_RULES TRUE )

if( "${CMAKE_GENERATOR}" STREQUAL "MinGW Makefiles" )
set( CMAKE_CXX_STANDARD 17 )
else()
set( CMAKE_CXX_STANDARD 14 )
endif()

project( ReDefine LANGUAGES CXX )

if( DEFINED ENV{CLANG_TIDY} )
Expand Down Expand Up @@ -173,6 +178,8 @@ endfunction()

StdFilesystem( ReDefine )

add_subdirectory( Test )

# Prettify IDE

set_property( GLOBAL PROPERTY USE_FOLDERS ON )
Expand Down
2 changes: 1 addition & 1 deletion Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void Usage( ReDefine* redefine )
redefine->SHOW( " --help Short summary of available options" );
redefine->SHOW( " --config [filename] Changes location of configuration file (default: ReDefine.cfg)" );
redefine->SHOW( " --headers [directory] Changes location of scripts headers directory (default: current directory)" );
redefine->SHOW( " --scripts[directory] Changes location of scripts directory (default: current directory)" );
redefine->SHOW( " --scripts [directory] Changes location of scripts directory (default: current directory)" );
redefine->SHOW( " --log-file [filename] Changes location of general logfile (default: %s)", redefine->LogFile.c_str() );
redefine->SHOW( " --log-warning [filename] Changes location of warnings logfile (default: %s)", redefine->LogWarning.c_str() );
redefine->SHOW( " --log-debug [filename] Changes location of debug logfile (default: %s)", redefine->LogDebug.c_str() );
Expand Down
23 changes: 23 additions & 0 deletions Source/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required( VERSION 3.14 FATAL_ERROR )

file( GLOB_RECURSE found_tests LIST_DIRECTORIES false RELATIVE "${CMAKE_CURRENT_LIST_DIR}" CONFIGURE_DEPENDS "*.test" )

enable_testing()
foreach( file IN LISTS found_tests )
get_filename_component( name_dir "${file}" DIRECTORY )
get_filename_component( name_wle "${file}" NAME_WLE )
set( name "${name_dir}/${name_wle}" )
# string( REGEX REPLACE "/ReDefine\\.test$" "" name "${file}" )
message( STATUS "Add test... ${name}" )
add_test( NAME ${name}
COMMAND ${CMAKE_COMMAND} -DREDEFINE=$<TARGET_FILE:ReDefine> -DTEST_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${file} -P ${CMAKE_CURRENT_SOURCE_DIR}/Run.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

endforeach()

add_custom_target( ReDefine.Test
DEPENDS ReDefine ${found_tests}
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
19 changes: 19 additions & 0 deletions Source/Test/Issue/8/ReDefine.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[ReDefine]
HeadersDir = .
ScriptsDir = .

[Defines]
DUMMY = ReDefine.cfg DUMMY

[Defines:ITEM_PID]
252 = PID_ANNA_GOLD_LOCKET

[Function]
obj_is_carrying_obj_pid = ? ITEM_PID

[Script:Minimize:ObjCarrying]
GetItem = RunAfter:90 IfFunction:obj_carrying_pid_obj DoNameSet:get_item
GetItemCount = RunAfter:90 IfFunction:obj_is_carrying_obj_pid DoNameSet:get_item_count
#
SelfItem = RunAfter:90 IfFunction:get_item IfArgumentValue:0,self_obj DoNameSet:self_item DoArgumentsErase:0
SelfItemCount = RunAfter:90 IfFunction:get_item_count IfArgumentValue:0,self_obj DoNameSet:self_item_count DoArgumentsErase:0
3 changes: 3 additions & 0 deletions Source/Test/Issue/8/ReDefine.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-
debug_msg("dcanna" + ": " + " obj_is_carrying_obj_pid(self_obj, PID_ANNA_GOLD_LOCKET) == " + obj_is_carrying_obj_pid(self_obj, 252) + "\n");
debug_msg("dcanna" + ": " + " obj_is_carrying_obj_pid(self_obj, PID_ANNA_GOLD_LOCKET) == " + self_item_count( PID_ANNA_GOLD_LOCKET ) + "\n");
56 changes: 56 additions & 0 deletions Source/Test/Run.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
set( PWD "${CMAKE_CURRENT_BINARY_DIR}" )

if( NOT REDEFINE )
message( FATAL_ERROR "REDEFINE not set" )
elseif( NOT TEST_FILE )
message( FATAL_ERROR "TEST_FILE not set" )
endif()

get_filename_component( TEST_DIR "${TEST_FILE}" DIRECTORY )
set( REDEFINE_CFG "${TEST_DIR}/ReDefine.cfg" )

#message( STATUS "TEST_DIR = ${TEST_DIR}" )
#message( STATUS "TEST_FILE = ${TEST_FILE}" )

file( STRINGS "${TEST_FILE}" lines )
#foreach( line IN LISTS lines )
# message( STATUS "${line}" )
#endforeach()

list( GET lines 0 script )
list( GET lines 1 origin )
list( GET lines 2 expect )

#message( STATUS "SCRIPT=${script} ORIGIN=${origin} EXPECT=${expect}" )

file( REMOVE_RECURSE "Run" )
file( MAKE_DIRECTORY "Run" )

if( EXISTS "${REDEFINE_CFG}" )
file( COPY "${REDEFINE_CFG}" DESTINATION "Run" )
endif()

if( NOT "${script}" STREQUAL "-" )
file( APPEND "Run/ReDefine.cfg" "\n" )
file( APPEND "Run/ReDefine.cfg" "[Script:Test]\n" )
file( APPEND "Run/ReDefine.cfg" "Run = ${script}\n" )
endif()

file( WRITE "Run/ReDefine.ssl" "${origin}" )

execute_process(
COMMAND ${REDEFINE} --debug-changes 1
WORKING_DIRECTORY ${PWD}/Run
)

file( STRINGS "Run/ReDefine.ssl" lines )
list( GET lines 0 result )

if( NOT "${expect}" STREQUAL "${result}" )
message( "" )
message( STATUS "EXPECT ${expect}" )
message( STATUS "RESULT ${result}" )
message( "" )
message( FATAL_ERROR "TEST FAILED" )
endif()
file( REMOVE_RECURSE "Run" )
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RunAfter IfFunction DoArgumentsErase:0
f(a, b);
f(b);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RunAfter IfFunction DoArgumentsErase:0
f(a, b, c);
f(b, c);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RunAfter IfFunction DoArgumentsErase:1
f(a, b, c);
f(a, c);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ReDefine]
HeadersDir = .
ScriptsDir = .

FormatFunctions = 0

[Defines]
DUMMY = ReDefine.cfg DUMMY
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RunAfter IfFunction DoArgumentsMoveBack:0
f(a, b, c);
f(b, c, a);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RunAfter IfFunction DoArgumentsMoveBack:1
f(a, b, c);
f(a, c, b);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ReDefine]
HeadersDir = .
ScriptsDir = .

FormatFunctions = 0

[Defines]
DUMMY = ReDefine.cfg DUMMY
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RunAfter IfFunction DoArgumentsMoveFront:1
f(a, b);
f(b, a);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RunAfter IfFunction DoArgumentsMoveFront:1
f(a, b, c);
f(b, a, c);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RunAfter IfFunction DoArgumentsMoveFront:2
f(a, b, c);
f(c, a, b);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ReDefine]
HeadersDir = .
ScriptsDir = .

FormatFunctions = 0

[Defines]
DUMMY = ReDefine.cfg DUMMY

0 comments on commit 3ab3389

Please sign in to comment.