blob: 91c0625a3406478806d111b2a920a2f495bf1c07 [file] [log] [blame] [view]
Volodymyr Gotra54993292017-12-18 02:08:09 +02001# 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 Geyer3f3567a2019-10-19 18:27:35 +020019Added 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 Gotra54993292017-12-18 02:08:09 +020020
21At current moment these tests use free Catch library (https://github.com/catchorg/Catch2/tree/Catch1.x) for easy test creation and usage.
22Decision 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
24Also, 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 Geyer3f3567a2019-10-19 18:27:35 +020032THRIFT_ADD_COMPILER(netstd "Enable compiler for .NET Standard" ON)
Volodymyr Gotra54993292017-12-18 02:08:09 +020033```
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
46set(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```
66mkdir cmake-vs && cd cmake-vs
67cmake ..
68cmake --build .
69ctest -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```
83mkdir cmake-vs
84cd cmake-vs
85cmake ..
86cmake --build .
87ctest -C Debug -V
88```