tests: make individual test sources compile cleanly

Tidy up headers and includes to ensure all individual test source
compile cleanly (but not link). To allow running clang-tidy (and
possibly other static analyzers) on them. It also improves readability
and allows to verify them locally, without the bundle logic.

clang-tidy ignores #included C files, so it's blind to bundle C files
the include these tests. The current workaround of embedding has
a couple of downsides:. meaningless filenames and line numbers,
missing issues, messing up self header paths. Thus, running it on
individual sources would be beneficial.

Also:
- de-duplicate includes.
- untangle some includes.
- formatting/indentation fixes.
- merge `getpart.h` into `first.h`.

Ref: https://github.com/curl/curl/pull/17680#issuecomment-2991730158

Closes #17703
This commit is contained in:
Viktor Szakats 2025-06-22 01:10:59 +02:00
parent 4d4d09eb7f
commit 6a0cd4feb7
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
259 changed files with 440 additions and 570 deletions

View File

@ -97,6 +97,6 @@ foreach my $src (@src) {
}
if($any_test) {
print "\nstatic const struct entry_s s_entries[] = {\n$tlist};\n";
print "\nconst struct entry_s s_entries[] = {\n$tlist {NULL, NULL}\n};\n";
print "\n#include \"first.c\"\n";
}

View File

@ -21,6 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
int main(int argc, char **argv)
{
@ -35,7 +36,7 @@ int main(int argc, char **argv)
entry_name = argv[1];
entry_func = NULL;
for(tmp = 0; tmp < CURL_ARRAYSIZE(s_entries); ++tmp) {
for(tmp = 0; s_entries[tmp].ptr; ++tmp) {
if(strcmp(entry_name, s_entries[tmp].name) == 0) {
entry_func = s_entries[tmp].ptr;
break;

View File

@ -32,6 +32,8 @@ struct entry_s {
entry_func_t ptr;
};
extern const struct entry_s s_entries[];
#include <curl/curl.h>
#include "curlx.h"

View File

@ -23,6 +23,8 @@
***************************************************************************/
/* This is based on the PoC client of issue #11982
*/
#include "first.h"
#include <assert.h>
static void usage_h2_pausing(const char *msg)

View File

@ -21,6 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
static int my_trace(CURL *handle, curl_infotype type,
char *data, size_t size, void *userp)

View File

@ -21,6 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
static size_t write_h2ue_cb(char *ptr, size_t size, size_t nmemb, void *opaque)
{

View File

@ -21,6 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
static int verbose_d = 1;

View File

@ -21,6 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
static int verbose_u = 1;

View File

@ -21,6 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
static size_t write_tse_cb(char *ptr, size_t size, size_t nmemb, void *opaque)
{

View File

@ -23,6 +23,8 @@
***************************************************************************/
/* This is based on the PoC client of issue #11769
*/
#include "first.h"
static size_t total_read = 0;
static size_t read_callback(char *ptr, size_t size, size_t nmemb,

View File

@ -21,6 +21,8 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#ifndef CURL_DISABLE_WEBSOCKETS
static CURLcode check_recv(const struct curl_ws_frame *frame,

View File

@ -21,6 +21,8 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#ifndef CURL_DISABLE_WEBSOCKETS
static CURLcode ping(CURL *curl, const char *send_payload)

View File

@ -21,6 +21,8 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#ifdef HAVE_LOCALE_H
# include <locale.h> /* for setlocale() */
#endif
@ -130,7 +132,7 @@ int main(int argc, char **argv)
entry_name = argv[1];
entry_func = NULL;
for(tmp = 0; tmp < CURL_ARRAYSIZE(s_entries); ++tmp) {
for(tmp = 0; s_entries[tmp].ptr; ++tmp) {
if(strcmp(entry_name, s_entries[tmp].name) == 0) {
entry_func = s_entries[tmp].ptr;
break;

View File

@ -32,6 +32,8 @@ struct entry_s {
entry_func_t ptr;
};
extern const struct entry_s s_entries[];
#include "curlx.h"
#endif /* HEADER_LIBTEST_FIRST_H */

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
/*
Check range/resume returned error codes and data presence.

View File

@ -40,7 +40,7 @@ static CURLcode test_lib1308(char *URL)
char buffer[] = "test buffer";
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
fail_unless(rc == 0, "curl_formadd returned error");
/* after the first curl_formadd when there's a single entry, both pointers

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include <fcntl.h>

View File

@ -29,7 +29,7 @@
* leak in the CURLOPT_RESOLVE handling with the multi interface.
*/
#include "test.h"
#include "first.h"
#include <limits.h>

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "timediff.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -28,7 +28,7 @@
* easy transfer finds and uses the populated stuff.
*/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -28,7 +28,7 @@
* of 42 (CURLE_ABORTED_BY_CALLBACK).
*/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -26,7 +26,7 @@
* size is unknown.
*/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -28,7 +28,7 @@
* (test1515) nor a dead connection is detected (test1616).
*/
#include "test.h"
#include "first.h"
#include "testtrace.h"
#include "testutil.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
/* test case and code based on https://github.com/curl/curl/issues/2847 */

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
/* test case and code based on https://github.com/curl/curl/issues/3927 */

View File

@ -28,7 +28,7 @@
* from server http header
*/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -27,7 +27,7 @@
* from server http header
*/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -27,7 +27,7 @@
* for server and proxy
*/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "timediff.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -29,7 +29,7 @@
* because this implies that the data has been sent completely to the server.
*/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testtrace.h"
#include "testutil.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -30,7 +30,7 @@
* first connection and open a second.
*/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "testtrace.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
static CURLcode test_lib1545(char *URL)
{

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "testtrace.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -25,7 +25,7 @@
* Verify that some API functions are locked from being called inside callback
*/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -30,7 +30,7 @@
* that this test will assume to be present!
*/
#include "test.h"
#include "first.h"
#if defined(USE_LIBIDN2) || defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN)
#define USE_IDN
#endif

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -27,7 +27,7 @@
* from server http header
*/
#include "test.h"
#include "first.h"
#include <stdio.h>

View File

@ -36,7 +36,7 @@
the default TEST_HANG_TIMEOUT to avoid issues when running on overloaded
CI machines. */
#include "test.h"
#include "first.h"
#include "testutil.h"

View File

@ -24,7 +24,7 @@
/* Test suppressing the If-Modified-Since header */
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -24,7 +24,7 @@
/* Testing Retry-After header parser */
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -24,7 +24,7 @@
/* Testing CURLOPT_PROTOCOLS_STR */
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -27,7 +27,7 @@
* from server http header
*/
#include "test.h"
#include "first.h"
#include <stdio.h>

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testtrace.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
struct t1662_WriteThis {
size_t sizeleft;

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "timediff.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "timediff.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testtrace.h"
#include "testutil.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "testutil.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

View File

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "first.h"
#include "memdebug.h"

Some files were not shown because too many files have changed in this diff Show More