-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use cmake for build process and add better test (#3)
* use cmake for build process and add better test * fix test * fix test 2 * use cmake for tests
- Loading branch information
1 parent
6294fa7
commit dfe8dd6
Showing
4 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(main) | ||
|
||
add_executable(main main.cpp) | ||
|
||
install(TARGETS main) | ||
|
||
enable_testing() | ||
# Configure the test script for the current build | ||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/test_sum.sh.in ${CMAKE_CURRENT_BINARY_DIR}/test_sum.sh) | ||
add_test(NAME test-summation COMMAND bash test_sum.sh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
|
||
|
||
|
||
# Let's test that execution without arguments should fail | ||
`@CMAKE_CURRENT_BINARY_DIR@/main` | ||
# Test the return code of the execution to not be 0 | ||
if [ $? -eq 0 ]; then | ||
exit -1 | ||
fi | ||
|
||
# Test some basic summation | ||
result=`@CMAKE_CURRENT_BINARY_DIR@/main 3.14` | ||
echo $result | ||
|
||
# Check that return code is 0 | ||
if [ ! $? -eq 0 ]; then exit -1; fi | ||
if [ ! "$result" = "3.14" ]; then | ||
exit -2 | ||
fi | ||
|
||
result=`@CMAKE_CURRENT_BINARY_DIR@/main 0.1 0.5` | ||
echo $result | ||
|
||
# Check that return code is 0 | ||
if [ ! $? -eq 0 ]; then exit -1; fi | ||
if [ ! "$result" = "0.6" ]; then | ||
exit -2 | ||
fi | ||
|
||
result=`@CMAKE_CURRENT_BINARY_DIR@/main 0.1 -0.1` | ||
echo $result | ||
|
||
# Check that return code is 0 | ||
if [ ! $? -eq 0 ]; then exit -1; fi | ||
if [ ! "$result" = "0" ]; then | ||
exit -2 | ||
fi | ||
|
||
result=`@CMAKE_CURRENT_BINARY_DIR@/main 0.1 -0.15 0.5` | ||
echo $result | ||
|
||
# Check that return code is 0 | ||
if [ ! $? -eq 0 ]; then exit -1; fi | ||
if [ ! "$result" = "0.45" ]; then | ||
exit -2 | ||
fi | ||
|
||
result=`@CMAKE_CURRENT_BINARY_DIR@/main -0.1 -0.15 0.05` | ||
echo $result | ||
|
||
# Check that return code is 0 | ||
if [ ! $? -eq 0 ]; then exit -1; fi | ||
if [ ! "$result" = "-0.2" ]; then | ||
exit -2 | ||
fi |