summaryrefslogtreecommitdiffstats
path: root/tests/versions.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 19:40:38 +0000
committeraur-build <aur-build@localhost>2026-11-19 19:40:38 +0000
commitbc4916d4a7de6a60d8b73ed7e3ccc0ec0695d580 (patch)
treecff4b8b2976579b565462467fba478b6209367b1 /tests/versions.rs
parent8e4e88946e52455e78065257a46a7e6d63147101 (diff)
downloadaur-build-bc4916d4a7de6a60d8b73ed7e3ccc0ec0695d580.tar.gz
aur-build-bc4916d4a7de6a60d8b73ed7e3ccc0ec0695d580.zip
tests: record the vercmp oracle instead of spawning it 1,089 times
The differential against pacman's vercmp is the suite's second biggest process cost, and its verdicts are a function of two strings plus the pacman that produced them. They are recorded in testcorpus/vercmp-oracle.tsv now and compared in process on every run, antisymmetry of the table included. The live differential is still there - AUR_LIVE_VERCMP=1 runs it and says so when it is not run.
Diffstat (limited to 'tests/versions.rs')
-rw-r--r--tests/versions.rs56
1 files changed, 47 insertions, 9 deletions
diff --git a/tests/versions.rs b/tests/versions.rs
index b8a0b56..2d808ba 100644
--- a/tests/versions.rs
+++ b/tests/versions.rs
@@ -74,10 +74,50 @@ fn vercmp_orders_the_canonical_vectors() {
}
}
+fn sign(o: Ordering) -> i32 {
+ match o {
+ Ordering::Less => -1,
+ Ordering::Equal => 0,
+ Ordering::Greater => 1,
+ }
+}
+
#[test]
-fn vercmp_matches_the_system_oracle() {
+fn vercmp_matches_the_recorded_oracle() {
+ let table = std::fs::read_to_string(corpus_root().join("vercmp-oracle.tsv"))
+ .expect("testcorpus/vercmp-oracle.tsv; regenerate with tools/gen-vercmp-oracle.py");
+ let mut recorded = std::collections::HashMap::new();
+ let mut checked = 0;
+ for line in table.lines().filter(|l| !l.starts_with('#') && !l.is_empty()) {
+ let mut cols = line.split('\t');
+ let (a, b) = (cols.next().unwrap(), cols.next().unwrap());
+ let theirs: i32 = cols.next().unwrap().parse().expect("verdict column");
+ assert_eq!(
+ sign(pkgver::vercmp_string(a, b)),
+ theirs,
+ "vercmp({a:?}, {b:?}) disagrees with the recorded oracle"
+ );
+ checked += 1;
+ recorded.insert((a, b), theirs);
+ }
+ assert!(checked >= 1089, "the cross-product should be substantial, checked {checked}");
+ for ((a, b), verdict) in &recorded {
+ assert_eq!(
+ recorded.get(&(*b, *a)),
+ Some(&-*verdict),
+ "the recorded table is not antisymmetric at {a:?} / {b:?}"
+ );
+ }
+}
+
+#[test]
+fn the_live_vercmp_tier_is_recorded_not_silently_absent() {
+ if std::env::var("AUR_LIVE_VERCMP").is_err() {
+ println!("note: AUR_LIVE_VERCMP unset; the live vercmp differential is skipped, not passed");
+ return;
+ }
if std::process::Command::new("vercmp").arg("1").arg("2").output().is_err() {
- eprintln!("note: pacman's `vercmp` is not on PATH; skipping the differential check");
+ println!("note: AUR_LIVE_VERCMP set but pacman's vercmp is not on PATH; tier skipped");
return;
}
let fragments = [
@@ -89,19 +129,17 @@ fn vercmp_matches_the_system_oracle() {
let mut checked = 0;
for a in fragments {
for b in fragments {
- let mine = pkgver::vercmp_string(a, b) as i32;
let theirs = std::process::Command::new("vercmp")
.arg(a)
.arg(b)
.output()
.expect("vercmp");
let theirs: i32 = String::from_utf8_lossy(&theirs.stdout).trim().parse().expect("vercmp output");
- let mine = match mine {
- x if x < 0 => -1,
- 0 => 0,
- _ => 1,
- };
- assert_eq!(mine, theirs, "vercmp({a:?}, {b:?}) disagrees with pacman");
+ assert_eq!(
+ sign(pkgver::vercmp_string(a, b)),
+ theirs,
+ "vercmp({a:?}, {b:?}) disagrees with pacman"
+ );
checked += 1;
}
}