kandi background
Explore Kits

cpputest | CppUTest unit testing and mocking framework for C/C | Unit Testing library

 by   cpputest C++ Version: latest-passing-build License: BSD-3-Clause

 by   cpputest C++ Version: latest-passing-build License: BSD-3-Clause

Download this library from

kandi X-RAY | cpputest Summary

cpputest is a C++ library typically used in Testing, Unit Testing applications. cpputest has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
[![Build Status](https://travis-ci.org/cpputest/cpputest.png?branch=master)](https://travis-ci.org/cpputest/cpputest) [![Build status](https://ci.appveyor.com/api/projects/status/irh38i4wblsb5tew?svg=true)](https://ci.appveyor.com/project/basvodde/cpputest) [![Coverage Status](https://coveralls.io/repos/cpputest/cpputest/badge.svg?branch=master&service=github)](https://coveralls.io/github/cpputest/cpputest?branch=master) [![ConanCenter package](https://repology.org/badge/version-for-repo/conancenter/cpputest.svg)](https://conan.io/center/cpputest). CppUTest unit testing and mocking framework for C/C++. [More information on the project page](https://cpputest.github.io). Slack channel: [Join if link not expired](https://join.slack.com/t/cpputest/shared_invite/zt-epq97u9h-6yBQHHl2cvUADjEENtdASw).
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • cpputest has a medium active ecosystem.
  • It has 922 star(s) with 399 fork(s). There are 89 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 111 open issues and 410 have been closed. On average issues are closed in 723 days. There are 17 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of cpputest is latest-passing-build
cpputest Support
Best in #Unit Testing
Average in #Unit Testing
cpputest Support
Best in #Unit Testing
Average in #Unit Testing

quality kandi Quality

  • cpputest has 0 bugs and 0 code smells.
cpputest Quality
Best in #Unit Testing
Average in #Unit Testing
cpputest Quality
Best in #Unit Testing
Average in #Unit Testing

securitySecurity

  • cpputest has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • cpputest code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
cpputest Security
Best in #Unit Testing
Average in #Unit Testing
cpputest Security
Best in #Unit Testing
Average in #Unit Testing

license License

  • cpputest is licensed under the BSD-3-Clause License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
cpputest License
Best in #Unit Testing
Average in #Unit Testing
cpputest License
Best in #Unit Testing
Average in #Unit Testing

buildReuse

  • cpputest releases are available to install and integrate.
  • Installation instructions, examples and code snippets are available.
cpputest Reuse
Best in #Unit Testing
Average in #Unit Testing
cpputest Reuse
Best in #Unit Testing
Average in #Unit Testing
Top functions reviewed by kandi - BETA

kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here

Get all kandi verified functions for this library.

Get all kandi verified functions for this library.

cpputest Key Features

CppUTest unit testing and mocking framework for C/C++

cpputest Examples and Code Snippets

See all related Code Snippets

Getting Started

copy iconCopydownload iconDownload
TEST_GROUP(FirstTestGroup)
{
};

TEST(FirstTestGroup, FirstTest)
{
   FAIL("Fail me!");
}

Building default checks with TestPlugin

copy iconCopydownload iconDownload
int main(int ac, char** av)
{
   LogPlugin logPlugin;
   TestRegistry::getCurrentRegistry()->installPlugin(&logPlugin);
   int result = CommandLineTestRunner::RunAllTests(ac, av);
   TestRegistry::getCurrentRegistry()->resetPlugins();
   return result;
}

How is memory leak detection implemented?

copy iconCopydownload iconDownload
TEST(MemoryLeakWarningTest, Ignore1)
{
    EXPECT_N_LEAKS(1);
    char* arrayToLeak1 = new char[100];
}

Example Main

copy iconCopydownload iconDownload
#include "CppUTest/CommandLineTestRunner.h"

int main(int ac, char** av)
{
  return RUN_ALL_TESTS(ac, av);
}

Example Test

copy iconCopydownload iconDownload
#include "CppUTest/TestHarness.h"
#include "ClassName.h"

TEST_GROUP(ClassName)
{
  ClassName* className;

  void setup()
  {
    className = new ClassName();
  }
  void teardown()
  {
    delete className;
  }
};

TEST(ClassName, Create)
{
  CHECK(0 != className);
  CHECK(true);
  CHECK_EQUAL(1,1);
  LONGS_EQUAL(1,1);
  DOUBLES_EQUAL(1.000, 1.001, .01);
  STRCMP_EQUAL("hello", "hello");
  FAIL("The prior tests pass, but this one doesn't");
}

Conan

copy iconCopydownload iconDownload
[requires]
cpputest/4.0

[generators]
cmake_find_package
cmake_paths

Integration as external CMake project

copy iconCopydownload iconDownload
# CppUTest
include(FetchContent)
FetchContent_Declare(
    CppUTest
    GIT_REPOSITORY https://github.com/cpputest/cpputest.git
    GIT_TAG        latest-passing-build # or use release tag, eg. v3.8
)
# Set this to ON if you want to have the CppUTests in your project as well.
set(TESTS OFF CACHE BOOL "Switch off CppUTest Test build")
FetchContent_MakeAvailable(CppUTest)

How to add compile options to a CMake FetchContent-dependency?

copy iconCopydownload iconDownload
set_target_properties(mytests PROPERTY
    CXX_STANDARD 11
    etc.
)
target_compile_options(mytests PUBLIC -option1 -option2 ...)

Docker compose fails to start a service with an error 'unknown option' but docker-compose build on the same command is a success

copy iconCopydownload iconDownload
ENTRYPOINT ["/opt/entrypoint.sh"]
CMD ["/usr/local/snort/bin/snort", "-i", "eth0", "-c", "/etc/snort/etc/snort.lua", "-A", "fast", "-s", "65535", "-k", "none"]
/opt/entrypoint.sh /usr/local/snort/bin/snort -i eth0 -c /etc/snort/etc/snort.lua -A fast -s 65535 -k none
#!/bin/sh
exec /usr/local/snort/bin/snort -c /etc/snort/etc/snort.lua "$@"
/usr/local/snort/bin/snort -c /etc/snort/etc/snort.lua /usr/local/snort/bin/snort -i eth0 -c /etc/snort/etc/snort.lua -A fast -s 65535 -k none
ENTRYPOINT ["/opt/entrypoint.sh"]
CMD ["/usr/local/snort/bin/snort", "-i", "eth0", "-c", "/etc/snort/etc/snort.lua", "-A", "fast", "-s", "65535", "-k", "none"]
/opt/entrypoint.sh /usr/local/snort/bin/snort -i eth0 -c /etc/snort/etc/snort.lua -A fast -s 65535 -k none
#!/bin/sh
exec /usr/local/snort/bin/snort -c /etc/snort/etc/snort.lua "$@"
/usr/local/snort/bin/snort -c /etc/snort/etc/snort.lua /usr/local/snort/bin/snort -i eth0 -c /etc/snort/etc/snort.lua -A fast -s 65535 -k none
ENTRYPOINT ["/opt/entrypoint.sh"]
CMD ["/usr/local/snort/bin/snort", "-i", "eth0", "-c", "/etc/snort/etc/snort.lua", "-A", "fast", "-s", "65535", "-k", "none"]
/opt/entrypoint.sh /usr/local/snort/bin/snort -i eth0 -c /etc/snort/etc/snort.lua -A fast -s 65535 -k none
#!/bin/sh
exec /usr/local/snort/bin/snort -c /etc/snort/etc/snort.lua "$@"
/usr/local/snort/bin/snort -c /etc/snort/etc/snort.lua /usr/local/snort/bin/snort -i eth0 -c /etc/snort/etc/snort.lua -A fast -s 65535 -k none
ENTRYPOINT ["/opt/entrypoint.sh"]
CMD ["/usr/local/snort/bin/snort", "-i", "eth0", "-c", "/etc/snort/etc/snort.lua", "-A", "fast", "-s", "65535", "-k", "none"]
/opt/entrypoint.sh /usr/local/snort/bin/snort -i eth0 -c /etc/snort/etc/snort.lua -A fast -s 65535 -k none
#!/bin/sh
exec /usr/local/snort/bin/snort -c /etc/snort/etc/snort.lua "$@"
/usr/local/snort/bin/snort -c /etc/snort/etc/snort.lua /usr/local/snort/bin/snort -i eth0 -c /etc/snort/etc/snort.lua -A fast -s 65535 -k none

Makefile multiple target patterns

copy iconCopydownload iconDownload
PROJECT_DIR=C:/STM32_Projects/blink_project
TEST_DIR=$(PROJECT_DIR)/test

TEST_SRC_DIRS=$(TEST_DIR)
TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) ...
TEST_OBJS = $(call src_to_o,$(TEST_SRC))
C:/STM32_Projects/blink_project/test/main.cpp
src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)
PROJECT_DIR = /STM32_Projects/blink_project
PROJECT_DIR=C:/STM32_Projects/blink_project
TEST_DIR=$(PROJECT_DIR)/test

TEST_SRC_DIRS=$(TEST_DIR)
TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) ...
TEST_OBJS = $(call src_to_o,$(TEST_SRC))
C:/STM32_Projects/blink_project/test/main.cpp
src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)
PROJECT_DIR = /STM32_Projects/blink_project
PROJECT_DIR=C:/STM32_Projects/blink_project
TEST_DIR=$(PROJECT_DIR)/test

TEST_SRC_DIRS=$(TEST_DIR)
TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) ...
TEST_OBJS = $(call src_to_o,$(TEST_SRC))
C:/STM32_Projects/blink_project/test/main.cpp
src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)
PROJECT_DIR = /STM32_Projects/blink_project
PROJECT_DIR=C:/STM32_Projects/blink_project
TEST_DIR=$(PROJECT_DIR)/test

TEST_SRC_DIRS=$(TEST_DIR)
TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) ...
TEST_OBJS = $(call src_to_o,$(TEST_SRC))
C:/STM32_Projects/blink_project/test/main.cpp
src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)
PROJECT_DIR = /STM32_Projects/blink_project
PROJECT_DIR=C:/STM32_Projects/blink_project
TEST_DIR=$(PROJECT_DIR)/test

TEST_SRC_DIRS=$(TEST_DIR)
TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) ...
TEST_OBJS = $(call src_to_o,$(TEST_SRC))
C:/STM32_Projects/blink_project/test/main.cpp
src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)
PROJECT_DIR = /STM32_Projects/blink_project
PROJECT_DIR=C:/STM32_Projects/blink_project
TEST_DIR=$(PROJECT_DIR)/test

TEST_SRC_DIRS=$(TEST_DIR)
TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) ...
TEST_OBJS = $(call src_to_o,$(TEST_SRC))
C:/STM32_Projects/blink_project/test/main.cpp
src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)
PROJECT_DIR = /STM32_Projects/blink_project
PROJECT_DIR=C:/STM32_Projects/blink_project
TEST_DIR=$(PROJECT_DIR)/test

TEST_SRC_DIRS=$(TEST_DIR)
TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) ...
TEST_OBJS = $(call src_to_o,$(TEST_SRC))
C:/STM32_Projects/blink_project/test/main.cpp
src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)
PROJECT_DIR = /STM32_Projects/blink_project

See all related Code Snippets

Community Discussions

Trending Discussions on cpputest
  • How to add compile options to a CMake FetchContent-dependency?
  • Docker compose fails to start a service with an error 'unknown option' but docker-compose build on the same command is a success
  • Makefile multiple target patterns
  • Including cpputest in makefile for project
Trending Discussions on cpputest

QUESTION

How to add compile options to a CMake FetchContent-dependency?

Asked 2021-Aug-09 at 11:48

I have a C/C++ project in which I want to use CppUTest. So I include the dependency of CppUTest with:

include(FetchContent)
FetchContent_Declare(
        CppUTest
        GIT_REPOSITORY      https://github.com/cpputest/cpputest.git
        GIT_TAG             latest-passing-build
        CONFIGURE_COMMAND   ""
        BUILD_COMMAND       ""
)
set(TESTS OFF CACHE BOOL "Switch off CppUTest Test build")
FetchContent_MakeAvailable(CppUTest)

This works fine.

In my (automotive) project, I use the C++20 standard and I need to enable all/most warnings. But when I do, CppUTest brings me a lot of warnings. So, I would like to compile CppUTest with different compiler options than the project's code.

How can I configure that in CMake? I googled a lot but didn't find anything that works.

Thanks, Stefan

PS: My simplified CMake file is:

cmake_minimum_required(VERSION 3.5)

project(projectName LANGUAGES CXX C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
    MESSAGE("Setting Clang flags:")
    SET(COMPILE_FLAGS_WARNINGS "-Weverything")
    SET(COMPILE_FLAGS_DEBUG    "-Og")
    SET(COMPILE_FLAGS_RELEASE  "-O2")
    SET(COMPILE_FLAGS_COVERAGE "--coverage")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    #more options here
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    #more options here
endif()

MESSAGE("Debug: ${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS_WARNINGS} ${COMPILE_FLAGS_DEBUG}")
MESSAGE("Release: ${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS_WARNINGS} ${COMPILE_FLAGS_RELEASE}")
MESSAGE("Coverage: ${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS_WARNINGS} ${COMPILE_FLAGS_DEBUG} ${COMPILE_FLAGS_COVERAGE}")

### Dependencies:

include(FetchContent)
FetchContent_Declare(
        CppUTest
        GIT_REPOSITORY      https://github.com/cpputest/cpputest.git
        GIT_TAG             latest-passing-build
        CONFIGURE_COMMAND   ""
        BUILD_COMMAND       ""
)    

set(TESTS OFF CACHE BOOL "Switch off CppUTest Test build")
FetchContent_MakeAvailable(CppUTest)

SET(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS_WARNINGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${COMPILE_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "${COMPILE_FLAGS_RELEASE}")
 
enable_testing()
    
### add tests
add_subdirectory(path/to/my/tests)

ANSWER

Answered 2021-Aug-09 at 11:48

Do not use set(CMAKE_<LANG>*. Use *target* interfaces. If you do not want all stuff to be compiled with a specific option, do not set them globally. Instead:

set_target_properties(mytests PROPERTY
    CXX_STANDARD 11
    etc.
)
target_compile_options(mytests PUBLIC -option1 -option2 ...)

Anyway, SET(CMAKE_<LANG>_* affect targets declared after it. So move set(CMAKE_* after FetchContent_MakeAvailable(CppUTest)

Source https://stackoverflow.com/questions/68708076

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install cpputest

You’ll need to do the following to get started:.
git clone git://github.com/cpputest/cpputest.git
cd cpputest_build
autoreconf .. -i
../configure
make
Download latest version
cmake CMakeLists.txt
make
Each TEST_GROUP may contain a setup and/or a teardown method. setup() is called prior to each TEST body and teardown() is called after the test body.
Each TEST_GROUP may contain a setup and/or a teardown method.
setup() is called prior to each TEST body and teardown() is called after the test body.

Support

Each TEST_GROUP may contain a setup and/or a teardown method. setup() is called prior to each TEST body and teardown() is called after the test body.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Reuse Pre-built Kits with cpputest
Consider Popular Unit Testing Libraries
Try Top Libraries by cpputest
Compare Unit Testing Libraries with Highest Support
Compare Unit Testing Libraries with Highest Quality
Compare Unit Testing Libraries with Highest Security
Compare Unit Testing Libraries with Permissive License
Compare Unit Testing Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.