From b49044c9a5a461d1da87a9dc6662700a1964d3f3 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 22 Feb 2026 00:18:15 +0300 Subject: [PATCH] nix: format test fixtures via `nix fmt` Signed-off-by: NotAShelf Change-Id: Ia9c1e9b0a8cd9c6d834f153609baa5426a6a6964 --- flake.nix | 19 +++++++++++- tests/attrset_var.nix | 3 +- tests/comparison.nix | 4 ++- tests/if.nix | 4 ++- tests/inherit.nix | 25 +++++++++------- tests/inherit_from.nix | 5 ++-- tests/inherit_simple.nix | 3 +- tests/lambda_pattern.nix | 63 ++++++++++++++++++++++++++++------------ tests/let.nix | 3 +- tests/logical.nix | 6 +++- tests/precedence.nix | 16 ++++++---- tests/shortcircuit.nix | 11 ++++--- tests/simple_op.nix | 2 +- tests/string_interp.nix | 25 +++++++++------- tests/unary.nix | 6 ++-- 15 files changed, 127 insertions(+), 68 deletions(-) diff --git a/flake.nix b/flake.nix index de7e7ad..a127312 100644 --- a/flake.nix +++ b/flake.nix @@ -4,9 +4,10 @@ outputs = {nixpkgs, ...}: let systems = ["x86_64-linux" "aarch64-linux"]; forAllSystems = nixpkgs.lib.genAttrs systems; + pkgsFor = system: nixpkgs.legacyPackages.${system}; in { devShells = forAllSystems (system: let - pkgs = nixpkgs.legacyPackages.${system}; + pkgs = pkgsFor system; in { default = pkgs.mkShell { name = "nixir"; @@ -34,5 +35,21 @@ env.NIX_PLUGINABI = "0.2"; }; }); + + formatter = forAllSystems (system: let + pkgs = pkgsFor system; + in + pkgs.writeShellApplication { + name = "nix3-fmt-wrapper"; + + runtimeInputs = [ + pkgs.alejandra + pkgs.fd + ]; + + text = '' + fd "$@" -t f -e nix -x alejandra -q '{}' + ''; + }); }; } diff --git a/tests/attrset_var.nix b/tests/attrset_var.nix index 11e1da6..6f9db40 100644 --- a/tests/attrset_var.nix +++ b/tests/attrset_var.nix @@ -1,4 +1,3 @@ let x = 10; -in - { a = x; } +in {a = x;} diff --git a/tests/comparison.nix b/tests/comparison.nix index be42016..a73c226 100644 --- a/tests/comparison.nix +++ b/tests/comparison.nix @@ -3,4 +3,6 @@ let a = 10; b = 20; in - if a < b then true else false + if a < b + then true + else false diff --git a/tests/if.nix b/tests/if.nix index 0ef94a5..7e48f38 100644 --- a/tests/if.nix +++ b/tests/if.nix @@ -1,2 +1,4 @@ # Conditional test -if true then 1 else 2 +if true +then 1 +else 2 diff --git a/tests/inherit.nix b/tests/inherit.nix index 470cccc..3382979 100644 --- a/tests/inherit.nix +++ b/tests/inherit.nix @@ -2,16 +2,19 @@ let x = 10; y = 20; - attrs = { a = 1; b = 2; c = 3; }; -in - { - # Basic inherit from outer scope - inherit x y; + attrs = { + a = 1; + b = 2; + c = 3; + }; +in { + # Basic inherit from outer scope + inherit x y; - # Inherit from expression - inherit (attrs) a b; + # Inherit from expression + inherit (attrs) a b; - # Mixed - z = 30; - inherit (attrs) c; - } + # Mixed + z = 30; + inherit (attrs) c; +} diff --git a/tests/inherit_from.nix b/tests/inherit_from.nix index e2d3797..31c2a00 100644 --- a/tests/inherit_from.nix +++ b/tests/inherit_from.nix @@ -1,4 +1,3 @@ let - attrs = { a = 1; }; -in - { inherit (attrs) a; } + attrs = {a = 1;}; +in {inherit (attrs) a;} diff --git a/tests/inherit_simple.nix b/tests/inherit_simple.nix index 6c004ca..2806435 100644 --- a/tests/inherit_simple.nix +++ b/tests/inherit_simple.nix @@ -1,4 +1,3 @@ let x = 10; -in - { inherit x; } +in {inherit x;} diff --git a/tests/lambda_pattern.nix b/tests/lambda_pattern.nix index dfbef9b..6fd3910 100644 --- a/tests/lambda_pattern.nix +++ b/tests/lambda_pattern.nix @@ -1,36 +1,61 @@ # Test lambda patterns let # Basic destructuring - f1 = { a, b }: a + b; + f1 = { + a, + b, + }: + a + b; # With default values - f2 = { a, b ? 10 }: a + b; + f2 = { + a, + b ? 10, + }: + a + b; # With ellipsis (extra fields allowed) - f3 = { a, ... }: a * 2; + f3 = {a, ...}: a * 2; # Named pattern with ellipsis to allow extra fields - f4 = arg@{ a, b, ... }: a + b + arg.c; + f4 = arg @ { + a, + b, + ... + }: + a + b + arg.c; # Simple lambda (not a pattern) f5 = x: x + 1; -in - { - # Test basic destructuring - test1 = f1 { a = 3; b = 4; }; +in { + # Test basic destructuring + test1 = f1 { + a = 3; + b = 4; + }; - # Test with defaults (provide both) - test2a = f2 { a = 5; b = 6; }; + # Test with defaults (provide both) + test2a = f2 { + a = 5; + b = 6; + }; - # Test with defaults (use default for b) - test2b = f2 { a = 5; }; + # Test with defaults (use default for b) + test2b = f2 {a = 5;}; - # Test ellipsis (extra field ignored) - test3 = f3 { a = 7; extra = 999; }; + # Test ellipsis (extra field ignored) + test3 = f3 { + a = 7; + extra = 999; + }; - # Test named pattern - test4 = f4 { a = 1; b = 2; c = 3; }; + # Test named pattern + test4 = f4 { + a = 1; + b = 2; + c = 3; + }; - # Test simple lambda - test5 = f5 10; - } + # Test simple lambda + test5 = f5 10; +} diff --git a/tests/let.nix b/tests/let.nix index d9c706b..04b80ce 100644 --- a/tests/let.nix +++ b/tests/let.nix @@ -2,4 +2,5 @@ let x = 10; y = 20; -in x +in + x diff --git a/tests/logical.nix b/tests/logical.nix index e2e2dac..bae055f 100644 --- a/tests/logical.nix +++ b/tests/logical.nix @@ -3,4 +3,8 @@ let x = true; y = false; in - if x && y then 1 else if x || y then 2 else 3 + if x && y + then 1 + else if x || y + then 2 + else 3 diff --git a/tests/precedence.nix b/tests/precedence.nix index 2949308..3535775 100644 --- a/tests/precedence.nix +++ b/tests/precedence.nix @@ -1,8 +1,12 @@ # Test operator precedence let - a = 1 + 2 * 3; # Should be 1 + (2 * 3) = 7 - b = 10 - 5 - 2; # Should be (10 - 5) - 2 = 3 - c = true && false || true; # Should be (true && false) || true = true - d = 1 < 2 && 3 > 2; # Should be (1 < 2) && (3 > 2) = true -in - { a = a; b = b; c = c; d = d; } + a = 1 + 2 * 3; # Should be 1 + (2 * 3) = 7 + b = 10 - 5 - 2; # Should be (10 - 5) - 2 = 3 + c = true && false || true; # Should be (true && false) || true = true + d = 1 < 2 && 3 > 2; # Should be (1 < 2) && (3 > 2) = true +in { + a = a; + b = b; + c = c; + d = d; +} diff --git a/tests/shortcircuit.nix b/tests/shortcircuit.nix index 063bf70..2326f2c 100644 --- a/tests/shortcircuit.nix +++ b/tests/shortcircuit.nix @@ -3,9 +3,8 @@ let alwaysFalse = false; alwaysTrue = true; x = 10; -in - { - and_false = alwaysFalse && alwaysTrue; - or_true = alwaysTrue || alwaysFalse; - impl_false = alwaysFalse -> alwaysFalse; - } +in { + and_false = alwaysFalse && alwaysTrue; + or_true = alwaysTrue || alwaysFalse; + impl_false = alwaysFalse -> alwaysFalse; +} diff --git a/tests/simple_op.nix b/tests/simple_op.nix index 193df0b..e0ef584 100644 --- a/tests/simple_op.nix +++ b/tests/simple_op.nix @@ -1 +1 @@ -1 + 2 \ No newline at end of file +1 + 2 diff --git a/tests/string_interp.nix b/tests/string_interp.nix index b9ae519..af7b42d 100644 --- a/tests/string_interp.nix +++ b/tests/string_interp.nix @@ -3,17 +3,20 @@ let name = "world"; x = 42; bool_val = true; -in - { - # Simple interpolation - greeting = "Hello ${name}!"; +in { + # Simple interpolation + greeting = "Hello ${name}!"; - # Multiple interpolations - multi = "x is ${x} and name is ${name}"; + # Multiple interpolations + multi = "x is ${x} and name is ${name}"; - # Nested expression - nested = "Result: ${if bool_val then "yes" else "no"}"; + # Nested expression + nested = "Result: ${ + if bool_val + then "yes" + else "no" + }"; - # Just a string (no interpolation) - plain = "plain text"; - } + # Just a string (no interpolation) + plain = "plain text"; +} diff --git a/tests/unary.nix b/tests/unary.nix index cc7ddab..b8e0e3e 100644 --- a/tests/unary.nix +++ b/tests/unary.nix @@ -2,5 +2,7 @@ let x = 10; y = true; -in - { neg = -x; not = !y; } +in { + neg = -x; + not = !y; +}