You are ready to start your new C++ project from scratch and you want to go with Test Driven Development approach. Where to start? How to structure your project?
In this post series I will try to answer those questions using meson.build
as a build system.
What we want to have on top level(root) of our project:
├── include
├── meson.build
├── src
├── subprojects
└── test
include
directory will contain header files
src
directory will contain source files
subprojects
directory will contain third party projects that use meson.build
as a build system
test
directory will contain everything related to tests
meson.build
file containing build description for meson build system
I usually group header files into sub directories inside include directory:
├── include
│ ├── bar
│ │ └── random.hpp
│ │ └── ...
│ ├── foo
│ │ └── dummy.hpp
│ │ └── ...
│ └── tar
│ └── generator.hpp
│ └── ...
├── meson.build
├── src
├── subprojects
└── test
Same goes for source files, if there is source file for specific header (if is not header only):
├── include
├── meson.build
├── src
| ├── meson.build
│ ├── bar
│ │ └── random.cpp
│ │ └── ...
│ ├── foo
│ │ └── dummy.cpp
│ │ └── ...
│ └── tar
│ └── generator.cpp
│ └── ...
├── subprojects
└── test
Lets take closer look at test directory. What we actually want is to support Testing Pyramid
, so we will have something like this:
├── include
├── meson.build
├── src
├── subprojects
└── test
├── meson.build
├── unit_tests
│ └── [List of all unit tests].cpp
│ └── meson.build
├── integration_tests
│ └── [List of all integration tests].cpp
│ └── meson.build
├── component_tests
│ └── [List of all component tests].cpp
│ └── meson.build
└── system_tests
└── [List of all system tests].cpp
└── meson.build
More info about Testing Pyramid
can be found here and here
That is it for Part I. In the next Part we will see how to actually write meson.build
description file to support presented structure.
NOTE: This is my first post.
If you find this content interesting, please let me know.
Top comments (2)
First (and only) time I've found a proposal for meson directory structure... Great!
Thank you! Do you have a suggestion what to cover next? What are you struggling with?