|
| 1 | +# cmake-gcc-runner |
| 2 | + |
| 3 | +This is a C/C++ runner for CMake projects (based on GCC). |
| 4 | + |
| 5 | +## How to Use it |
| 6 | + |
| 7 | +```yaml |
| 8 | +runner: |
| 9 | + name: codingame/cmake-gcc-runner |
| 10 | + version: 1.0-gcc-6.3 |
| 11 | +``` |
| 12 | +
|
| 13 | +Your project will be compiled one with: |
| 14 | +
|
| 15 | +``` |
| 16 | +cmake . |
| 17 | +make |
| 18 | +``` |
| 19 | + |
| 20 | +And on each run, `make` will be executed and the command specified in the markdown file will be executed. |
| 21 | + |
| 22 | +## Example |
| 23 | + |
| 24 | +In this example, the unit testing framework "Catch" is used. Here's the content of the CMakeLists.txt file: |
| 25 | + |
| 26 | +``` |
| 27 | +cmake_minimum_required(VERSION 2.8.9) |
| 28 | +project (tests) |
| 29 | +add_executable(tests tests.cpp factorial.cpp factorial.h) |
| 30 | +
|
| 31 | +# Includes Catch in the project: |
| 32 | +add_subdirectory(catch) |
| 33 | +include_directories(${CATCH_INCLUDE_DIR} ${COMMON_INCLUDES}) |
| 34 | +enable_testing(true) # Enables unit-testing. |
| 35 | +
|
| 36 | +add_dependencies(tests catch) |
| 37 | +
|
| 38 | +add_test(factorial ./tests [factorial]) |
| 39 | +``` |
| 40 | + |
| 41 | +Here's the stub (factorial.cpp): |
| 42 | + |
| 43 | +```C++ |
| 44 | +unsigned int Factorial( unsigned int number ) { |
| 45 | + return number <= 1 ? number : Factorial(number-1)*number; |
| 46 | +} |
| 47 | +``` |
| 48 | +
|
| 49 | +And the main file (tests.cpp): |
| 50 | +
|
| 51 | +```C++ |
| 52 | +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file |
| 53 | +#include "catch.hpp" |
| 54 | +#include "factorial.h" |
| 55 | +
|
| 56 | +TEST_CASE( "Factorials are computed", "[factorial]" ) { |
| 57 | + REQUIRE( Factorial(1) == 1 ); |
| 58 | + REQUIRE( Factorial(2) == 2 ); |
| 59 | + REQUIRE( Factorial(3) == 6 ); |
| 60 | + REQUIRE( Factorial(10) == 3628800 ); |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +In the markdown file, you must specify the command used to execute your test. |
| 65 | + |
| 66 | +```markdown |
| 67 | +@[Example]({"stubs": ["factorial.cpp"], "command": "./tests [factorial]"}) |
| 68 | +``` |
0 commit comments