Merge pull request #101 from balp/c99

Add CMake and Unity test framework for c99
This commit is contained in:
Emily Bache 2018-10-31 07:32:40 +01:00 committed by GitHub
commit 3906ee2b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 0 deletions

31
c99/CMakeLists.txt Normal file
View File

@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 2.8.4)
project(GildedRose_c99)
enable_testing()
include(ExternalProject)
ExternalProject_Add(unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
GIT_TAG master
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/unity-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/unity-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/unity-src/src/unity.c
DEPENDS unity
COMMAND "")
add_executable( GildedRose_Unity
GildedRose.c
${CMAKE_CURRENT_BINARY_DIR}/unity-src/src/unity.c
test_unity_gildedrose.c
)
target_include_directories(GildedRose_Unity PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/unity-src/src/)
set_property(TARGET GildedRose_Unity PROPERTY C_STANDARD 99)
add_dependencies(GildedRose_Unity unity)
add_test(NAME GildedRose_Unity COMMAND GildedRose_Unity)

8
c99/run-once-cmake.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
if [[ ! -d build ]]; then
mkdir -p build
fi
cd build
cmake .. -DCMAKE_BUILD_TYPE=DEBUG && cmake --build . && ctest --output-on-failure

View File

@ -0,0 +1,18 @@
#include "unity.h"
#include "GildedRose.h"
void test_NameOfItem(void)
{
Item items[1];
init_item(items, "Foo", 0, 0);
update_quality(items, 1);
TEST_ASSERT_EQUAL_STRING( "fixme", items[0].name );
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_NameOfItem);
return UNITY_END();
}