1

I understand googletest is for C++ Unit testing. However, I hope that I can use it for C Unit testing as well. I created a Hello world project with the following CmakeList.txt file which obviously didn't work.

One of the issue was /usr/bin/cc complained about C++ syntax such as "include < limits >" not found. I guess it though it was supposed to be limits.h to be C stylistically correct.

cmake_minimum_required(VERSION 3.10)
project(untitled C CXX)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_VERBOSE_MAKEFILE 1)

include_directories(../googletest/googletest/include)

add_executable(untitled main.c)
link_libraries(untitled gtest gtest_main)

main.c

#include <stdio.h>
#include <gtest/gtest.h>

int return_one()
{
    return 1;
}

TEST(test_case, test_name)
{
    ASSERT_EQ(return_one(), 1);
}
user1502776
  • 553
  • 7
  • 17
  • 1
    What is your question? It would be good if you provide a minimal example that demonstrates your problem. – Bernhard Nov 09 '18 at 06:48
  • 2
    GoogleTest is a C++ library, you cannot use it with C program. However, if your C program is correct for C++ too, you may compile it with C++ compiler: `set_source_files_properties(main.c PROPERTIES LANGUAGE CXX)`. This would allow you to use GoogleTest in your code. – Tsyvarev Nov 09 '18 at 07:44
  • 1
    Googletest can certainly be used to unit-test C APIs, but your post suggests that perhaps you haven't got the basic concepts of unit-testing quite straight to begin with. To get useful help, edit your post to show us what is in `main.c`. – Mike Kinghan Nov 09 '18 at 15:10

0 Answers0