Skip to content

unit tests: extract "private" prototypes at build time #17750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

bagder
Copy link
Member

@bagder bagder commented Jun 26, 2025

In order to do unit tests for private functions, functions that are marked UNITTEST but without a global scope in the library, functions that do not have prototypes in their corresponding header file, unit tests previously brought their own private prototype copy into the unit test.

This was error-prone when the internal function changes but the change might be missed in the unit test which then uses an outdated prototype copy for testing.

This change removes the private prototypes from unit tests and instead introduces a C file parser that parses the specific C files and extracts the necessary unit test prototypes into a generated header file for unit tests to use. This geneated lib/unitprotos.h header is then included by unit tests that need private prototypes.

TODO

  • fix for cmake builds
  • find the sources to scan in out of tree builds
  • silent build rule by default in automake (acknowledge V=1)

@bagder bagder added the tests label Jun 26, 2025
@bagder
Copy link
Member Author

bagder commented Jun 26, 2025

@vszakats would you be able to help me and do the necessary cmake version of this in lib/ as I have done in lib/Makefile.am? I'd be grateful. Thanks!

@bagder
Copy link
Member Author

bagder commented Jun 26, 2025

The build failures so far are more or less expected. This is not complete (yet).

@vszakats
Copy link
Member

@vszakats would you be able to help me and do the necessary cmake version of this in lib/ as I have done in lib/Makefile.am? I'd be grateful. Thanks!

I'll look into it!

@vszakats

This comment was marked as resolved.

@bagder bagder force-pushed the bagder/unit-private-proto branch from a81964e to 54f4d55 Compare June 29, 2025 12:33
In order to do unit tests for private functions, functions that are
marked UNITTEST but without a global scope in the library, functions
that do not have prototypes in their corresponding header file, unit
tests previously brought their own private prototype *copy* into the
unit test.

This was error-prone when the internal function changes but the change
might be missed in the unit test which then uses an outdated prototype
copy for testing.

This change removes the private prototypes from unit tests and instead
introduces a C file parser that parses the specific C files and extracts
the necessary unit test prototypes into a generated header file for unit
tests to use. This geneated lib/unitprotos.h header is then included by
unit tests that need private prototypes.

Assisted-by: Viktor Szakats
Closes #17750
@bagder bagder force-pushed the bagder/unit-private-proto branch from 95b43e9 to 896e88a Compare June 29, 2025 15:11
@bagder bagder marked this pull request as ready for review June 29, 2025 15:18
typo

Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
@bagder bagder closed this in c9bb9cd Jun 30, 2025
@bagder bagder deleted the bagder/unit-private-proto branch June 30, 2025 21:17
vszakats added a commit to vszakats/curl that referenced this pull request Jul 3, 2025
to make `ninja units-clang-tidy` target work without manually
building core components first.

Follow-up to c9bb9cd curl#17750
vszakats added a commit that referenced this pull request Jul 3, 2025
To make `ninja units-clang-tidy` target work without manually building
core components first.

Also rename the clang-tidy test target generator macro to align its name
with the built-in `add_custom_target()` function.

Follow-up to c9bb9cd #17750

Closes #17810
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants