Skip to content

Commit

Permalink
Additional folders for refactoring (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille authored Sep 4, 2024
1 parent d910c2c commit 9fa2969
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 12 deletions.
29 changes: 23 additions & 6 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
fail-fast: false
matrix:
sys:
- {compiler: clang, version: '16', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON' }
- {compiler: clang, version: '16', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON', build_refactoring: 'ON' }
# - {compiler: clang, version: '16', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17', date-polyfill: 'ON' }
- {compiler: clang, version: '17', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON' }
- {compiler: clang, version: '17', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON', build_refactoring: 'OFF' }
# - {compiler: clang, version: '17', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17', date-polyfill: 'ON' }

- {compiler: gcc, version: '12', config-flags: '', date-polyfill: 'ON' }
- {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'ON' }
- {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'OFF' }
- {compiler: gcc, version: '12', config-flags: '', date-polyfill: 'ON', build_refactoring: 'OFF' }
- {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'ON', build_refactoring: 'OFF' }
- {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'OFF', build_refactoring: 'ON' }

config:
- { name: Debug }
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
cache-downloads: true

- name: Configure using CMake
run: cmake -G Ninja -Bbuild ${{matrix.sys.config-flags}} -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON
run: cmake -G Ninja -Bbuild ${{matrix.sys.config-flags}} -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_REFACTORING=${{matrix.sys.build_refactoring}}

- name: Install
working-directory: build
Expand All @@ -84,6 +84,23 @@ jobs:
name: test_sparrow_lib_report_Linux_${{ matrix.sys.compiler }}_${{ matrix.sys.version }}_${{ matrix.sys.stdlib }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}}
path: '**/test_sparrow_lib_report.xml'

- name: Build refactoring
if: matrix.sys.build_refactoring == 'ON'
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target test_sparrow_lib_v01 --parallel 8

- name: Run refactoring tests
if: matrix.sys.build_refactoring == 'ON'
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target run_tests_with_junit_report_v01

- name: Upload refactoring test results
uses: actions/upload-artifact@v4
if: matrix.sys.build_refactoring == 'ON' && (success() || failure())
with:
name: test_sparrow_lib_report_Linux_v01_${{ matrix.sys.compiler }}_${{ matrix.sys.version }}_${{ matrix.sys.stdlib }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}}
path: '**/test_sparrow_lib_report_v01.xml'

- name: Run all examples
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target run_examples
17 changes: 16 additions & 1 deletion .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
echo "CMAKE_CXX_COMPILER=/usr/bin/clang++" >> $GITHUB_ENV
- name: Configure using CMake
run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON
run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_REFACTORING=ON

- name: Install
working-directory: build
Expand All @@ -78,6 +78,21 @@ jobs:
with:
name: test_sparrow_lib_report_OSX_${{ matrix.os }}_${{ matrix.config.name }}_${{ matrix.compiler }}
path: '**/test_sparrow_lib_report.xml'

- name: Build refactoring
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target test_sparrow_lib_v01 --parallel 8

- name: Run refactoring tests
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target run_tests_with_junit_report_v01

- name: Upload refactoring test results
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test_sparrow_lib_report_OSX_v01_${{ matrix.os }}_${{ matrix.config.name }}_${{ matrix.compiler }}
path: '**/test_sparrow_lib_report_v01.xml'

- name: Run all examples
working-directory: build
Expand Down
27 changes: 22 additions & 5 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
matrix:
runs-on: [windows-latest]
sys:
- { compiler: msvc, date-polyfill: 'ON' }
- { compiler: msvc, date-polyfill: 'OFF' }
- { compiler: clang, date-polyfill: 'ON', version: 17 }
- { compiler: clang, date-polyfill: 'OFF', version: 17 }
- { compiler: msvc, date-polyfill: 'ON', build_refactoring: 'OFF' }
- { compiler: msvc, date-polyfill: 'OFF', build_refactoring: 'ON' }
- { compiler: clang, date-polyfill: 'ON', version: 17, build_refactoring: 'OFF'}
- { compiler: clang, date-polyfill: 'OFF', version: 17, build_refactoring: 'ON' }
config:
- { name: Debug }
- { name: Release }
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
ninja
- name: Configure using CMake
run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -G "${{matrix.build-system}}"
run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -DBUILD_REFACTORING=${{matrix.sys.build_refactoring}} -G "${{matrix.build-system}}"

- name: Install
working-directory: build
Expand All @@ -84,6 +84,23 @@ jobs:
name: test_sparrow_lib_report_Windows_${{ matrix.sys.compiler }}_${{ matrix.build-system }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}}
path: '**/test_sparrow_lib_report.xml'

- name: Build refactoring
if: matrix.sys.build_refactoring == 'ON'
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target test_sparrow_lib_v01 --parallel 8

- name: Run refactoring tests
if: matrix.sys.build_refactoring == 'ON'
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target run_tests_with_junit_report_v01

- name: Upload refactoring test results
uses: actions/upload-artifact@v4
if: matrix.sys.build_refactoring == 'ON' && (success() || failure())
with:
name: test_sparrow_lib_report_Windows_v01_${{ matrix.sys.compiler }}_${{ matrix.build-system }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}}
path: '**/test_sparrow_lib_report_v01.xml'

- name: Run all examples
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target run_examples
Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ OPTION(BUILD_TESTS "Build sparrow test suite" OFF)
OPTION(BUILD_DOCS "Build sparrow documentation" OFF)
OPTION(BUILD_EXAMPLES "Build sparrow examples" OFF)
OPTION(USE_DATE_POLYFILL "Use date polyfill implementation" ON)
OPTION(BUILD_REFACTORING "Build the refactoring target" OFF)

include(CheckCXXSymbolExists)

Expand Down Expand Up @@ -138,6 +139,13 @@ set(SPARROW_HEADERS
${SPARROW_INCLUDE_DIR}/sparrow/details/3rdparty/float16_t.hpp
)

if (BUILD_REFACTORING)
set(SPARROW_V01_HEADERS
${SPARROW_INCLUDE_DIR}/sparrow_v01/utils/memory.hpp
)
list(APPEND SPARROW_HEADERS ${SPARROW_V01_HEADERS})
endif ()

add_library(sparrow INTERFACE ${SPARROW_HEADERS})

target_include_directories(sparrow INTERFACE
Expand All @@ -153,6 +161,9 @@ target_compile_features(sparrow INTERFACE cxx_std_20)
if (BUILD_TESTS)
enable_testing()
add_subdirectory(test)
if (BUILD_REFACTORING)
add_subdirectory(test_v01)
endif ()
endif ()

# Docs
Expand Down Expand Up @@ -186,6 +197,10 @@ install(DIRECTORY ${SPARROW_INCLUDE_DIR}/sparrow
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN ".clang-*" EXCLUDE
PATTERN "README.md" EXCLUDE)
if (BUILD_REFACTORING)
install(DIRECTORY ${SPARROW_INCLUDE_DIR}/sparrow_v01
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif ()

set(SPARROW_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE
STRING "install path for sparrowConfig.cmake")
Expand Down
23 changes: 23 additions & 0 deletions include/sparrow_v01/utils/memory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 Man Group Operations Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or mplied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

namespace sparrow
{
inline int dummy()
{
return 0;
}
}
143 changes: 143 additions & 0 deletions test_v01/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Copyright 2024 Man Group Operations Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.8)

enable_testing()

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
project(sparrow-test CXX)
find_package(sparrow REQUIRED CONFIG)
set(SPARROW_INCLUDE_DIR ${sparrow_INCLUDE_DIRS})
endif()

find_package(doctest REQUIRED)

# find_package(Threads)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting tests build type to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
else()
message(STATUS "Tests build type is ${CMAKE_BUILD_TYPE}")
endif()

set(SPARROW_V1_TESTS_SOURCES
../test/main.cpp
../test/better_junit_reporter.hpp
../test/junit.hpp
../test/junit.cpp
../test/junit_xml_writer.hpp
test_memory.cpp
)
set(test_target_v01 "test_sparrow_lib_v01")
add_executable(${test_target_v01} ${SPARROW_V1_TESTS_SOURCES})
target_link_libraries(${test_target_v01}
PRIVATE
sparrow doctest::doctest $<$<BOOL:USE_SANITIZER>:${SANITIZER_LINK_LIBRARIES}>)

include(doctest)
doctest_discover_tests(${test_target_v01})

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(compiles_options
/permissive-
/WX # treat warnings as errors
/W4 # Baseline reasonable warnings
/we4242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
/we4244 # conversion from 'type1' to 'type_2', possible loss of data
/we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
/we4263 # 'function': member function does not override any base class virtual member function
/we4265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not be destructed correctly
/we4287 # 'operator': unsigned/negative constant mismatch
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside the for-loop scope
/we4296 # 'operator': expression is always 'boolean_value'
/we4311 # 'variable': pointer truncation from 'type1' to 'type2'
/we4545 # expression before comma evaluates to a function which is missing an argument list
/we4546 # function call before comma missing argument list
/we4547 # 'operator': operator before comma has no effect; expected operator with side-effect
/we4549 # 'operator': operator before comma has no effect; did you intend 'operator'?
/we4555 # expression has no effect; expected expression with side- effect
/we4619 # pragma warning: there is no warning number 'number'
/we4640 # Enable warning on thread un-safe static member initialization
/we4826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior.
/we4905 # wide string literal cast to 'LPSTR'
/we4906 # string literal cast to 'LPWSTR'
/we4928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
/we5038 # data member 'member1' will be initialized after data member 'member2'
/Zc:__cplusplus)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(compiles_options
-pedantic # Warn on language extensions
-Wall # reasonable and standard
-Wcast-align # warn for potential performance problem casts
-Wconversion # warn on type conversions that may lose data
-Wdouble-promotion # warn if float is implicitly promoted to double
-Werror # treat warnings as errors
-Wextra
-Wformat=2 # warn on security issues around functions that format output (i.e., printf)
-Wimplicit-fallthrough # Warns when case statements fall-through. (Included with -Wextra in GCC, not in clang)
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors
-Wnull-dereference # warn if a null dereference is detected
-Wold-style-cast # warn for c-style casts
-Woverloaded-virtual # warn if you overload (not override) a virtual function
-Wpedantic # warn if non-standard C++ is used
-Wshadow # warn the user if a variable declaration shadows one from a parent context
-Wsign-conversion # warn on sign conversions
-Wunused # warn on anything being unused
$<$<CXX_COMPILER_ID:GNU>:-Wno-maybe-uninitialized>
$<$<CXX_COMPILER_ID:GNU>:-Wno-array-bounds>
$<$<CXX_COMPILER_ID:GNU>:-Wno-stringop-overread>
$<$<CXX_COMPILER_ID:GNU>:-Wduplicated-branches> # warn if if / else branches have duplicated code
$<$<CXX_COMPILER_ID:GNU>:-Wduplicated-cond> # warn if if / else chain has duplicated conditions
$<$<CXX_COMPILER_ID:GNU>:-Wlogical-op> # warn about logical operations being used where bitwise were probably wanted
$<$<CXX_COMPILER_ID:GNU>:-Wno-subobject-linkage> # suppress warnings about subobject linkage
$<$<CXX_COMPILER_ID:GNU>:-Wuseless-cast> # warn if you perform a cast to the same type
)
target_compile_options(${test_target_v01} PRIVATE "-ftemplate-backtrace-limit=0")
endif()

target_compile_options(${test_target_v01}
PRIVATE
${compiles_options}
$<$<BOOL:USE_SANITIZER>:${SANITIZER_COMPILE_OPTIONS}>
)
target_link_options(${test_target_v01}
PRIVATE
$<$<BOOL:USE_SANITIZER>:${SANITIZER_LINK_OPTIONS}>)
# We do not use non-standard C++
set_target_properties(${test_target_v01} PROPERTIES CMAKE_CXX_EXTENSIONS OFF)
target_compile_features(${test_target_v01} PRIVATE cxx_std_20)

add_custom_target(run_tests_v01
COMMAND ${test_target_v01}
DEPENDS ${test_target_v01}
COMMENT "Running tests"
USES_TERMINAL
)

set_target_properties(run_tests_v01 PROPERTIES FOLDER "Tests utilities")

set(JUNIT_REPORT_FILE_V1
${CMAKE_CURRENT_BINARY_DIR}/test_sparrow_lib_report_v01.xml)

add_custom_target(run_tests_with_junit_report_v01
COMMAND ${test_target_v01} --reporters=better_junit
--out=${JUNIT_REPORT_FILE_V1} --no-path-filenames=true
DEPENDS ${test_target_v01}
COMMENT "Running tests with JUnit report saved to: ${JUNIT_REPORT_FILE_V1}"
USES_TERMINAL
)

set_target_properties(run_tests_with_junit_report_v01 PROPERTIES FOLDER "Tests utilities")
25 changes: 25 additions & 0 deletions test_v01/test_memory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024 Man Group Operations Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "sparrow_v01/utils/memory.hpp"

#include "doctest/doctest.h"

TEST_SUITE("memory_v01")
{
TEST_CASE("dummy")
{
CHECK_EQ(sparrow::dummy(), 0);
}
}

0 comments on commit 9fa2969

Please sign in to comment.