Giter Club home page Giter Club logo

ctest's Introduction

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

ctest

ctest is a simple portable C test runner.

Setup

  1. Clone ctest by:
git clone https://github.com/Azure/ctest
  1. Create a folder called cmake (or any name of your choice).

  2. Switch to the cmake folder and run

cmake ..

Build

Switch to the cmake folder and run:

cmake --build .

Installation and Use

Optionally, you may choose to install ctest on your machine:

  1. Switch to the cmake folder and run

    cmake --build . --target install
    

    or

    Linux:

    sudo make install
    

    Windows:

    msbuild /m INSTALL.vcxproj
    
  2. Use it in your project (if installed)

    find_package(ctest REQUIRED CONFIG)
    target_link_library(yourlib ctest)
    

Building the tests

In order to build the tests use the run_unittests cmake option:

cmake .. -Drun_unittests:bool=ON

Example

#include "ctest.h"
#include "SomeUnitUnderTest.h"

CTEST_BEGIN_TEST_SUITE(SimpleTestSuiteOneTest)

CTEST_FUNCTION(Test1)
{
    // arrange

    // act
    int x = SomeFunction();

    // assert
    CTEST_ASSERT_ARE_EQUAL(int, 42, x);
}

CTEST_END_TEST_SUITE(SimpleTestSuiteOneTest)

ctest's People

Contributors

ackpaul avatar andrew-buckley avatar anporumb avatar aribeironovaes avatar avranju avatar damonbarry avatar danewalton avatar darobs avatar dcristoloveanu avatar ewertons avatar ipg2013 avatar jebrando avatar jetstreamroysprowl avatar jspaith avatar kevcadieux avatar m-iceberg avatar marcschier avatar mattdurak avatar microsoft-github-policy-service[bot] avatar mrohera avatar msftbot[bot] avatar parth21999 avatar sahithkallakunta avatar sfathelbab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ctest's Issues

WTB rich(-er) ASSERTS

At the moment the following is possible

CTEST_ASSERT_IS_TRUE_WITH_MSG(3==3, "someMessage").

I would like to have the MSG part extended, to behave printf-ish like, as in:
CTEST_ASSERT_IS_TRUE_WITH_MSG(3==3, "here is my integer = %d", i);

CTEST_ASSERT_ARE_EQUAL doesn't work with array type

Example:

typedef unsigned char my_type[32];

// … test code
ASSERT_ARE_EQUAL(my_type, a, b);

Fails to compile in CTEST_ASSERT_ARE_EQUAL because the code tries to cast/assign an array type:

#define CTEST_ASSERT_ARE_EQUAL(type, A, B, ...) \
do { \
    const type A_value = (const type)(A); \
    const type B_value = (const type)(B); \

error C2067: cast to array type is illegal

Instead, this does work:

typedef unsigned char my_type[32];
typedef my_type* my_type_ptr;

// … test code
ASSERT_ARE_EQUAL(my_type_ptr, &a, &b);

inconsistent vsnprintf behavior

When using the clang compiler and a test fails with a non-NULL log parameter, ctest fails with the following printf statement: inconsistent vsnprintf behavior. The failure is happening due to a va_list failure that needs to be looked at.

RUN_TEST_SUITE improvements

Would be awesome if the RUN_TEST_SUITE macro would:

  1. either be a rvalue (and return failedTestCount)
  2. either take a size_t*, because it is immediately un-obvious that failedTestCount is actually written by the macro.

WTB test fixtures!

at the moment, there's a (1x) global TEST_SUITE_INITIALIZE and a (1x) global TEST_FUNCTION_INITIALIZE. This does not leave much flexibility in setting up the initial conditions for a test.

A test fixture feature would allow reuse of pre-existing conditions easier and would (likely) reduce the amount of code in ///arrange sections.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.