From fadbf69fab0d3e6dd172d962fe1eb561f11dce5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Menou?= Date: Wed, 16 Oct 2024 13:42:59 +0200 Subject: [PATCH] Actually launch tests from Garnix --- flake.nix | 8 ++++++++ helpers.nix | 9 +++++++++ tests/default.nix | 2 +- tests/lint.sh | 14 ++++++++++++++ tests/spell.sh | 15 ++++++++++++++- 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 helpers.nix create mode 100644 tests/lint.sh diff --git a/flake.nix b/flake.nix index f3e5593..a31a35e 100644 --- a/flake.nix +++ b/flake.nix @@ -28,12 +28,20 @@ overlay = _: _: { inherit posix-toolbox; }; homeManagerModule = import ./home-manager-module.nix posix-toolbox; + + helpers = pkgs.callPackages ./helpers.nix {}; + in { inherit overlay; overlays.default = overlay; packages.${system} = tests // { inherit default; }; + checks.${system} = helpers.mkChecks { + lint = "${tests.lint}/bin/posix-toolbox-lint-nix ${./.}"; + spell = "${tests.spell}/bin/posix-toolbox-spell ${./.}"; + }; + homeManagerModules.default = homeManagerModule; homeConfigurations = { diff --git a/helpers.nix b/helpers.nix new file mode 100644 index 0000000..ea6c123 --- /dev/null +++ b/helpers.nix @@ -0,0 +1,9 @@ +{ runCommand, lib }: + +let mkCheck = name: script: + runCommand name {} '' + mkdir -p $out + ${script} + ''; + +in { mkChecks = lib.attrsets.mapAttrs mkCheck; } diff --git a/tests/default.nix b/tests/default.nix index 72d0807..5058e78 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -9,7 +9,7 @@ in lint = writeShellApplication { name = "posix-toolbox-lint-nix"; runtimeInputs = [ nix-linter ]; - text = "find . -name '*.nix' -exec nix-linter {} +"; + text = builtins.readFile ./lint.sh; }; spell = writeShellApplication { name = "posix-toolbox-spell"; diff --git a/tests/lint.sh b/tests/lint.sh new file mode 100644 index 0000000..4c03e55 --- /dev/null +++ b/tests/lint.sh @@ -0,0 +1,14 @@ +set -e + +src="." +if [ $# -ge 1 ] +then + src="$1" +fi + +if [ -z "$src" ] +then + src="." +fi + +find "$src" -type f -name "*.nix" -exec nix-linter {} + && echo "Everything is fine!" diff --git a/tests/spell.sh b/tests/spell.sh index 56c3b7c..b0d726b 100644 --- a/tests/spell.sh +++ b/tests/spell.sh @@ -1,7 +1,20 @@ +set -e + +src="." +if [ $# -ge 1 ] +then + src="$1" +fi + +if [ -z "$src" ] +then + src="." +fi + function check { local filename="$1" echo "$filename" aspell list < "$filename" } -check README.md +check "$src"/README.md