ThrowTheSwitch / Ceedling

Ruby-based unit testing and build system for C projects

Home Page:http://throwtheswitch.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`INCLUDE_DIR` feature similar to `TEST_FILE`

swaldhoer opened this issue · comments

For some good reasons, the project has a more complex include structure than just some/path/include.
This leads to a longer list of directories to include.
Ando so 95% of the characters of the build command line consists of include paths.
And this leads to problems, or at least inconveniences with cleeding.
Assume a project that has something like 300 files to be compiled.
The ceedling build command line for the tests is then unreadable, as there are e.g., 50 include directories from which 45 are not needed for each individual file.

An example for clarification.
The normal build of two files in the project:

  • a.c: gcc -Iinclude -Ibla1 -Iblu1 a.o
  • b.c: gcc -Iinclude -Ibla2 -Iblu2 b.o

As there are many directories that could be included the project.yml looks something like this:

:paths:
  :test:
    - +:tests/**
  :source:
    - /src/**
  :include:
    - +:include
    - +:bla1
    - +:bla2
    - +:blu1
    - +:blu2
    # and so on

Then, ceedling creates the command line:

  • a.c: gcc -Iinclude -Ibla1 -Iblu1 -Ibla2 -Iblu2 a.o
  • test_a.c: gcc -Iinclude -Ibla1 -Iblu1 -Ibla2 -Iblu2 test_a.o

For both example files, 50% of the build command is superfluous.
This is especially a problem on Windows, where the length of the command line is limited, but anyhow, it complicates a command line, and you might include things that you actually don’t want to include.

I would like to propose a feature, that works similar to TEST_FILE(...), named

INCLUDE_DIR(...).

What should this feature do:
One could have a setup like this

:paths:
  # other project setup stuff
  :include:
    - +:include

and then use in test_a.c

INCLUDE_DIR('bla1')
INCLUDE_DIR('blu1')

and these includes are applied to test_a.c as well as when compiling a.c.

I think a similar feature would be very useful for example in multi-platform projects. Where some source files need specific includes that can't be defined globally.

The branch for 0.32 now includes this feature albeit with different names and documentation forthcoming. 0.32 is still pre-release and still being worked on. Ceedling 0.32 is a significant refactoring of the tool. One big feature among several is that it now builds each test executable as a mini-project with its own defines, flags, and search paths. Two build directives (do-nothing macros in test files) are now available:

  • TEST_SOURCE_FILE() (formerly TEST_FILE()) — Tells Ceedling of a .c file to be compiled and linked into the final test executable.
  • TEST_INCLUDE_PATH() — Tells Ceedling of search paths to add for this test file, adding to any base paths already configured with [:paths][:include] in the project file. This is especially useful in large or complex projects where search paths might change per test or a lengthy command line of all search paths exceeds Windows' limit.