diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a2237bc --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +* text=auto eol=lf + +*.bat text eol=crlf +*.cmd text eol=crlf diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 187ea61..992bb34 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -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 diff --git a/Build.cmake b/Build.cmake index 99cb6d0..e956a7b 100644 --- a/Build.cmake +++ b/Build.cmake @@ -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" ) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index b061f77..8326aa6 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -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} ) @@ -173,6 +178,8 @@ endfunction() StdFilesystem( ReDefine ) +add_subdirectory( Test ) + # Prettify IDE set_property( GLOBAL PROPERTY USE_FOLDERS ON ) diff --git a/Source/Main.cpp b/Source/Main.cpp index 9996da3..e90b882 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -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() ); diff --git a/Source/Test/CMakeLists.txt b/Source/Test/CMakeLists.txt new file mode 100644 index 0000000..c99989d --- /dev/null +++ b/Source/Test/CMakeLists.txt @@ -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=$ -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} +) diff --git a/Source/Test/Issue/8/ReDefine.cfg b/Source/Test/Issue/8/ReDefine.cfg new file mode 100644 index 0000000..daeb03b --- /dev/null +++ b/Source/Test/Issue/8/ReDefine.cfg @@ -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 diff --git a/Source/Test/Issue/8/ReDefine.test b/Source/Test/Issue/8/ReDefine.test new file mode 100644 index 0000000..972f97c --- /dev/null +++ b/Source/Test/Issue/8/ReDefine.test @@ -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"); diff --git a/Source/Test/Run.cmake b/Source/Test/Run.cmake new file mode 100644 index 0000000..1394666 --- /dev/null +++ b/Source/Test/Run.cmake @@ -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" ) diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/2Arguments.test b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/2Arguments.test new file mode 100644 index 0000000..7306713 --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/2Arguments.test @@ -0,0 +1,3 @@ +RunAfter IfFunction DoArgumentsErase:0 +f(a, b); +f(b); diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/3Arguments.0.test b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/3Arguments.0.test new file mode 100644 index 0000000..a563326 --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/3Arguments.0.test @@ -0,0 +1,3 @@ +RunAfter IfFunction DoArgumentsErase:0 +f(a, b, c); +f(b, c); diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/3Arguments.1.test b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/3Arguments.1.test new file mode 100644 index 0000000..33d083e --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/3Arguments.1.test @@ -0,0 +1,3 @@ +RunAfter IfFunction DoArgumentsErase:1 +f(a, b, c); +f(a, c); diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/ReDefine.cfg b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/ReDefine.cfg new file mode 100644 index 0000000..8d12485 --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsErase/ReDefine.cfg @@ -0,0 +1,8 @@ +[ReDefine] +HeadersDir = . +ScriptsDir = . + +FormatFunctions = 0 + +[Defines] +DUMMY = ReDefine.cfg DUMMY diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveBack/3Arguments.0.test b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveBack/3Arguments.0.test new file mode 100644 index 0000000..72ee8c0 --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveBack/3Arguments.0.test @@ -0,0 +1,3 @@ +RunAfter IfFunction DoArgumentsMoveBack:0 +f(a, b, c); +f(b, c, a); diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveBack/3Arguments.1.test b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveBack/3Arguments.1.test new file mode 100644 index 0000000..e08d908 --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveBack/3Arguments.1.test @@ -0,0 +1,3 @@ +RunAfter IfFunction DoArgumentsMoveBack:1 +f(a, b, c); +f(a, c, b); diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveBack/ReDefine.cfg b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveBack/ReDefine.cfg new file mode 100644 index 0000000..8d12485 --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveBack/ReDefine.cfg @@ -0,0 +1,8 @@ +[ReDefine] +HeadersDir = . +ScriptsDir = . + +FormatFunctions = 0 + +[Defines] +DUMMY = ReDefine.cfg DUMMY diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/2Arguments.test b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/2Arguments.test new file mode 100644 index 0000000..6f51e78 --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/2Arguments.test @@ -0,0 +1,3 @@ +RunAfter IfFunction DoArgumentsMoveFront:1 +f(a, b); +f(b, a); diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/3Arguments.1.test b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/3Arguments.1.test new file mode 100644 index 0000000..68824ee --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/3Arguments.1.test @@ -0,0 +1,3 @@ +RunAfter IfFunction DoArgumentsMoveFront:1 +f(a, b, c); +f(b, a, c); diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/3Arguments.2.test b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/3Arguments.2.test new file mode 100644 index 0000000..0c9c166 --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/3Arguments.2.test @@ -0,0 +1,3 @@ +RunAfter IfFunction DoArgumentsMoveFront:2 +f(a, b, c); +f(c, a, b); diff --git a/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/ReDefine.cfg b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/ReDefine.cfg new file mode 100644 index 0000000..8d12485 --- /dev/null +++ b/Source/Test/SCRIPT_FORMAT_UNCHANGED/DoArgumentsMoveFront/ReDefine.cfg @@ -0,0 +1,8 @@ +[ReDefine] +HeadersDir = . +ScriptsDir = . + +FormatFunctions = 0 + +[Defines] +DUMMY = ReDefine.cfg DUMMY