Giter Site home page Giter Site logo

nikleberg / cmake-cmocka-tdd-template Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 370 KB

This is a template for test driven development of c projects with gcc, cmake and cmocka.

Home Page: https://nikleberg.github.io/cmake-cmocka-tdd-template/

License: MIT License

Dockerfile 3.48% CMake 42.12% C 54.40%
cmake template tdd c cmocka

cmake-cmocka-tdd-template's Introduction

cmake-cmocka-tdd-template

This is a template for test driven development tdd for a C project. The project gets generated by cmake and build by gcc. The tests use the integrated ctest funcionality of cmake and are written with the cmocka framework. Additionally doxygen is used to automaticly generate source code documentation and cppcheck to statically analyze the source code.

Requirements

Version in brackets is what was used at the time of writing.

  • cmake (3.18.4)
  • gcc (10.3.0)
  • cppcheck (2.3)
  • cmocka (1.1.5-2)
  • doxygen (1.9.1)

A Dockerfile is available for easy setup of the needed tools. Or even easier as prebuilt image on dockerhub nikolodion/cmake-tdd. If VSCode or another supported editor is used one could also use the additional devcontainer.json to setup the environment automatically.

Usage

Please note that the commands have to be executed from the build subdirectory.

command action  
cmake .. generate buildsystem  
make compile source code executable can be found under build/src/
make test_cmocka run cmocka tests  
make test_cppcheck check source code with cppcheck  
make tests run all tests cmocka & cppcheck
make doc generate documentation to view open build/doc/html/index.html
make clean remove compiled files  

If VSCode is used these commands are also available as tasks in tasks.json.

Project structure

  • lib/
    • Place for external dependencies.
  • src/
    • Here is all the source code for the application placed.
    • For modular code subfolders with appropriate CMake-Scripts can be created. As example see mylib/CMakeLists.txt. The module is built as library linked with main.
    • If a file or module is added, add it also to the CMakeLists.txt.
  • test/
    • For each source file in src a file that tests the implementation should be created here. The cmocka framework makes this very easy.
    • In the spirit of TDD, the tests should be written at the same time as the code.

Related Projects

  • cmake-tdd-template - A similar cmake template that is based on Catch2 framework and supports C++.
  • FreeRTOS-Emulator - Inspiration for defining the steps like test & check as build targets with cmake.

License

MIT © NikLeberg.

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.