diff options
Diffstat (limited to '')
-rw-r--r-- | .github/workflows/ci.yml | 63 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | Makefile | 84 | ||||
m--------- | cmake | 0 | ||||
-rw-r--r-- | test/CMakeLists.txt | 15 | ||||
-rw-r--r-- | test/unit_tests/CMakeLists.txt | 51 |
7 files changed, 147 insertions, 69 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df63d9e..fd05ccd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,7 @@ jobs: PLATFORM: '${{ matrix.platform }}' CONFIGURATION: '${{ matrix.configuration }}' BOOST_VERSION: 1.65.0 + CMAKE_FLAGS: -D WINAPI_COMMON_TESTS=ON defaults: run: shell: pwsh @@ -58,70 +59,22 @@ jobs: platform: '${{ matrix.platform }}' if: matrix.toolset == 'mingw' - name: Build Boost - run: | - cd cmake - python -m project.ci.boost -- --with-test + run: make deps - name: Build - run: | - cd cmake - $flags = if ('${{ matrix.toolset }}' -eq 'msvc') { - '--','-D','WINAPI_COMMON_TESTS=ON' - } else { - @() - } - python -m project.ci.cmake --install $flags + run: make install - name: Upload binaries uses: actions/upload-artifact@v2 with: name: 'winapi-common-${{ matrix.os }}-${{ matrix.toolset }}-${{ matrix.platform }}-${{ matrix.configuration }}' path: '${{ runner.workspace }}/build/install/' - - name: Make test logs directory - run: mkdir ../test_logs - if: runner.os == 'Windows' - - name: Run unit tests (w/o console tests) - run: | - $args = @( - '--log_level=all', - '--log_sink=..\test_logs\tests.log', - '--report_sink=..\test_logs\report.txt', - '--run_test=!console_tests,process_console_tests', - '--', - '--echo_exe=..\build\install\bin\winapi-common-test-echo.exe', - '--worker_exe=..\build\install\bin\winapi-common-test-worker.exe' - ) - ..\build\install\bin\winapi-common-unit-tests.exe $args - if: runner.os == 'Windows' - - name: Check test report (w/o console tests) - run: | - cat ..\test_logs\report.txt - $last_line = Get-Content ..\test_logs\report.txt -Tail 1 - $($last_line -eq '*** No errors detected') -or $(throw $last_line) - if: runner.os == 'Windows' - - name: Run unit tests (console tests) - run: | - $args = @( - '--log_level=all', - '--log_sink=..\test_logs\tests_console.log', - '--report_sink=..\test_logs\report_console.txt', - '--run_test=console_tests,process_console_tests', - '--', - '--echo_exe=..\build\install\bin\winapi-common-test-echo.exe', - '--worker_exe=..\build\install\bin\winapi-common-test-worker.exe' - ) - Start-Process ` - -FilePath ..\build\install\bin\winapi-common-unit-tests.exe ` - -ArgumentList $args ` - -Wait - if: runner.os == 'Windows' - - name: Check test report (console tests) - run: | - cat ..\test_logs\report_console.txt - $last_line = Get-Content ..\test_logs\report_console.txt -Tail 1 - $($last_line -eq '*** No errors detected') -or $(throw $last_line) + - name: Test + run: make test if: runner.os == 'Windows' - name: Upload test logs uses: actions/upload-artifact@v2 with: name: 'test_logs-${{ matrix.os }}-${{ matrix.platform }}-${{ matrix.configuration }}' - path: '${{ runner.workspace }}/test_logs/' + path: | + ${{ runner.workspace }}/build/**/*_tests.log + ${{ runner.workspace }}/build/**/*_report.txt if: always() && runner.os == 'Windows' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e03e15 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index c6a4357..3fc3b4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.5) # for Boost::* imported targets project(winapi_common CXX) +enable_testing() + include(cmake/common.cmake) file(GLOB_RECURSE winapi_common_include "include/*.hpp") diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b1641b3 --- /dev/null +++ b/Makefile @@ -0,0 +1,84 @@ +# Various one-liners which I'm too lazy to remember. +# Basically a collection of really small shell scripts. + +MAKEFLAGS += --no-builtin-rules --no-builtin-variables --warn-undefined-variables +unexport MAKEFLAGS +.DEFAULT_GOAL := all +.DELETE_ON_ERROR: +.SUFFIXES: +SHELL := bash +.SHELLFLAGS := -eu -o pipefail -c + +.PHONY: DO +DO: + +escape = $(subst ','\'',$(1)) + +define noexpand +ifeq ($$(origin $(1)),environment) + $(1) := $$(value $(1)) +endif +ifeq ($$(origin $(1)),environment override) + $(1) := $$(value $(1)) +endif +ifeq ($$(origin $(1)),command line) + override $(1) := $$(value $(1)) +endif +endef + +TOOLSET ?= mingw +CONFIGURATION ?= Debug +BOOST_VERSION ?= 1.65.0 +BOOST_LIBRARIES := --with-test +CMAKE_FLAGS ?= -D WINAPI_COMMON_TESTS=ON + +this_dir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +src_dir := $(this_dir) +ifdef CI +build_dir := $(this_dir)../build +else +build_dir := $(this_dir).build +endif +boost_dir := $(build_dir)/boost +cmake_dir := $(build_dir)/cmake +DESTDIR ?= $(build_dir)/install + +$(eval $(call noexpand,TOOLSET)) +$(eval $(call noexpand,CONFIGURATION)) +$(eval $(call noexpand,BOOST_VERSION)) +$(eval $(call noexpand,CMAKE_FLAGS)) +$(eval $(call noexpand,DESTDIR)) + +.PHONY: all +all: build + +.PHONY: clean +clean: + rm -rf -- '$(call escape,$(build_dir))' + +$(boost_dir)/: + cd cmake && python3 -m project.boost.download --cache '$(call escape,$(build_dir))' -- '$(call escape,$(BOOST_VERSION))' '$(call escape,$(boost_dir))' + +.PHONY: deps +ifdef CI +deps: + cd cmake && python3 -m project.ci.boost -- $(BOOST_LIBRARIES) +else +deps: $(boost_dir)/ + cd cmake && python3 -m project.boost.build --toolset '$(call escape,$(TOOLSET))' --configuration '$(call escape,$(CONFIGURATION))' -- '$(call escape,$(boost_dir))' $(BOOST_LIBRARIES) +endif + +.PHONY: build +build: +ifdef CI + cd cmake && python3 -m project.ci.cmake --install -- $(CMAKE_FLAGS) +else + cd cmake && python3 -m project.cmake.build --toolset '$(call escape,$(TOOLSET))' --configuration '$(call escape,$(CONFIGURATION))' --build '$(call escape,$(cmake_dir))' --install '$(call escape,$(DESTDIR))' --boost '$(call escape,$(boost_dir))' -- '$(call escape,$(src_dir))' $(CMAKE_FLAGS) +endif + +.PHONY: install +install: build + +.PHONY: test +test: + cd -- '$(call escape,$(cmake_dir))' && ctest -C '$(call escape,$(CONFIGURATION))' --verbose diff --git a/cmake b/cmake -Subproject e5de0b18453dd2fb3bf3e02414ee00ee185d81d +Subproject 3317c146e3a2eaec192c378a4e04389cf34246f diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3b61d11..ed1ebab 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,10 @@ -add_executable(echo echo.cpp) -set_target_properties(echo PROPERTIES OUTPUT_NAME winapi-common-test-echo) +# echo.cpp is MSVC-only, I think. +# TODO: fix that? +if(MSVC) + add_executable(echo echo.cpp) + set_target_properties(echo PROPERTIES OUTPUT_NAME winapi-common-test-echo) + install(TARGETS echo RUNTIME DESTINATION bin) + install_pdbs(TARGETS echo DESTINATION bin) -install(TARGETS echo RUNTIME DESTINATION bin) -install_pdbs(TARGETS echo DESTINATION bin) - -add_subdirectory(unit_tests) + add_subdirectory(unit_tests) +endif() diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt index c3d5b84..070e1bb 100644 --- a/test/unit_tests/CMakeLists.txt +++ b/test/unit_tests/CMakeLists.txt @@ -1,25 +1,60 @@ +find_package(Boost REQUIRED COMPONENTS unit_test_framework) + file(GLOB shared_src "shared/*.hpp") file(GLOB unit_tests_src "*.cpp" "*.h" "*.hpp" "*.rc") add_executable(unit_tests ${unit_tests_src} ${shared_src}) set_target_properties(unit_tests PROPERTIES OUTPUT_NAME winapi-common-unit-tests) - target_link_libraries(unit_tests PRIVATE winapi_common winapi_utf8) - -find_package(Boost REQUIRED COMPONENTS unit_test_framework) target_link_libraries(unit_tests PRIVATE Boost::disable_autolinking Boost::unit_test_framework) - install(TARGETS unit_tests RUNTIME DESTINATION bin) install_pdbs(TARGETS unit_tests DESTINATION bin) file(GLOB worker_src "worker/*.cpp") add_executable(worker ${worker_src} ${shared_src}) set_target_properties(worker PROPERTIES OUTPUT_NAME winapi-common-test-worker) - target_link_libraries(worker PRIVATE winapi_common winapi_utf8) - -find_package(Boost REQUIRED) target_link_libraries(worker PRIVATE Boost::disable_autolinking Boost::boost) - install(TARGETS worker RUNTIME DESTINATION bin) install_pdbs(TARGETS worker DESTINATION bin) + +find_package(Python3 REQUIRED COMPONENTS Interpreter) + +add_test(NAME unit_tests COMMAND unit_tests + --log_level=all + --no_color_output + "--log_sink=$<TARGET_FILE_DIR:unit_tests>/unit_tests.log" + "--report_sink=$<TARGET_FILE_DIR:unit_tests>/unit_tests_report.txt" + --run_test=!console_tests,process_console_tests + -- + "--echo_exe=$<TARGET_FILE:echo>" + "--worker_exe=$<TARGET_FILE:worker>") + +add_test(NAME unit_tests_report COMMAND Python3::Interpreter + "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/tools/ctest-driver.py" + grep + --pass-regex [=[^\*\*\* No errors detected$]=] + -- + "$<TARGET_FILE_DIR:unit_tests>/unit_tests_report.txt") + +add_test(NAME console_tests COMMAND Python3::Interpreter + "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/tools/ctest-driver.py" + run + --new-window + -- + "$<TARGET_FILE:unit_tests>" + --log_level=all + --no_color_output + "--log_sink=$<TARGET_FILE_DIR:unit_tests>/console_tests.log" + "--report_sink=$<TARGET_FILE_DIR:unit_tests>/console_tests_report.txt" + --run_test=console_tests,process_console_tests + -- + "--echo_exe=$<TARGET_FILE:echo>" + "--worker_exe=$<TARGET_FILE:worker>") + +add_test(NAME console_tests_report COMMAND Python3::Interpreter + "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/tools/ctest-driver.py" + grep + --pass-regex [=[^\*\*\* No errors detected$]=] + -- + "$<TARGET_FILE_DIR:unit_tests>/console_tests_report.txt") |