Skip to content

test: characterize the cf preprocessor before its port (Refs #1499) - #1502

Merged
zackees merged 1 commit into
obs-rust:masterfrom
vpacher:test/1499-cf-preprocessor
Oct 20, 2026
Merged

zackees merged 1 commit into
obs-rust:masterfrom
vpacher:test/1499-cf-preprocessor

Conversation

@vpacher

@vpacher vpacher commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

C-only characterization for #1499, before the Rust port of the cf preprocessor (libobs/util/cf-lexer.c.h). No libobs change.

test_cf_lexer.c already covers #define, #ifdef/#else, two errors and add/remove of defines. The new test_cf_preprocessor.c covers the rest, with the values the C code gives today, quirks included:

  • #include relative to the including file, nested, twice, a missing file, and a path that is not a string. The missing-file error text runs to the end of the source, not only the path.
  • <...> includes are skipped without an error, with or without a system include directory.
  • Macros with parameters: an argument that is a call, too few and too many arguments, a name without a call, an unterminated parameter list.
  • #undef, an unknown #undef, and a second #define of the same name (two entries; the first is used).
  • #ifndef, a block inside a skipped block, a #define in a skipped block.
  • A define that expands to another define, a backslash continuation, a # that is not first on its line.
  • #if with a number or a define value, the six comparators, a hex number, #elif/#else chains, and an #if in a skipped block. On an #if error (an undefined name, a negative number, a define with text, a macro, a wrong comparator) the line is dropped, the block is kept, and the #endif is then reported outside of a block. After a true branch, an #elif condition is reported as an unexpected token.
  • #pragma, a second #else, #else and #elif outside a block, #define without a name or with a number, empty source.

The include tests use their own directory, cf_pp_test, made in the group setup and removed in teardown. Every case checks the joined output, the token count, the define and dependency counts, the error count and text, and bnum_allocs.

Testing: the expected values come from a probe against the C libobs on macOS arm64. The test passes 13/13 on Linux x86_64 against the C libobs and against libobs-with-rust (the preprocessor is C in both). clang-format 22.1.3 and gersemi 0.25.0 clean.

🤖 Generated with Claude Code

@vpacher
vpacher requested a review from zackees as a code owner October 20, 2026 06:13
…#1499)

test_cf_lexer.c covers #define, #ifdef/#else, two errors and
add/remove of defines. The new test_cf_preprocessor.c covers the rest
of cf-lexer.c.h, with the values the C code gives today:

- #include relative to the including file, nested, twice, a missing
  file and a path that is not a string. The missing-file error text runs
  to the end of the source, not only the path.
- <...> includes are skipped without an error, with or without a system
  include directory.
- Macros with parameters, an argument that is a call, too few and too
  many arguments, a name without a call, an unterminated list.
- #undef, an unknown #undef, and a second #define of the same name (two
  entries, the first is used).
- #ifndef, a block inside a skipped block, a #define in a skipped block.
- A define that expands to another define, a backslash continuation, a
  '#' that is not first on its line.
- #if with a number or a define value, the six comparators, a hex
  number, #elif and #else chains, and an #if in a skipped block. On an
  #if error (an undefined name, a negative number, a define with text, a
  macro, a wrong comparator) the line is dropped, the block is kept and
  the #endif is then reported outside of a block. After a true branch,
  an #elif condition is reported as an unexpected token.
- #pragma, a second #else, #else and #elif outside a block, #define
  without a name or with a number, empty source.

The include tests use their own directory, cf_pp_test, made in the
group setup and removed in teardown. Every case checks the joined
output, the token count, the define and dependency counts, the error
count and text, and bnum_allocs.

The expected values come from a probe against the C libobs on macOS
arm64. The test passes on Linux x86_64 against the C libobs and the
libobs-with-rust twin (the preprocessor is C in both).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher force-pushed the test/1499-cf-preprocessor branch from e3a6ffe to 177b950 Compare October 20, 2026 06:20
@zackees
zackees added this pull request to the merge queue Oct 20, 2026
Merged via the queue into obs-rust:master with commit 4bf905d Oct 20, 2026
23 checks passed
@vpacher
vpacher deleted the test/1499-cf-preprocessor branch October 24, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants