Skip to content

Commit 53b43ce

Browse files
committed
tests.nixpkgs-check-by-name: Fix and document behavior without --base
Previously, not passing `--base` would enforce the most strict checks. While there's currently no actual violation of these stricter checks, this does not match the previous behavior. This won't matter once CI passes `--base`, the code handling the optionality can be removed then.
1 parent bb08bfc commit 53b43ce

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

pkgs/test/nixpkgs-check-by-name/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ This API may be changed over time if the CI workflow making use of it is adjuste
1010

1111
- Command line: `nixpkgs-check-by-name [--base <BASE_NIXPKGS>] <NIXPKGS>`
1212
- Arguments:
13-
- `<BASE_NIXPKGS>`: The path to the Nixpkgs to check against
14-
- `<NIXPKGS>`: The path to the Nixpkgs to check
13+
- `<NIXPKGS>`: The path to the Nixpkgs to check.
14+
- `<BASE_NIXPKGS>`: The path to the Nixpkgs to use as the base to compare `<NIXPKGS>` against.
15+
This allows the strictness of checks to increase over time by only preventing _new_ violations from being introduced,
16+
while allowing violations that already existed.
17+
18+
If not specified, all violations of stricter checks are allowed.
19+
However, this flag will become required once CI passes it.
1520
- Exit code:
1621
- `0`: If the [validation](#validity-checks) is successful
1722
- `1`: If the [validation](#validity-checks) is not successful

pkgs/test/nixpkgs-check-by-name/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ pub fn process<W: io::Write>(
7575
let main_result = check_nixpkgs(main_nixpkgs, eval_accessible_paths)?;
7676
let check_result = main_result.result_map(|nixpkgs_version| {
7777
if let Some(base) = base_nixpkgs {
78-
check_nixpkgs(base, eval_accessible_paths)?.result_map(|base_nixpkgs_version| {
79-
Ok(Nixpkgs::compare(base_nixpkgs_version, nixpkgs_version))
80-
})
78+
check_nixpkgs(base, eval_accessible_paths, error_writer)?.result_map(
79+
|base_nixpkgs_version| {
80+
Ok(Nixpkgs::compare(
81+
Some(base_nixpkgs_version),
82+
nixpkgs_version,
83+
))
84+
},
85+
)
8186
} else {
82-
Ok(Nixpkgs::compare(
83-
version::Nixpkgs::default(),
84-
nixpkgs_version,
85-
))
87+
Ok(Nixpkgs::compare(None, nixpkgs_version))
8688
}
8789
})?;
8890

pkgs/test/nixpkgs-check-by-name/src/version.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,25 @@ impl Nixpkgs {
1616
/// Compares two Nixpkgs versions against each other, returning validation errors only if the
1717
/// `from` version satisfied the stricter checks, while the `to` version doesn't satisfy them
1818
/// anymore.
19-
pub fn compare(from: Self, to: Self) -> Validation<()> {
19+
pub fn compare(optional_from: Option<Self>, to: Self) -> Validation<()> {
2020
validation::sequence_(
2121
// We only loop over the current attributes,
2222
// we don't need to check ones that were removed
2323
to.attributes.into_iter().map(|(name, attr_to)| {
24-
Attribute::compare(&name, from.attributes.get(&name), &attr_to)
24+
let attr_from = if let Some(from) = &optional_from {
25+
from.attributes.get(&name)
26+
} else {
27+
// This pretends that if there's no base version to compare against, all
28+
// attributes existed without conforming to the new strictness check for
29+
// backwards compatibility.
30+
// TODO: Remove this case. This is only needed because the `--base`
31+
// argument is still optional, which doesn't need to be once CI is updated
32+
// to pass it.
33+
Some(&Attribute {
34+
empty_non_auto_called: EmptyNonAutoCalled::Invalid,
35+
})
36+
};
37+
Attribute::compare(&name, attr_from, &attr_to)
2538
}),
2639
)
2740
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import ../../mock-nixpkgs.nix { root = ./.; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(this is just here so the directory can get tracked by git)

0 commit comments

Comments
 (0)