| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 1 | # Build and run compiler tests using CMake |
| 2 | |
| 3 | <!-- TOC --> |
| 4 | |
| 5 | - [Build and run compiler tests using CMake](#build-and-run-compiler-tests-using-cmake) |
| 6 | - [General information](#general-information) |
| 7 | - [How to add your tests](#how-to-add-your-tests) |
| 8 | - [Build and run tests on Unix-like systems](#build-and-run-tests-on-unix-like-systems) |
| 9 | - [Prerequisites:](#prerequisites) |
| 10 | - [Build and run test with CMake](#build-and-run-test-with-cmake) |
| 11 | - [Build and run tests on Windows](#build-and-run-tests-on-windows) |
| 12 | - [Prerequisites:](#prerequisites-1) |
| 13 | - [Generation of VS project with CMake, build and run on Windows](#generation-of-vs-project-with-cmake-build-and-run-on-windows) |
| 14 | |
| 15 | <!-- /TOC --> |
| 16 | |
| 17 | ## General information |
| 18 | |
| Jens Geyer | 3f3567a | 2019-10-19 18:27:35 +0200 | [diff] [blame] | 19 | Added generic way to cover code by tests for many languages (you just need to make a correct header file for generator for your language - example in **netstd** implementation) |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 20 | |
| 21 | At current moment these tests use free Catch library (https://github.com/catchorg/Catch2/tree/Catch1.x) for easy test creation and usage. |
| 22 | Decision to use it was because of simplicity, easy usage, one header file to use, stable community and growing interest (https://cpp.libhunt.com/project/googletest-google/vs/catch?rel=cmp-cmp) |
| 23 | |
| 24 | Also, maybe, later it will be migrated to Catch2 (https://github.com/philsquared/Catch) - depends on need to support legacy compilers (c++98) |
| 25 | |
| 26 | ## How to add your tests |
| 27 | |
| 28 | - Open **CMakeLists.txt** |
| 29 | - Set **On** to call of **THRIFT_ADD_COMPILER** for your language |
| 30 | |
| 31 | ``` cmake |
| Jens Geyer | 3f3567a | 2019-10-19 18:27:35 +0200 | [diff] [blame] | 32 | THRIFT_ADD_COMPILER(netstd "Enable compiler for .NET Standard" ON) |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 33 | ``` |
| 34 | |
| 35 | - Create folder with name specified in list of languages in **CMakeLists.txt** |
| 36 | - Create tests in folder for your language (with extensions like *.c* - cc, cpp, etc) |
| 37 | - Don't forget to add include of catch.hpp in your test file |
| 38 | ``` C |
| 39 | #include "../catch/catch.hpp" |
| 40 | ``` |
| 41 | |
| 42 | - If you need - add files manually to **thrift_compiler_tests_manual_SOURCES** in **CMakeLists.txt** similar to |
| 43 | |
| 44 | ``` cmake |
| 45 | # you can add some files manually there |
| 46 | set(thrift_compiler_tests_manual_SOURCES |
| 47 | # tests file to avoid main in every test file |
| 48 | ${CMAKE_CURRENT_SOURCE_DIR}/tests_main.cc |
| 49 | ) |
| 50 | ``` |
| 51 | |
| 52 | - Run **cmake** with arguments for your environment and compiler |
| 53 | - Enjoy |
| 54 | |
| 55 | ## Build and run tests on Unix-like systems |
| 56 | |
| 57 | ### Prerequisites: |
| 58 | - Install CMake - <https://cmake.org/download/> |
| 59 | - Install winflexbison - <https://sourceforge.net/projects/winflexbison/> |
| 60 | |
| 61 | ### Build and run test with CMake |
| 62 | |
| 63 | - Run commands in command line in current directory: |
| 64 | |
| 65 | ``` |
| 66 | mkdir cmake-vs && cd cmake-vs |
| 67 | cmake .. |
| 68 | cmake --build . |
| 69 | ctest -C Debug -V |
| 70 | ``` |
| 71 | |
| 72 | ## Build and run tests on Windows |
| 73 | |
| 74 | ### Prerequisites: |
| 75 | - Install CMake - <https://cmake.org/download/> |
| 76 | - Install winflexbison - <https://sourceforge.net/projects/winflexbison/> |
| 77 | - Install VS2017 Community Edition - <https://www.visualstudio.com/vs/whatsnew/> (ensure that you installed workload "Desktop Development with C++" for VS2017) |
| 78 | |
| 79 | ### Generation of VS project with CMake, build and run on Windows |
| 80 | - Run commands in command line in current directory (ensure that VS installed): |
| 81 | |
| 82 | ``` |
| 83 | mkdir cmake-vs |
| 84 | cd cmake-vs |
| 85 | cmake .. |
| 86 | cmake --build . |
| 87 | ctest -C Debug -V |
| 88 | ``` |