Skip to content

Commit 8b51322

Browse files
committed
test(mtree): Happy path parsing
Signed-off-by: Arne Beer <[email protected]>
1 parent f146d71 commit 8b51322

13 files changed

+1196
-0
lines changed

REUSE.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ precedence = "aggregate"
1414
SPDX-FileCopyrightText = "ALPM Contributors"
1515
SPDX-License-Identifier = "CC0-1.0"
1616
path = [
17+
"**.bash",
1718
"**.mtree",
19+
"**.pkgbuild",
1820
"**.sh",
1921
"**.snap",
2022
"**.srcinfo",
23+
"**.stub",
2124
"**.toml",
2225
"*.json",
2326
"*.lock",

alpm-srcinfo/tests/correct.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use std::{fs::read_to_string, path::PathBuf};
2+
3+
use alpm_srcinfo::{MergedPackage, SourceInfo};
4+
use alpm_types::Architecture;
5+
use insta::assert_snapshot;
6+
use rstest::rstest;
7+
use testresult::TestResult;
8+
9+
/// Get some correct SRCINFO files and make sure the JSON output is created as expected.
10+
///
11+
/// This test also looks for specific keywords in the generated output, specifically:
12+
/// - `unexpected` is used for any kind of value that shouldn't be included in the JSON output.
13+
/// - `beefc0ffee` is used to mark hex values that shouldn't be included in the JSON.
14+
///
15+
/// The SRCINFO files are generated from `*.pkgbuild` files in the `tests/correct` folder
16+
/// Each `*.pkgbuild` file contains an explanation of what it tests.
17+
/// To regenerate the SRCINFO files run the following command in the `alpm-srcinfo` project root:
18+
///
19+
/// ```sh
20+
/// ./tests/generate_srcinfo.bash tests/*/*.pkgbuild
21+
/// ```
22+
///
23+
/// `makepkg` expects changelog and INSTALL files to be in the build directory when creating
24+
/// the SRCINFO file. The script also takes care of creating those files.
25+
#[rstest]
26+
pub fn correct_files(#[files("tests/correct/*.srcinfo")] case: PathBuf) -> TestResult {
27+
// Read the input file and parse it.
28+
let input = read_to_string(&case)?;
29+
let source_info_result = SourceInfo::from_string(input.as_str());
30+
31+
// Make sure there're no parse errors
32+
let source_info_result = match source_info_result {
33+
Ok(result) => result,
34+
Err(err) => {
35+
return Err(format!(
36+
"The parser errored even though it should've succeeded the parsing step:\n{err}"
37+
)
38+
.into());
39+
}
40+
};
41+
42+
// Ensure that there're lint errors
43+
let source_info = match source_info_result.lint() {
44+
Ok(source_info) => source_info,
45+
Err(err) => {
46+
return Err(
47+
format!("The parser produce (lint) errors that weren't expected:\n {err}").into(),
48+
)
49+
}
50+
};
51+
52+
let packages = source_info
53+
.packages_for_architecture(Architecture::X86_64)
54+
.collect::<Vec<MergedPackage>>();
55+
56+
let json = serde_json::to_string_pretty(&packages)?;
57+
let name = case.file_stem().unwrap().to_str().unwrap().to_string();
58+
59+
if json.contains("unexpected") {
60+
return Err(format!(
61+
"Found 'unexpected' keyword in json output. {}:\n{json}",
62+
"This indicates that data was included that shouldn't be in there"
63+
)
64+
.into());
65+
}
66+
67+
if json.contains("beefc0ffee") {
68+
return Err(format!(
69+
"Found 'beefc0ffee' keyword in json output. {}:\n{json}",
70+
"This indicates that an checksum was included that shouldn't be in there"
71+
)
72+
.into());
73+
}
74+
75+
// Compare the generated json with the expected snapshot.
76+
// Remove the usual module prefix by explicitly setting the snapshot path.
77+
// This is necessary, as we're manually sorting snapshots by test scenario.
78+
insta::with_settings!({
79+
snapshot_path => "correct_snapshots",
80+
prepend_module_to_snapshot => false,
81+
}, {
82+
assert_snapshot!(name, json);
83+
});
84+
85+
Ok(())
86+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# This PKGBUILD file is used to ensure that all clearable properties can be cleared, on both
2+
# architecture and non-architecture specific assignments.
3+
4+
pkgname=(example)
5+
pkgver=0.1.0
6+
pkgrel=1
7+
epoch=1
8+
arch=(x86_64 aarch64)
9+
10+
pkgdesc="A example with all pkgbase properties set."
11+
url="https://archlinux.org"
12+
license=(MIT)
13+
changelog=changelog.stub
14+
install=install.sh.stub
15+
groups=(
16+
group
17+
group_2
18+
)
19+
backup=(etc/pacman.conf)
20+
options=("!lto")
21+
22+
depends=(default_dep)
23+
optdepends=(default_optdep)
24+
provides=(default_provides)
25+
conflicts=(default_conflict)
26+
replaces=(default_replaces)
27+
28+
# x86_64 specific stuff
29+
# This should show up in the test
30+
depends_x86_64=(arch_default_dep)
31+
optdepends_x86_64=(arch_default_optdep)
32+
provides_x86_64=(arch_default_provides)
33+
conflicts_x86_64=(arch_default_conflict)
34+
replaces_x86_64=(arch_default_replaces)
35+
36+
# Now clear all variables that're clearable
37+
package_example() {
38+
pkgdesc=
39+
url=
40+
license=()
41+
changelog=
42+
install=
43+
groups=()
44+
backup=()
45+
options=()
46+
47+
depends=()
48+
optdepends=()
49+
provides=()
50+
conflicts=()
51+
replaces=()
52+
53+
depends_x86_64=()
54+
optdepends_x86_64=()
55+
provides_x86_64=()
56+
conflicts_x86_64=()
57+
replaces_x86_64=()
58+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
pkgbase = example
2+
pkgdesc = A example with all pkgbase properties set.
3+
pkgver = 0.1.0
4+
pkgrel = 1
5+
epoch = 1
6+
url = https://archlinux.org
7+
install = install.sh.stub
8+
changelog = changelog.stub
9+
arch = x86_64
10+
arch = aarch64
11+
groups = group
12+
groups = group_2
13+
license = MIT
14+
depends = default_dep
15+
optdepends = default_optdep
16+
provides = default_provides
17+
conflicts = default_conflict
18+
replaces = default_replaces
19+
options = !lto
20+
backup = etc/pacman.conf
21+
provides_x86_64 = arch_default_provides
22+
conflicts_x86_64 = arch_default_conflict
23+
depends_x86_64 = arch_default_dep
24+
replaces_x86_64 = arch_default_replaces
25+
optdepends_x86_64 = arch_default_optdep
26+
27+
pkgname = example
28+
pkgdesc =
29+
url =
30+
install =
31+
changelog =
32+
groups =
33+
license =
34+
depends =
35+
optdepends =
36+
provides =
37+
conflicts =
38+
replaces =
39+
options =
40+
backup =
41+
provides_x86_64 =
42+
conflicts_x86_64 =
43+
depends_x86_64 =
44+
replaces_x86_64 =
45+
optdepends_x86_64 =
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# This PKGBUILD file is used to ensure that all overridable properties can be overridden
2+
# with both architecture and non-architecture specific assignments.
3+
4+
pkgname=(example)
5+
pkgver=0.1.0
6+
pkgrel=1
7+
epoch=1
8+
arch=(x86_64 aarch64)
9+
10+
pkgdesc="A example with all pkgbase properties set."
11+
url="https://archlinux.org"
12+
license=(MIT)
13+
changelog=changelog.stub
14+
install=install.sh.stub
15+
groups=(
16+
group
17+
group_2
18+
)
19+
backup=(etc/pacman.conf)
20+
options=("!lto")
21+
22+
depends=(default_dep)
23+
optdepends=(default_optdep)
24+
provides=(default_provides)
25+
conflicts=(default_conflict)
26+
replaces=(default_replaces)
27+
28+
# x86_64 specific stuff
29+
# This should show up in the test
30+
depends_x86_64=(arch_default_dep)
31+
optdepends_x86_64=(arch_default_optdep)
32+
provides_x86_64=(arch_default_provides)
33+
conflicts_x86_64=(arch_default_conflict)
34+
replaces_x86_64=(arch_default_replaces)
35+
36+
# Now override all variables that can be overridden
37+
package_example() {
38+
pkgdesc="overridden"
39+
url="https://overridden.com/"
40+
license=("Apache-2.0")
41+
changelog=overridden.stub
42+
install=overridden.stub
43+
groups=(overridden)
44+
backup=(overridden)
45+
options=(emptydirs)
46+
47+
depends=(overridden)
48+
optdepends=(overridden)
49+
provides=(overridden)
50+
conflicts=(overridden)
51+
replaces=(overridden)
52+
53+
depends_x86_64=(arch_overridden)
54+
optdepends_x86_64=(arch_overridden)
55+
provides_x86_64=(arch_overridden)
56+
conflicts_x86_64=(arch_overridden)
57+
replaces_x86_64=(arch_overridden)
58+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
pkgbase = example
2+
pkgdesc = A example with all pkgbase properties set.
3+
pkgver = 0.1.0
4+
pkgrel = 1
5+
epoch = 1
6+
url = https://archlinux.org
7+
install = install.sh.stub
8+
changelog = changelog.stub
9+
arch = x86_64
10+
arch = aarch64
11+
groups = group
12+
groups = group_2
13+
license = MIT
14+
depends = default_dep
15+
optdepends = default_optdep
16+
provides = default_provides
17+
conflicts = default_conflict
18+
replaces = default_replaces
19+
options = !lto
20+
backup = etc/pacman.conf
21+
provides_x86_64 = arch_default_provides
22+
conflicts_x86_64 = arch_default_conflict
23+
depends_x86_64 = arch_default_dep
24+
replaces_x86_64 = arch_default_replaces
25+
optdepends_x86_64 = arch_default_optdep
26+
27+
pkgname = example
28+
pkgdesc = overridden
29+
url = https://overridden.com/
30+
install = overridden.stub
31+
changelog = overridden.stub
32+
groups = overridden
33+
license = Apache-2.0
34+
depends = overridden
35+
optdepends = overridden
36+
provides = overridden
37+
conflicts = overridden
38+
replaces = overridden
39+
options = emptydirs
40+
backup = overridden
41+
provides_x86_64 = arch_overridden
42+
conflicts_x86_64 = arch_overridden
43+
depends_x86_64 = arch_overridden
44+
replaces_x86_64 = arch_overridden
45+
optdepends_x86_64 = arch_overridden

0 commit comments

Comments
 (0)