unittests: cleanups

- make sure all UNITTEST prototypes mark in which unit test they are used,
  with "@unittest" markup

- make sure all UNITTEST functions do not use Curl_ prefix, as that is a
  prefix we use for global private functions and these functions are static
  and therefore not global and the prefix is wrong

- drop UNITTEST for functions not used in unit tests

- make the extract-unit-protos script highlight the above issues if found

- extract-unit-protos now also outputs the unit test number for all the
  generated protos in lib/unitprotos.h to aid readers. It also adds the source
  file and line number where the proto originates from.

- extract-unit-protos now exits with a non-zero value if any of the above
  warnings are triggered

- cf-dns: Curl_cf_dns_result => static cf_dns_result
- hostip: Curl_ipv6works => static ipv6works
- url: remove Curl_setup_conn() - not used anymore
- connect: Curl_timeleft_now_ms => UNITTEST timeleft_now_ms

Closes #21330
This commit is contained in:
Daniel Stenberg 2026-04-15 12:11:54 +02:00
parent 94f14c54b0
commit 7fd35f4c34
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
36 changed files with 248 additions and 216 deletions

View file

@ -29,18 +29,43 @@ use warnings;
my @proto;
my %func;
my %inc;
my %test;
my %from;
my $error;
sub scanfile {
my ($file) = @_;
open(F, "<$file") || die "$file failed";
my $unit = 0;
my $line = 0;
my $unitref = 0;
my $unittest = 0;
while(<F>) {
$line++;
my $full = $_;
if($_ =~ /\@unittest (\d+)/) {
$unittest = $1;
$unitref = $line; # store line number
}
if($_ =~ /^UNITTEST .*[* ]([a-z0-9_]+)\(/i) {
my $n = $1;
if($func{$n}) {
# already prototyped, this is now the function itself
}
else {
if($n =~ /^Curl_/) {
print STDERR "$file:$line:1: warn: $n is Curl_ prefixed?\n";
$error++;
}
if(($line - $unitref) > 10) {
print STDERR "$file:$line:1: warn: Missing \@unittest reference?\n";
$error++;
}
else {
$test{$full} = $unittest;
$from{$full} = "$file:$line";
}
$func{$n} = 1;
push @proto, $_;
$inc{$file} = 1;
@ -68,6 +93,10 @@ foreach my $f (@ARGV) {
scanfile($f);
}
if($error) {
exit 1;
}
print <<HEAD
#ifndef UNITTESTPROTOS_H
#define UNITTESTPROTOS_H
@ -109,6 +138,10 @@ for my $f (sort keys %inc) {
}
for my $p (@proto) {
if($test{$p}) {
printf "\n/* for unit test %d from %s */\n",
$test{$p}, $from{$p};
}
print $p;
}