Coder Social home page Coder Social logo

selavy / cgreen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cgreen-devs/cgreen

0.0 0.0 0.0 2.53 MB

A modern, portable, cross-language unit testing and mocking framework for C and C++

License: ISC License

Emacs Lisp 0.01% CMake 9.27% Makefile 1.84% Python 1.56% Shell 2.23% C++ 9.13% C 75.36% Perl 0.52% sed 0.07%

cgreen's Introduction

Build Status Coverage Status Chat on Gitter

Cgreen - The Modern Unit Test and Mocking Framework for C and C++

Do you TDD? In C or C++? Maybe you want to have your tests read out in a fluent fashion? Like this

Ensure(Converter, converts_XIV_to_14) {
    assert_that(convert_roman_to_decimal("XIV"), is_equal_to(14));
}

And you want output like this

roman_test.c:12: Failure: Converter -> converts_XIV_to_14
        Expected [convert_roman_to_decimal("XIV")] to [equal] [14]
                actual value:                   [0]
                expected value:                 [14]

Then Cgreen is the thing for you!

TLDR; The full tutorial is on github.io. Or have a look at the cheat sheet.

What It Is

Cgreen is a modern unit test and mocking framework for C and C++. Here are some of Cgreens unique selling points:

  • fast build, clean code, highly portable
  • auto-discovery of tests without the abuse of static initializers or globals
  • extensible without recompiling
  • fluent, expressive and readable API with the same modern syntax across C and C++
  • process isolation for each test preventing intermittent failures and cross-test dependencies
  • built-in mocking for C, compatible with mockitopp and other C++ mocking libraries
  • expressive and clear output using the default reporter
  • fully functional mocks, both strict, loose and learning
  • mocks with side effects
  • extensive and expressive constraints for many datatypes
  • custom constraints can be constructed by user
  • bdd-flavoured test declarations with Before and After declarations
  • extensible reporting mechanism
  • fully composable test suites
  • a single test can be run in a single process for easier debugging

Getting It

Cgreen is hosted on GitHub. As of now there are no pre-built packages to download, so you have to clone the repository or download the source zip from GitHub and build it yourself.

There are some packaging scripts floating around, some of which have unclear status:

Building It

You need the CMake build system. Most standard C/C++ compilers should work. GCC definitely does.

In the root directory run make. That will configure and build the library and the cgreen-runner, both supporting both C and C++. See also the documentation.

Using Cgreen in other CMake projects

Once Cgreen is installed you can use find_package(cgreen) in your CMake projects to get access to useful variables like ${CGREEN_LIBRARIES}, ${CGREEN_EXECUTABLE} and ${CGREEN_INCLUDE_DIRS}. Version can be specified in find_package as well. For example, in order to enforce a minimum version of Cgreen in your project use find_package(cgreen 1.1.0)

Reading Up!

You can read the extensive tutorial directly on GitHub.

There is a cheat sheet available.

You can also build the documentation yourself in HTML and PDF format. Generate it using Asciidoctor, which can be done using the CMake configuration. Of course you need Asciidoctor.

make docs
make pdf

(Generating PDF also requires asciidoctor-pdf.)

License

Cgreen is licensed under the ISC License (http://spdx.org/licenses/ISC), sometimes known as the OpenBSD license. If there is no licence agreement with this package please download a version from the location above. You must read and accept that licence to use this software. The file is titled simply LICENSE.

The Original Version

What is it? It's a framework for unit testing, written in C. A tool for C developers writing tests of their own code.

If you have used JUnit, or any of the xUnit clones, you will find the concept familiar. In particular the tool supports a range of assertions, composable test suites and setup/teardown facilities. Because of the peculiarities of C programming, each test function is normally run in it's own process.

This project is very close in scope to the "Check" unit tester and was influenced by it... http://check.sourceforge.net/projects/check/

The main difference from this tool and other xUnit tools, such as "Check", is that test results are not stored. Instead they are streamed to the reporter psuedo-class, one that is easily overridden by the end user.

The other main extra feature is the support for writing mock callbacks. This includes generating sequences for return values or parameter expectations.

Feedback, queries and request should be put to the cgreen developers through https://github.com/cgreen-devs/cgreen.

This tool is basically a spin off from a research project at Wordtracker and would not have happened without the generous financial support of the Wordtracker keyword tool... http://www.wordtracker.com/

Substantial inital work by Marcus Baker [email protected]. Recent additions by Matt Hargett [email protected], Thomas Nilefalk [email protected], João Freitas [email protected] and others.

cgreen's People

Contributors

thoni56 avatar lastcraft avatar joaohf avatar matthargett avatar gladiac avatar joaopapereira avatar aytchell avatar stevemadsenblippar avatar ptzafrir avatar ykaliuta avatar dankm avatar derfian avatar adamburgess avatar d-meiser avatar crockagile avatar selavy avatar partouf avatar

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.