MCPcopy Create free account
hub / github.com/aio-libs/multidict / self_test

Function self_test

tools/codegen_diff.py:254–290  ·  view source on GitHub ↗

Check that the comparison still sees differences it once missed.

()

Source from the content-addressed store, hash-verified

252
253
254def self_test():
255 """Check that the comparison still sees differences it once missed."""
256 failures = 0
257 with tempfile.TemporaryDirectory(prefix="codegen-selftest-") as tmp:
258 tmp = Path(tmp)
259 for name, (before_src, after_src) in SELF_TEST_CASES.items():
260 objects = []
261 for label, source in (("before", before_src), ("after", after_src)):
262 path = tmp / f"{label}.c"
263 path.write_text(source + "\n")
264 obj = tmp / f"{label}.o"
265 gcc(["-c", "-fPIC", "-O3", path, "-o", obj])
266 objects.append(obj)
267 _, report = compare(*objects)
268 expected = name != "unchanged"
269 ok = bool(report) is expected
270 failures += not ok
271 print(f"{'ok ' if ok else 'FAIL'} {name}")
272
273 # -fpermissive gives GCC 14 and newer the older default, where an
274 # implicit declaration is only a warning, so this also checks
275 # nothing lets it through on a compiler that still accepts it.
276 path = tmp / "undeclared.c"
277 path.write_text("int f(int v) { return undeclared(v); }\n")
278 for name, extra in (
279 ("undeclared call", []),
280 ("undeclared call, -fpermissive", ["-fpermissive"]),
281 ):
282 try:
283 gcc(["-c", "-O3", *extra, path, "-o", tmp / "undeclared.o"])
284 except BuildError:
285 ok = True
286 else:
287 ok = False
288 failures += not ok
289 print(f"{'ok ' if ok else 'FAIL'} {name}")
290 return 1 if failures else 0
291
292
293def main():

Callers 1

mainFunction · 0.85

Calls 3

gccFunction · 0.85
compareFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected