Skip to content

Commit d30fcbc

Browse files
committed
tests/package-option: downgrade some errors to warnings
I'm not yet planning to migrate all package options for plugins not yet using `mkVimPlugin` or `mkNeovimPlugin` since that'll happen naturally over time. So I've made it so that these options print a warning but do not fail the test.
1 parent 3128f4b commit d30fcbc

File tree

1 file changed

+62
-28
lines changed

1 file changed

+62
-28
lines changed

tests/package-options.nix

+62-28
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ let
99
inherit (builtins)
1010
filter
1111
head
12+
length
1213
map
1314
match
15+
partition
16+
toString
1417
;
1518
inherit (lib.strings) concatMapStringsSep removePrefix removeSuffix;
19+
inherit (lib.lists) last;
1620
inherit (lib.attrsets) isDerivation;
1721
inherit (lib.options)
1822
isOption
@@ -37,51 +41,81 @@ let
3741

3842
# Bad options do not use `literalExpression` in their `defaultText`,
3943
# or have a `defaultText` that doesn't start with "pkgs."
40-
badOptions = filter (
41-
opt:
42-
opt.defaultText._type or null != "literalExpression"
43-
|| match ''pkgs[.].*'' (opt.defaultText.text or "") == null
44-
) drvOptions;
44+
badOptions = lib.pipe drvOptions [
45+
(filter (
46+
opt:
47+
opt.defaultText._type or null != "literalExpression"
48+
|| match ''pkgs[.].*'' (opt.defaultText.text or "") == null
49+
))
50+
# Treat `plugins.*.package` errors as warnings
51+
# TODO: upgrade these to errors once all plugins are migrated
52+
(partition (opt: length opt.loc == 3 && last opt.loc == "package"))
53+
(
54+
{ right, wrong }:
55+
{
56+
warnings = right;
57+
errors = wrong;
58+
}
59+
)
60+
];
61+
62+
# Error strings to print
63+
toErrorStrings =
64+
let
65+
# A little hack to get the flake's source in the nix store
66+
# We will use this to make the option declaration sources more readable
67+
src = removeSuffix "modules/top-level/output.nix" (
68+
head evaluatedNixvim.options.package.declarations
69+
);
70+
in
71+
map (
72+
opt:
73+
let
74+
# The default, as rendered in documentation. Will always be a literalExpression.
75+
default = builtins.addErrorContext "while evaluating the default text for `${showOption opt.loc}`" (
76+
renderOptionValue (opt.defaultText or opt.default)
77+
);
78+
in
79+
''
80+
- ${showOption opt.loc} (${default.text}), declared in:
81+
${concatMapStringsSep "\n" (file: " - ${removePrefix src file}") opt.declarations}
82+
''
83+
);
84+
85+
# Used to print warnings during eval
86+
showWarnings =
87+
if badOptions.warnings == [ ] then
88+
lib.id
89+
else
90+
lib.warn ''
91+
92+
Found ${toString (length badOptions.warnings)} warnings:
93+
${lib.concatStrings (toErrorStrings badOptions.warnings)}
94+
(${toString (length badOptions.warnings)} options with warnings)
95+
'';
4596
in
4697
runCommandNoCCLocal "validate-package-options"
47-
{
98+
(showWarnings {
4899
# Use structuredAttrs to avoid "Argument List Too Long" errors
49100
# and get proper bash array support.
50101
__structuredAttrs = true;
51102

52103
# Passthroughs for debugging purposes
53104
passthru = {
54105
inherit evaluatedNixvim drvOptions badOptions;
106+
warnings = toErrorStrings badOptions.warnings;
55107
};
56108

57109
# Error strings to print
58-
errors =
59-
let
60-
# A little hack to get the flake's source in the nix store
61-
# We will use this to make the option declaration sources more readable
62-
src = removeSuffix "modules/top-level/output.nix" (head evaluatedNixvim.options.package.declarations);
63-
in
64-
map (
65-
opt:
66-
let
67-
# The default, as rendered in documentation. Will always be a literalExpression.
68-
default = builtins.addErrorContext "while evaluating the default text for `${showOption opt.loc}`" (
69-
renderOptionValue (opt.defaultText or opt.default)
70-
);
71-
in
72-
''
73-
- ${showOption opt.loc} (${default.text}), declared in:
74-
${concatMapStringsSep "\n" (file: " - ${removePrefix src file}") opt.declarations}
75-
''
76-
) badOptions;
77-
}
110+
errors = toErrorStrings badOptions.errors;
111+
})
78112
''
79113
if [ -n "$errors" ]; then
80-
echo "Found ''${#errors[@]} issues:"
114+
echo "Found ''${#errors[@]} errors:"
81115
for err in "''${errors[@]}"; do
82116
echo "$err"
83117
done
84-
echo "(''${#errors[@]} options with issues)"
118+
echo "(''${#errors[@]} options with errors)"
85119
exit 1
86120
fi
87121
touch $out

0 commit comments

Comments
 (0)