Skip to content

Commit

Permalink
Add simple test runner
Browse files Browse the repository at this point in the history
Tests mostly imported from Alejandra
  • Loading branch information
piegamesde committed May 5, 2023
1 parent 13b7904 commit 37e17e7
Show file tree
Hide file tree
Showing 77 changed files with 7,547 additions and 1 deletion.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
# nixfmt: expand
cabal-install
stylish-haskell
shellcheck
]);
});

Expand Down
4 changes: 3 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ the input.

Tests in `invalid` should return an error when formatted.

Tests in `changed` have input and output files. `nixfmt --verify foo.in.nix`
Tests in `diff` have input and output files. `nixfmt --verify < foo.in.nix`
should output exactly `foo.out.nix`.

`test.sh` runs these tests for you. Pass `--update-diff` to update the out files in `diff`.
100 changes: 100 additions & 0 deletions test/diff/apply/in.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
[
(a
b)
(
(a b)
(a b)
(a /*b*/ c)
(/*a*/ b /*c*/ d /*e*/)
)
''
otherModules=${
pkgs.writeText "other-modules.json"
(l.toJSON
(l.mapAttrs
(pname: subOutputs:
let
pkg = subOutputs.packages."${pname}".overrideAttrs (old: {
buildScript = "true";
installMethod = "copy";
});
in
"${pkg}/lib/node_modules/${pname}/node_modules")
outputs.subPackages))
}
''
{
name1 =
function
arg
{asdf = 1;};

name2 =
function
arg
{asdf = 1;}
argument;

name3 =
function
arg
{asdf = 1;}
{qwer = 12345;}
argument;
}
{
name1 = function arg {
asdf = 1;
};

name2 = function arg {
asdf = 1;
}
argument;

name3 = function arg {
asdf = 1;
} {
qwer = 12345;
}
argument;
}
{
name4 =
function
arg
{asdf = 1;}
{
qwer = 12345;
qwer2 = 54321;
}
argument;
}
{
option1 = function arg {asdf = 1;} {
qwer = 12345;
qwer2 = 54321;
}
lastArg;

option2 = function arg {asdf = 1;} {
qwer = 12345;
qwer2 = 54321;
}
lastArg;

option3 = function arg {asdf = 1;}
{
qwer = 12345;
qwer2 = 54321;
}
lastArg;
}
# https://github.com/kamadorueda/alejandra/issues/372#issuecomment-1435083516
{
outputs =
{ utils }:
# For each supported platform,
utils.lib.eachDefaultSystem (system: {});
}
]
63 changes: 63 additions & 0 deletions test/diff/apply/out.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[
(a b)
((a b) (a b) (a # b
c) ( # a
b # c
d # e
))
''
otherModules=${
pkgs.writeText "other-modules.json" (l.toJSON (l.mapAttrs
(pname: subOutputs:
let
pkg = subOutputs.packages."${pname}".overrideAttrs (old: {
buildScript = "true";
installMethod = "copy";
});
in "${pkg}/lib/node_modules/${pname}/node_modules")
outputs.subPackages))
}
''
{
name1 = function arg { asdf = 1; };

name2 = function arg { asdf = 1; } argument;

name3 = function arg { asdf = 1; } { qwer = 12345; } argument;
}
{
name1 = function arg { asdf = 1; };

name2 = function arg { asdf = 1; } argument;

name3 = function arg { asdf = 1; } { qwer = 12345; } argument;
}
{
name4 = function arg { asdf = 1; } {
qwer = 12345;
qwer2 = 54321;
} argument;
}
{
option1 = function arg { asdf = 1; } {
qwer = 12345;
qwer2 = 54321;
} lastArg;

option2 = function arg { asdf = 1; } {
qwer = 12345;
qwer2 = 54321;
} lastArg;

option3 = function arg { asdf = 1; } {
qwer = 12345;
qwer2 = 54321;
} lastArg;
}
# https://github.com/kamadorueda/alejandra/issues/372#issuecomment-1435083516
{
outputs = { utils }:
# For each supported platform,
utils.lib.eachDefaultSystem (system: { });
}
]
13 changes: 13 additions & 0 deletions test/diff/assert/in.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
(assert b ; e)
(assert b ; /*d*/ e)
(assert b /*c*/; e)
(assert b /*c*/; /*d*/ e)
(assert /*a*/ b ; e)
(assert /*a*/ b ; /*d*/ e)
(assert /*a*/ b /*c*/; e)
(assert /*a*/ b /*c*/; /*d*/ e)
( assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
( assert b;
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
]
27 changes: 27 additions & 0 deletions test/diff/assert/out.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
(assert b; e)
(assert b; # d
e)
(assert b # c
;
e)
(assert b # c
; # d
e)
(assert # a
b;
e)
(assert # a
b; # d
e)
(assert # a
b # c
;
e)
(assert # a
b # c
; # d
e)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
]
60 changes: 60 additions & 0 deletions test/diff/attr_set/in.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[
{}
{/*a*/}
{a=1;}
{a=1;
}

{ b=1; }
{ b=1; /*c*/ }
{ /*a*/ b=1; }
{ /*a*/ b=1; /*c*/ }

rec { c=1; }
rec { c=1; /*d*/ }
rec { /*b*/ c=1; }
rec { /*b*/ c=1; /*d*/ }
rec /*a*/ { c=1; }
rec /*a*/ { c=1; /*d*/ }
rec /*a*/ { /*b*/ c=1; }
rec /*a*/ { /*b*/ c=1; /*d*/ }

{
a=rec {
a={
a=rec {
a={
a=rec {a={a=rec {a={a=rec {a={};};};};};};};};};};}

rec {

c=1;


e=1;


}

rec
/*a*/
{


/*b*/


c=1;


/*d*/


e=1;


/*f*/


}
]
81 changes: 81 additions & 0 deletions test/diff/attr_set/out.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[
{ }
{ # a
}
{ a = 1; }
{ a = 1; }

{ b = 1; }
{
b = 1; # c
}
{ # a
b = 1;
}
{ # a
b = 1; # c
}

rec { c = 1; }
rec {
c = 1; # d
}
rec { # b
c = 1;
}
rec { # b
c = 1; # d
}
rec # a
{
c = 1;
}
rec # a
{
c = 1; # d
}
rec # a
{ # b
c = 1;
}
rec # a
{ # b
c = 1; # d
}

{
a = rec {
a = {
a = rec {
a = {
a = rec { a = { a = rec { a = { a = rec { a = { }; }; }; }; }; };
};
};
};
};
}

rec {

c = 1;

e = 1;

}

rec
# a
{

# b

c = 1;

# d

e = 1;

# f

}
]
Loading

0 comments on commit 37e17e7

Please sign in to comment.