Skip to content

Commit

Permalink
Use feature list for tests
Browse files Browse the repository at this point in the history
This commit adds a list of features to the output of --version
test.py and tests.json are updated to use the features instead
of relying on the curl version.
  • Loading branch information
jacobmealey authored and bagder committed May 29, 2023
1 parent f44a586 commit 3129d40
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 34 deletions.
30 changes: 6 additions & 24 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from subprocess import PIPE, run
from dataclasses import dataclass, asdict
from typing import Any, Optional
from packaging.version import parse as parse_version

PROGNAME = "trurl"
TESTFILE = "tests.json"
Expand Down Expand Up @@ -134,11 +133,7 @@ def main(argc, argv):
stdout=PIPE, stderr=PIPE,
encoding="utf-8"
)
version_re = r' libcurl\/([\w\.\-]+) \[built\-with ([\w\.\-]+)\]$'
match = re.findall(version_re, output.stdout)
libcurl_runtime, libcurl_buildtime = match[0]
libcurl_runtime = parse_version(libcurl_runtime)
libcurl_buildtime = parse_version(libcurl_buildtime)
features = output.stdout.split('\n')[1].split()[1:]

with open(path.join(baseDir, TESTFILE), "r") as file:
allTests = json.load(file)
Expand Down Expand Up @@ -166,24 +161,11 @@ def main(argc, argv):
numTestsPassed = 0
numTestsSkipped = 0
for testIndex in testIndexesToRun:
# skip tests if the run-time libcurl version is too low
if "minruntime" in allTests[testIndex]:
minruntime = allTests[testIndex]["minruntime"]
minruntime = parse_version(minruntime)
if libcurl_runtime < minruntime:
skipMessage = "libcurl run-time version is too low: "
skipMessage += f"{libcurl_runtime} < {minruntime}"
print(f"{testIndex + 1}: skipped\t{skipMessage}")
numTestsSkipped += 1
continue
# skip tests if the build-time libcurl version is too low
if "minbuildtime" in allTests[testIndex]:
minbuildtime = allTests[testIndex]["minbuildtime"]
minbuildtime = parse_version(minbuildtime)
if libcurl_buildtime < minbuildtime:
skipMessage = "libcurl build-time version is too low: "
skipMessage += f"{libcurl_buildtime} < {minbuildtime}"
print(f"{testIndex + 1}: skipped\t{skipMessage}")
# skip tests if required features are not met
if "required" in allTests[testIndex]:
required = allTests[testIndex]["required"]
if not set(required).issubset(set(features)):
print(f"Missing feature, skipping test {testIndex + 1}.")
numTestsSkipped += 1
continue

Expand Down
17 changes: 7 additions & 10 deletions tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
"{host}"
]
},
"minruntime": "7.77.0",
"required": ["normalize-ipv4"],
"expected": {
"stdout": "10.0.0.1\n",
"stderr": "",
Expand All @@ -417,7 +417,7 @@
"{host}"
]
},
"minruntime": "7.81.0",
"required": ["zone-id"],
"expected": {
"stdout": "[fe80::20c:29ff:fe9c:409b]\n",
"stderr": "",
Expand Down Expand Up @@ -760,8 +760,7 @@
"gopher:https://localhost/ with space"
]
},
"minruntime": "7.78.0",
"minbuildtime": "7.78.0",
"required": ["white-space"],
"expected": {
"stdout": "gopher:https://localhost/%20with%20space\n",
"stderr": "",
Expand All @@ -776,8 +775,7 @@
"https://localhost/?with space"
]
},
"minruntime": "7.78.0",
"minbuildtime": "7.78.0",
"required": ["white-space"],
"expected": {
"stdout": "https://localhost/?with+space\n",
"stderr": "",
Expand Down Expand Up @@ -1053,7 +1051,7 @@
"[2001:0db8:0000:0000:0000:ff00:0042:8329]"
]
},
"minruntime": "7.81.0",
"required": ["zone-id"],
"expected": {
"stdout": "https://[2001:db8::ff00:42:8329]/\n",
"stderr": "",
Expand Down Expand Up @@ -1615,7 +1613,7 @@
"{puny:url}"
]
},
"minbuildtime": "7.88.0",
"required": ["punycode"],
"expected": {
"stderr": "",
"returncode": 0,
Expand All @@ -1630,15 +1628,14 @@
"{puny:host}"
]
},
"minbuildtime": "7.88.0",
"required": ["punycode"],
"expected": {
"stderr": "",
"returncode": 0,
"stdout": "xn--rksmrgs-5wao1o.se\n"
}
},
{
"minruntime": "7.65.0",
"input": {
"arguments": [
"imaps:https://user:pasword;crazy@[ff00::1234%hello]:1234/path?a=b&c=d#fragment",
Expand Down
29 changes: 29 additions & 0 deletions trurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#define strdup _strdup
#endif

#if CURL_AT_LEAST_VERSION(7,77,0)
#define SUPPORTS_NORM_IPV4
#endif
#if CURL_AT_LEAST_VERSION(7,81,0)
#define SUPPORTS_ZONEID
#endif
Expand Down Expand Up @@ -186,6 +189,32 @@ static void show_version(void)
curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
fprintf(stdout, "%s version %s libcurl/%s [built-with %s]\n",
PROGNAME, TRURL_VERSION_TXT, data->version, LIBCURL_VERSION);
/* puny code isn't guaranteed based on the version, so it must be polled
* from libcurl */
bool supports_puny = false;
#ifdef SUPPORTS_PUNYCODE
const char *const *feature_name = data->feature_names;
while(*feature_name && !supports_puny) {
supports_puny = !strncmp(*feature_name, "IDN", 3);
feature_name++;
}
#endif

fprintf(stdout, "features: %s", supports_puny?"punycode ":"");
#ifdef SUPPORTS_ALLOW_SPACE
fprintf(stdout, "white-space ");
#endif
#ifdef SUPPORTS_ZONEID
fprintf(stdout, "zone-id ");
#endif
#ifdef SUPPORTS_URL_STRERROR
fprintf(stdout, "url-strerror ");
#endif
#ifdef SUPPORTS_NORM_IPV4
fprintf(stdout, "normalize-ipv4");
#endif

fprintf(stdout, "\n");
exit(0);
}

Expand Down

0 comments on commit 3129d40

Please sign in to comment.