Add Catch2 test framework. Add example test. Add tests build instructions.
This commit is contained in:
parent
9772905ade
commit
68ce375a18
16
CMakeLists.txt
Normal file
16
CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
|
project(cmake_test)
|
||||||
|
|
||||||
|
# Prepare "Catch" library for other executables
|
||||||
|
set(CATCH_INCLUDE_DIR Catch2)
|
||||||
|
add_library(Catch INTERFACE)
|
||||||
|
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
|
||||||
|
|
||||||
|
# Make test executable
|
||||||
|
set(TEST_SOURCES
|
||||||
|
Tests/tests.cpp
|
||||||
|
Tests/Example_test.cpp
|
||||||
|
)
|
||||||
|
add_executable(tests ${TEST_SOURCES})
|
||||||
|
target_link_libraries(tests Catch)
|
13287
Catch2/catch.hpp
Normal file
13287
Catch2/catch.hpp
Normal file
File diff suppressed because it is too large
Load Diff
20
README.md
20
README.md
@ -51,3 +51,23 @@ or you can also save the output code to the file (in so called `HEX`-format) `"F
|
|||||||
`Sketch->ExportCompiledBinary`
|
`Sketch->ExportCompiledBinary`
|
||||||
and then upload it to the printer using the program `"FirmwareUpdater"`
|
and then upload it to the printer using the program `"FirmwareUpdater"`
|
||||||
_note: this file is created in the directory `"Firmware/"`_
|
_note: this file is created in the directory `"Firmware/"`_
|
||||||
|
|
||||||
|
# 3. Automated tests
|
||||||
|
## Prerequisites
|
||||||
|
c++11 compiler e.g. g++ 6.3.1
|
||||||
|
cmake
|
||||||
|
build system - ninja or gnu make
|
||||||
|
## Building
|
||||||
|
Create folder where you want to build tests.
|
||||||
|
Example:
|
||||||
|
cd ..
|
||||||
|
mkdir Prusa-Firmware-test
|
||||||
|
Generate build scripts in target folder.
|
||||||
|
Example:
|
||||||
|
cd Prusa-Firmware-test
|
||||||
|
cmake -G "Eclipse CDT4 - Ninja" ../Prusa-Firmware
|
||||||
|
Build it.
|
||||||
|
Example:
|
||||||
|
ninja
|
||||||
|
## Runing
|
||||||
|
./tests
|
12
Tests/Example_test.cpp
Normal file
12
Tests/Example_test.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
unsigned int Factorial( unsigned int number ) {
|
||||||
|
return number <= 1 ? number : Factorial(number-1)*number;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||||
|
REQUIRE( Factorial(1) == 1 );
|
||||||
|
REQUIRE( Factorial(2) == 2 );
|
||||||
|
REQUIRE( Factorial(3) == 6 );
|
||||||
|
REQUIRE( Factorial(10) == 3628800 );
|
||||||
|
}
|
2
Tests/tests.cpp
Normal file
2
Tests/tests.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include "catch.hpp"
|
Loading…
Reference in New Issue
Block a user