1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
mod common;
use std::cmp::Ordering;
use aur_build::db::model::*;
use aur_build::pipeline;
use aur_build::pkgver;
use aur_build::review::{candidates, diff};
use common::*;
// What remains here is what a unit test cannot be: both tests build a real
// package, publish it, and then move its upstream, so they need the fixture
// harness and a database. The pure comparison vectors, the chunk rule, the
// epoch rules and the dependency grammar all moved into src/pkgver/mod.rs,
// where they are unit tests of the module rather than consumers of it.
#[test]
fn a_downgrade_in_the_aur_is_flagged_not_silently_served() {
let (env, fx) = env_with_fixture("plain-make");
publish(&env, "plain-make");
fx.bump(&[("pkgver", "0.9")]);
let c = detect(&env, "plain-make");
let base = base_release(&env, &c);
let panels = diff::panels(&env.cfg, &env.db, &c, base.as_ref()).unwrap();
let version = panel(&panels, "version");
assert!(version.body.contains("DOWNGRADE"), "the version panel must call out a downgrade: {:?}", version.body);
assert!(version.body.contains("1.0-1 -> 0.9-1"), "{:?}", version.body);
assert!(pkgver::is_downgrade("1.0-1", "0.9-1"));
assert_eq!(aur_build::db::index_version(&env.db, "plain-make").unwrap().unwrap(), "1.0-1");
}
#[test]
fn an_epoch_bump_is_an_upgrade_even_though_the_version_went_down() {
let (env, fx) = env_with_fixture("epoch-bump");
publish(&env, "epoch-bump");
append_line(&fx, "epoch=1");
fx.bump(&[("pkgver", "0.9")]);
let c = detect(&env, "epoch-bump");
assert_eq!(c.epoch, "1", "the recipe's epoch must be parsed out of the PKGBUILD");
let full = c.version();
assert!(full.starts_with("1:"), "epoch belongs to the version: {full}");
assert_eq!(pkgver::vercmp(&full, "1.0-1"), Ordering::Greater, "1:0.9-1 beats 1.0-1");
assert!(!pkgver::is_downgrade("1.0-1", &full), "an epoch bump is never a downgrade");
let base = base_release(&env, &c);
let panels = diff::panels(&env.cfg, &env.db, &c, base.as_ref()).unwrap();
let version = panel(&panels, "version");
assert!(version.body.contains("epoch bump"), "the panel should name the epoch change: {:?}", version.body);
assert!(!version.body.contains("DOWNGRADE"), "an epoch bump must not read as a downgrade: {:?}", version.body);
}
// --- helpers -------------------------------------------------------------
fn publish(env: &Env, name: &str) {
let c = detect_raw(env, name);
let dd = diff::render_and_store(&env.db, &env.cfg, &c).unwrap();
let c = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap();
aur_build::review::approve::approve(&env.db, "t", c.id, &c.identity_hash, &dd, None).unwrap();
let c = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap();
let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
pipeline::run(&env.cfg, &env.db, &id).unwrap();
}
fn detect(env: &Env, name: &str) -> CandidateRow {
detect_raw(env, name)
}
fn detect_raw(env: &Env, name: &str) -> CandidateRow {
aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap();
let c = candidates::pending_candidates(&env.db).unwrap().remove(0);
diff::render_and_store(&env.db, &env.cfg, &c).unwrap();
candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap()
}
fn base_release(env: &Env, c: &CandidateRow) -> Option<ReleaseRow> {
match c.base_release_id {
Some(id) => aur_build::db::release_by_id(&env.db, id).unwrap(),
None => None,
}
}
fn panel<'a>(panels: &'a [diff::Panel], name: &str) -> &'a diff::Panel {
panels.iter().find(|p| p.name == name).unwrap_or_else(|| panic!("no {name} panel"))
}
fn append_line(fx: &Fixture, line: &str) {
let path = fx.aur.join("PKGBUILD");
let text = std::fs::read_to_string(&path).unwrap();
let out: String = text
.lines()
.flat_map(|l| {
if l.starts_with("arch=") {
[line.to_string(), l.to_string()]
} else {
[String::new(), l.to_string()]
}
})
.map(|l| format!("{l}\n"))
.collect();
let out = out.replace("\n\n", "\n");
std::fs::write(&path, out).unwrap();
git(&fx.aur, &["add", "-A"]);
git(&fx.aur, &["commit", "-q", "-m", "append"]);
}
|