diff --git a/.clang-format b/.clang-format index 906e38a..19a9d20 100644 --- a/.clang-format +++ b/.clang-format @@ -40,7 +40,7 @@ NamespaceIndentation: All PenaltyBreakComment: 20 PenaltyExcessCharacter: 5 PointerAlignment: Middle -SortUsingDeclarations: false +SortUsingDeclarations: true SpaceAfterTemplateKeyword: false SpaceBeforeCpp11BracedList: true SpacesBeforeTrailingComments: 1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 988ab3f..3ac36c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,7 @@ on: - synchronize jobs: + # Tests disabled because ci doesn't have opengl, need to find a fix for that # test: # runs-on: ubuntu-latest @@ -25,18 +26,18 @@ jobs: # run: pip install gcovr # - name: Setup project - # run: cmake -S ${TEST_DIR} -B ${BUILD_DIR} -DCMAKE_BUILD_TYPE=Debug + # run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug # - name: Build - # run: cmake --build ${BUILD_DIR} + # run: cmake --build build - # # - name: Test - # # working-directory: build - # # run: ctest -V - - # - name: Test with Coverage + # - name: Test # working-directory: build - # run: cmake --build ${BUILD_DIR} --target os_test_coverage + # run: ctest -V + + # # - name: Test with Coverage + # # working-directory: build + # # run: cmake --build ${BUILD_DIR} --target os_test_coverage lint: runs-on: ubuntu-latest diff --git a/.vscode/launch.json b/.vscode/launch.json index 5558fa6..ae76d79 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -29,6 +29,17 @@ "ignoreFailures": true } ] + }, + // https://stackoverflow.com/a/76447033 + { + "name": "(ctest) Launch", + "type": "cppdbg", + "cwd": "${cmake.testWorkingDirectory}", + "request": "launch", + "program": "${cmake.testProgram}", + "args": [ + "${cmake.testArgs}" + ] } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..26ceda5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "cmake.ctest.testSuiteDelimiter": "\\.", + "cmake.ctest.testExplorerIntegrationEnabled": true +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ba65cf..b1a9c44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,10 +6,10 @@ project(glpp LANGUAGES CXX) set(GLPP_IS_MASTER_PROJECT OFF) -if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) set(GLPP_IS_MASTER_PROJECT ON) endif() - + option(GLPP_BUILD_DOCS "Builds the glpp documentation" ${GLPP_IS_MASTER_PROJECT}) option(GLPP_BUILD_EXAMPLES "Builds the glpp examples" ${GLPP_IS_MASTER_PROJECT}) option(GLPP_BUILD_TESTS "Builds the glpp tests" ${GLPP_IS_MASTER_PROJECT}) @@ -43,7 +43,7 @@ endif() include(GNUInstallDirs) # Create config.h with project version numbers -configure_File(cmake/config.h.in include/config.h) +configure_file(cmake/config.h.in include/config.h) include_directories(PRIVATE ${CMAKE_BINARY_DIR}/include) find_package(OpenGL REQUIRED) diff --git a/LICENSE b/LICENSE index 862f8ea..985f30f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License -Copyright 2021 Thomas Harrison +Copyright 2021 Thomas Harrison Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 7cf389f..8ce254e 100644 --- a/Makefile +++ b/Makefile @@ -28,4 +28,7 @@ lint: format: @find src include examples tests -name '*.c' -or -name '*.h' -or -name '*.cpp' -or -name '*.hpp' | xargs clang-format -i --Werror --sort-includes -.PHONY: config build install lint format +test: + cmake --build $(PWD)/build --target test + +.PHONY: config build install lint format test diff --git a/external/glm.cmake b/external/glm.cmake index 7bee5b1..5f71fc9 100644 --- a/external/glm.cmake +++ b/external/glm.cmake @@ -3,7 +3,7 @@ include(FetchContent) FetchContent_Declare( glm GIT_REPOSITORY https://github.com/g-truc/glm.git - GIT_TAG 1.0.1 + GIT_TAG 1.0.2 ) set(USE_SYSTEM_GLM ON) diff --git a/external/gtest.cmake b/external/gtest.cmake index 7e285bc..3c9c7bc 100644 --- a/external/gtest.cmake +++ b/external/gtest.cmake @@ -1,11 +1,11 @@ +include(FetchContent) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.12.1 + GIT_TAG v1.15.2 ) -# if(NOT glm_POPULATED) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) set(BUILD_GTEST ON CACHE BOOL "" FORCE) diff --git a/include/glpp/Buffer.hpp b/include/glpp/Buffer.hpp index 0327cc2..1ab65a6 100644 --- a/include/glpp/Buffer.hpp +++ b/include/glpp/Buffer.hpp @@ -10,8 +10,8 @@ #include namespace glpp { - using std::vector; using std::shared_ptr; + using std::vector; /** * A single array buffer. diff --git a/include/glpp/FrameBuffer.hpp b/include/glpp/FrameBuffer.hpp index e5d3eab..2caa349 100644 --- a/include/glpp/FrameBuffer.hpp +++ b/include/glpp/FrameBuffer.hpp @@ -11,8 +11,8 @@ #include "Texture.hpp" namespace glpp { - using std::vector; using std::shared_ptr; + using std::vector; class RenderBuffer { public: diff --git a/include/glpp/Shader.hpp b/include/glpp/Shader.hpp index 02a10be..5a05137 100644 --- a/include/glpp/Shader.hpp +++ b/include/glpp/Shader.hpp @@ -13,9 +13,9 @@ // https://www.khronos.org/opengl/wiki/Shader_Compilation namespace glpp { + using std::shared_ptr; using std::string; using std::string_view; - using std::shared_ptr; class ShaderCompileException : public std::runtime_error { public: diff --git a/include/glpp/Texture.hpp b/include/glpp/Texture.hpp index d550181..2735864 100644 --- a/include/glpp/Texture.hpp +++ b/include/glpp/Texture.hpp @@ -10,8 +10,8 @@ #include namespace glpp { - using std::string; using std::shared_ptr; + using std::string; class TextureLoadException : public std::runtime_error { public: diff --git a/include/glpp/extra/GeometryBuffer.hpp b/include/glpp/extra/GeometryBuffer.hpp index b746b81..a3d1dbe 100644 --- a/include/glpp/extra/GeometryBuffer.hpp +++ b/include/glpp/extra/GeometryBuffer.hpp @@ -9,8 +9,8 @@ #include "glpp/extra/Vertex.hpp" namespace glpp::extra { - using std::shared_ptr; using glm::uvec2; + using std::shared_ptr; class GeometryBuffer : public FrameBuffer { public: diff --git a/include/glpp/extra/Vertex.hpp b/include/glpp/extra/Vertex.hpp index 746b556..2fc83c1 100644 --- a/include/glpp/extra/Vertex.hpp +++ b/include/glpp/extra/Vertex.hpp @@ -6,8 +6,8 @@ #include "glpp/Buffer.hpp" namespace glpp::extra { - using std::vector; using std::shared_ptr; + using std::vector; /** * A single point in the format accepted by VBO, Mesh and Model. diff --git a/src/extra/Grid.cpp b/src/extra/Grid.cpp index cf6fb1c..ef4b08b 100644 --- a/src/extra/Grid.cpp +++ b/src/extra/Grid.cpp @@ -22,8 +22,8 @@ void main() { })"; namespace glpp::extra { - using std::vector; using std::make_shared; + using std::vector; void Grid::updateBuffer() { vector vertices; diff --git a/src/extra/Line.cpp b/src/extra/Line.cpp index fd0e2fd..398362e 100644 --- a/src/extra/Line.cpp +++ b/src/extra/Line.cpp @@ -28,8 +28,8 @@ void main() { }) namespace glpp::extra { - using std::vector; using std::make_shared; + using std::vector; void Line::updateBuffer() { vector vertices = points; diff --git a/src/extra/Marker.cpp b/src/extra/Marker.cpp index 41514ed..d02f13a 100644 --- a/src/extra/Marker.cpp +++ b/src/extra/Marker.cpp @@ -1,8 +1,8 @@ #include "glpp/extra/Marker.hpp" namespace glpp::extra { - using std::move; using std::make_shared; + using std::move; Mark::Mark(const vector & points, const glm::vec4 & color) : Transform(), line(make_shared(points, color, Line::Lines)) {} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0a0e7a5..5409183 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,29 +1,22 @@ -set(TARGET tests) +enable_testing() +include(GoogleTest) -macro(define_test name) +file(GLOB_RECURSE SOURCE_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +file(GLOB_RECURSE HEADER_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) - set(SOURCE_LIST - glTest.cpp - glTest.hpp - glmChecker.cpp - glmChecker.hpp - test_${name}.cpp - ) - list(TRANSFORM SOURCE_LIST PREPEND "${${PROJECT_NAME}_SOURCE_DIR}/tests/") +foreach(TEST_SOURCE ${SOURCE_LIST}) + cmake_path(GET TEST_SOURCE STEM test_name) + if(${test_name} MATCHES "^test_") + message("Generate test ${test_name}") - add_executable(${TARGET}_${name} ${SOURCE_LIST}) - target_link_libraries(${TARGET}_${name} PRIVATE gtest gtest_main glpp glfw) + add_executable(${test_name} ${TEST_SOURCE} ${HEADER_LIST} + glTest.cpp + glTest.hpp + glmChecker.cpp + glmChecker.hpp) + target_link_libraries(${test_name} PRIVATE gtest gtest_main glpp glfw) - target_include_directories(${TARGET}_${name} PRIVATE "${${PROJECT_NAME}_SOURCE_DIR}/tests/") + gtest_discover_tests(${test_name}) + endif() +endforeach() - add_test(NAME ${TARGET}_${name} COMMAND ${TARGET}_${name}) -endmacro() - -define_test(shader) -define_test(uniform) -define_test(texture) -define_test(vertex) -define_test(quad) - -define_test(glm_compare) -define_test(extra_Transform) diff --git a/tests/glmChecker.cpp b/tests/glmChecker.cpp index 9384901..77185c9 100644 --- a/tests/glmChecker.cpp +++ b/tests/glmChecker.cpp @@ -4,9 +4,9 @@ #include #include -using glm::vec3; -using glm::quat; using glm::mat4; +using glm::quat; +using glm::vec3; using std::ostream; // static ostream & operator<<(ostream & os, const quat & q) { diff --git a/tests/test_extra_Transform.cpp b/tests/test_extra_Transform.cpp index bfeb9c2..fe0308b 100644 --- a/tests/test_extra_Transform.cpp +++ b/tests/test_extra_Transform.cpp @@ -12,10 +12,10 @@ #include "glTest.hpp" namespace { - using glpp::extra::Transform; - using glm::vec3; - using glm::quat; using glm::mat4; + using glm::quat; + using glm::vec3; + using glpp::extra::Transform; /** * Empty constructor should have default position and rotation of 0 with diff --git a/tests/test_glm_compare.cpp b/tests/test_glm_compare.cpp index b769d6b..037054b 100644 --- a/tests/test_glm_compare.cpp +++ b/tests/test_glm_compare.cpp @@ -6,9 +6,9 @@ #include "glTest.hpp" namespace { - using glm::vec3; - using glm::quat; using glm::mat4; + using glm::quat; + using glm::vec3; TEST(GLMTest, VecEqIsExpected) { vec3 a(1, 2, 3); diff --git a/tests/test_shader.cpp b/tests/test_shader.cpp index f3eae1c..f37cdee 100644 --- a/tests/test_shader.cpp +++ b/tests/test_shader.cpp @@ -135,8 +135,7 @@ namespace { } TEST_F(ShaderTest, defaultShader) { - // TODO: Why did this switch to 0 instead of > 0 - EXPECT_EQ(shader.getProgram(), 0); + EXPECT_GT(shader.getProgram(), 0); } TEST_F(ShaderTest, fromFragmentSource) {