Skip to content

Commit

Permalink
Move unit tests into their own directory.
Browse files Browse the repository at this point in the history
Unit tests in this case are all those not depending on data, but just
testing lower-level functions of the library.
  • Loading branch information
joto committed Feb 28, 2018
1 parent 6342541 commit f07ae35
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 12 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ if(CLANG_TIDY)
${CLANG_TIDY}
-p ${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/test/*.cpp
${CMAKE_SOURCE_DIR}/test/t/*/reader_test_cases.cpp
${CMAKE_SOURCE_DIR}/test/t/*/writer_test_cases.cpp
${CMAKE_SOURCE_DIR}/test/t/*/*.cpp
${CMAKE_SOURCE_DIR}/test/unit/*.cpp
${CMAKE_SOURCE_DIR}/tools/*.cpp
)
add_dependencies(clang-tidy writer_tests)
Expand All @@ -94,6 +94,7 @@ if(CPPCHECK)
${CMAKE_SOURCE_DIR}/test/*.cpp
${CMAKE_SOURCE_DIR}/test/include/*.hpp
${CMAKE_SOURCE_DIR}/test/t/*/*.cpp
${CMAKE_SOURCE_DIR}/test/unit/*.cpp
${CMAKE_SOURCE_DIR}/tools/*.cpp
)
else()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ Extensive tests are included. Build them using CMake:

Call `ctest` to run the tests.

The reader tests are always build, the writer tests are only build if the
Google Protobuf library is found when running CMake.
The unit and reader tests are always build, the writer tests are only build if
the Google Protobuf library is found when running CMake.

See `test/README.md` for more details about the test.

Expand Down
10 changes: 3 additions & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/catch")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")

add_subdirectory(unit)

set(TEST_DIRS alignment
basic
bool
bytes
complex
data_view
double
endian
enum
exceptions
fixed32
fixed64
float
Expand Down Expand Up @@ -52,10 +50,8 @@ set(TEST_DIRS alignment
tags
uint32
uint64
varint
vector_tile
wrong_type_access
zigzag)
wrong_type_access)

string(REGEX REPLACE "([^;]+)" "t/\\1/reader_test_cases.cpp" _test_sources "${TEST_DIRS}")

Expand Down
10 changes: 9 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

Tests are using the [Catch Unit Test Framework](https://github.com/philsquared/Catch).

## Organization of the unit tests

## Organization of the test cases
Unit tests test low-level functions of the library. They are in the `unit`
directory.


## Organization of the reader/writer test cases

The hart of the tests are the reader/writer tests checking all aspects of
decoding and encoding protobuf files.

Each test case is in its own directory under the `t` directory. Each directory
contains (some of) the following files:
Expand Down
23 changes: 23 additions & 0 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#-----------------------------------------------------------------------------
#
# CMake config
#
# protozero unit tests
#
#-----------------------------------------------------------------------------

set(UNIT_TESTS data_view
basic
endian
exceptions
varint
zigzag)

string(REGEX REPLACE "([^;]+)" "test_\\1.cpp" _test_sources "${UNIT_TESTS}")

add_executable(unit_tests main.cpp ${_test_sources})

add_test(NAME unit_tests COMMAND unit_tests)


#-----------------------------------------------------------------------------
4 changes: 4 additions & 0 deletions test/unit/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#define CATCH_CONFIG_MAIN
#include <test.hpp> // IWYU pragma: keep

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f07ae35

Please sign in to comment.