Skip to content

Commit

Permalink
add flake check for format search path features
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeon committed Jul 17, 2023
1 parent 6d289ee commit 651616b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions checks/fixtures/formats/a/foo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions checks/fixtures/formats/b/bar.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions checks/fixtures/formats/c/baz.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions checks/fixtures/formats/d/quux.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
78 changes: 78 additions & 0 deletions checks/test-format-search-path.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
nixpkgs,
self,
system,
}: let
inherit
(self.packages.${system})
nixos-generate
;

pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.runCommand "test-format-search-path" {} ''
rc=$?
fail() {
rc="$?"
if (( "$#" > 0 )); then
printf 1>&2 -- "$@"
else
printf 1>&2 -- 'unknown error\n'
fi
}
run() {
${nixos-generate}/bin/nixos-generate "$@"
}
showFormatSearchPath() {
run --show-format-search-path "$@"
}
list() {
run --list "$@"
}
fixtures="${self}/checks/fixtures/formats"
builtin="${nixos-generate}/share/nixos-generator/formats"
path="$(showFormatSearchPath)" || fail 'error running nixos-generate\n'
expected="$builtin"
[[ "$path" == "$expected" ]] \
|| fail 'expected format search path to contain:\n%s\ngot:\n%s\n' "$expected" "$path"
export NIXOS_GENERATORS_FORMAT_SEARCH_PATH="''${fixtures}/c:''${fixtures}/d"
path="$(showFormatSearchPath --format-search-path "''${fixtures}/b" --format-search-path "''${fixtures}/a")" \
|| fail 'error running nixos-generate\n'
expected="\
''${fixtures}/a
''${fixtures}/b
''${fixtures}/c
''${fixtures}/d
$builtin"
[[ "$path" == "$expected" ]] \
|| fail 'expected format search path to contain:\n%s\ngot:\n%s\n' "$expected" "$path"
declare -A formats
while read -r format; do
formats["$format"]=1
done < <(list --format-search-path "''${fixtures}/b" --format-search-path "''${fixtures}/a")
for format in foo bar baz quux; do
[[ -n "''${formats["$format"]:-}" ]] \
|| fail 'expected formats to include %s\n' "$format"
done
if (( rc == 0 )); then
touch "$out"
fi
exit "$rc"
''
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@
test-customize-format = import ./checks/test-customize-format.nix {
inherit nixpkgs system;
};
test-format-search-path = import ./checks/test-format-search-path.nix {
inherit nixpkgs self system;
};
in
lib.mapAttrs makeLazyDrv (
{
Expand All @@ -159,7 +162,7 @@
nixos-generate
;

inherit test-customize-format;
inherit test-customize-format test-format-search-path;

is-formatted = import ./checks/is-formatted.nix {
pkgs = nixpkgs.legacyPackages.${system};
Expand Down

0 comments on commit 651616b

Please sign in to comment.