summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/gen-vercmp-oracle.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/gen-vercmp-oracle.py b/tools/gen-vercmp-oracle.py
new file mode 100755
index 0000000..992e10c
--- /dev/null
+++ b/tools/gen-vercmp-oracle.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+"""Regenerate testcorpus/vercmp-oracle.tsv from pacman's `vercmp`.
+
+The suite used to shell out to `vercmp` 1,090 times per run to differential-test
+pkgver::vercmp_string. The verdicts are a function of the two strings and the
+pacman version that produced them, so they are recorded once here and compared
+in process instead. The live differential still exists — tests/versions.rs runs
+it when AUR_LIVE_VERCMP is set — this is the part that runs on every run.
+
+Usage: tools/gen-vercmp-oracle.py [path]
+"""
+
+import os
+import subprocess
+import sys
+
+FRAGMENTS = [
+ "1", "1.0", "1.0.0", "1.0.1", "1.1", "2", "2.0", "1.0a", "1.0rc1", "1.0.2a", "1.0.2.1",
+ "1.0.2.a", "1.0.2.aa", "1.0.2.b", "1.0.2z", "1.0z", "1.0.z", "0.9", "10", "2.24", "2.5",
+ "1.02", "1.0_2", "1.0.p", "1.0.3a", "1.0.3b", "1.a", "1a", "1.0+git", "1.0~beta", "2.0_1",
+ "1.0.x", "2024.01",
+]
+
+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+OUT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(ROOT, "testcorpus", "vercmp-oracle.tsv")
+
+
+def main():
+ pacman = subprocess.run(["pacman", "-Q", "pacman"], capture_output=True, text=True).stdout.strip()
+ rows = []
+ for a in FRAGMENTS:
+ for b in FRAGMENTS:
+ verdict = int(subprocess.run(["vercmp", a, b], capture_output=True, text=True).stdout.strip())
+ rows.append(f"{a}\t{b}\t{verdict}")
+
+ with open(OUT, "w") as handle:
+ handle.write("# pkgver::vercmp_string differential, generated by tools/gen-vercmp-oracle.py\n")
+ handle.write(f"# oracle: {pacman or 'vercmp not owned by pacman'}\n")
+ handle.write("# columns: a <TAB> b <TAB> sign(vercmp a b)\n")
+ handle.write("\n".join(rows) + "\n")
+ print(f"{OUT}: {len(rows)} rows")
+
+
+if __name__ == "__main__":
+ main()