Skip to content

Commit 1341157

Browse files
committed
📝 TEST_SOURCE_FILE() subtractive paths
1 parent cb3b816 commit 1341157

5 files changed

Lines changed: 25 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ project set up.
1515
* **`#include` relative paths & duplicate filename disambiguation**. Ceedling now fully supports relative paths in `#include` directives and `TEST_SOURCE_FILE()` build directive macros. Ceedling is now also able to distinguish files of the same name using paths in the preceding and at the command line to distinguish test files of the same name (e.g. `ceedling test:foo/file` vs. `ceedling test:bar/file`).
1616
* **Multiple file extensions per file type.** You may now provide a list of file types via `:extensions` to gather files into your project’s build. For instance, the extensions `.c` and `.cc` can now both be used together to collect all source file in your project.
1717
* **Dedicated mocks and test runner generation build tasks.** It is now possible to run the test build pipeline only up through generating mocks or test runners without running the rest of a build using `ceedling gen:mocks:<test>` and `ceedling gen:test_runner:<test>` mirroring the convention of `test:` tasks.
18+
* The `TEST_SOURCE_FILE()` build directive macro can now be used to remove source files from a test executable build. This can be handy in overriding Ceedling’s conventions for associating source files with a test executable if your project structure does not match up with Ceedling’s conventions.
1819

1920
# 🌱 Ceedling is a handy-dandy build system for C projects
2021

docs/Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Tasks mirroring command line `test:` task invocation but with an early terminati
4343

4444
Like with command line `test:` tasks, `<test>` can be `all`, a test file name, or a source file name that has a corresponding test file.
4545

46+
### Subtractive paths in `TEST_SOURCE_FILE()`
47+
The `TEST_SOURCE_FILE()` build directive macro can now be used to remove source files from a test executable build using the same `-:` filepath decorator as available in `:paths` project configuration (ex. `TEST_SOURCE_FILE("-:foo/bar/file.c")`). This can be handy in overriding Ceedling’s conventions for associating source files with a test executable if your project structure does not match up with Ceedling’s conventions.
48+
4649
### Filepath limit checks
4750
Platform filepath limits (especially Windows) can lead to mysterious build failures, especially in CI where deep project subdirectories can occur. To help track down funny business, filepaths are intercepted and their lengths logged if they are nearing or exceed the platform limit.
4851

docs/mkdocs/configuration/reference/paths.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Subtractive paths may be simple paths or globs just like any other path entry.
275275
paths with Mixins to your heart’s content. The subtractive paths are not
276276
removed until all Mixins have been merged.
277277

278-
!!! tip "The same `+:`/`-:` convention is available in test files"
278+
!!! tip "The same `+:` / `-:` convention is available in test files"
279279
The [`TEST_SOURCE_FILE()` build directive macro][test-source-file-subtractive]
280280
supports this identical notation for removing a specific source file from
281281
a test executable’s own compile/link list.

docs/mkdocs/testing-guide/build-directives.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,28 @@ conventions.
8484

8585
A `TEST_SOURCE_FILE()` entry can also be prefixed with `-:` to remove a
8686
named file from a test executable’s compile/link list outright, rather
87-
than add one. This uses the same `+:`/`-:` convention available for
87+
than add one. This uses the same `+:` / `-:` convention available for
8888
[`:paths` list entries](../configuration/reference/paths.md#subtractive-entries).
8989

90-
Unlike the override behavior above — which only cancels the one file the
91-
header/source convention would otherwise have matched to a same-named
92-
`#include` — a `-:` entry applies to the fully assembled list for a test,
93-
after every other source has already been added to it. It removes the
94-
named file regardless of how that file got there: the implicit
95-
header/source convention, a positive `TEST_SOURCE_FILE()` entry, or a
96-
[Partial](partials/index.md).
90+
Unlike the override behavior above that only modifies the header/source
91+
convention for same-named files, a `-:` decorated entry applies to the fully
92+
assembled list for a test. It removes the named file regardless of how
93+
that file was added to the list and acts only after every other source
94+
has already been added to the list.
9795

9896
This is useful whenever Ceedling’s convention of compiling and linking any
9997
`.c` file matching an `#include`d header’s name pulls in a file that
100-
shouldn’t be part of a particular test executable — for instance, a
101-
same-named file elsewhere in the project that defines a conflicting
102-
symbol and would otherwise break the link.
98+
should not be part of a particular test executable. Certain splits of
99+
headers, source, and arranging of symbols can lead to duplicate symbols
100+
if Ceedling’s convention operates without intervention.
103101

104102
As with the override behavior, Ceedling logs an informational notice
105103
naming the removed file, so a `-:` entry is never silent.
106104

105+
Like in `:paths` entries, a `+:` decorator is assumed. That is omitting any
106+
decorator yields an additive file path. The `+:` decorator is available
107+
solely for formatting or self-documentation purposes.
108+
107109
### `TEST_SOURCE_FILE()` Example
108110

109111
```c

docs/mkdocs/testing-guide/conventions.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ above, this override is logged with an informational notice naming the winning
6262
`TEST_SOURCE_FILE()` entry and the `#include` it overrode, so the substitution
6363
is not silent either.
6464

65-
A `TEST_SOURCE_FILE()` entry prefixed with `-:` goes further still, removing
66-
a named file from a test's compile/link list outright rather than winning an
67-
override — and, unlike the override above, it applies to the fully assembled
68-
list regardless of how a file arrived there (the header/source convention, a
69-
positive `TEST_SOURCE_FILE()` entry, or a Partial), not only to a same-basename
70-
match. See [`TEST_SOURCE_FILE()` Subtractive Notation][test-source-file-subtractive]
71-
for the full discussion.
72-
7365
### Test files (CLI test tasks)
7466

7567
Execute [`ceedling test:` tasks][ceedling-test] at the command line with an
@@ -231,6 +223,13 @@ directive macro `TEST_SOURCE_FILE(...)` to tell Ceedling to compile
231223
and link the desired source file into the test executable (see
232224
[macro documentation](build-directives.md)).
233225

226+
Conversely, sometimes you may need to remove from a test executable
227+
build a source file that corresponds to an `#include` directive in your
228+
test file. A `TEST_SOURCE_FILE()` entry prefixed with a `-:` decorator
229+
removes a named file from a test‘s compile/link list. See
230+
[`TEST_SOURCE_FILE()` Subtractive Notation][test-source-file-subtractive]
231+
for the full discussion.
232+
234233
That was a lot of information and many clauses in a very few
235234
sentences; the commented example test file code that follows in a
236235
bit will make it clearer.

0 commit comments

Comments
 (0)