-
-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: refactor to use callTest(s)
pattern + move calls to tests/default.nix
#2433
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,27 @@ | ||
{ self, helpers, ... }: | ||
{ | ||
self, | ||
lib, | ||
helpers, | ||
... | ||
}: | ||
{ | ||
perSystem = | ||
{ | ||
pkgs, | ||
pkgsUnfree, | ||
system, | ||
makeNixvimWithModule, | ||
self', | ||
... | ||
}: | ||
let | ||
inherit (self'.legacyPackages) nixvimConfiguration; | ||
in | ||
{ | ||
checks = { | ||
extra-args-tests = import ../tests/extra-args.nix { | ||
inherit pkgs; | ||
inherit makeNixvimWithModule; | ||
}; | ||
|
||
extend = import ../tests/extend.nix { inherit pkgs makeNixvimWithModule; }; | ||
|
||
extra-files = import ../tests/extra-files.nix { inherit pkgs makeNixvimWithModule; }; | ||
|
||
enable-except-in-tests = import ../tests/enable-except-in-tests.nix { | ||
inherit pkgs makeNixvimWithModule; | ||
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; | ||
}; | ||
|
||
failing-tests = pkgs.callPackage ../tests/failing-tests.nix { | ||
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; | ||
}; | ||
|
||
no-flake = import ../tests/no-flake.nix { | ||
inherit system; | ||
inherit (self.lib.${system}.check) mkTestDerivationFromNvim; | ||
nixvim = "${self}"; | ||
}; | ||
|
||
lib-tests = import ../tests/lib-tests.nix { | ||
inherit pkgs helpers; | ||
inherit (pkgs) lib; | ||
}; | ||
|
||
maintainers = import ../tests/maintainers.nix { inherit pkgs; }; | ||
|
||
plugins-by-name = pkgs.callPackage ../tests/plugins-by-name.nix { inherit nixvimConfiguration; }; | ||
|
||
generated = pkgs.callPackage ../tests/generated.nix { }; | ||
|
||
package-options = pkgs.callPackage ../tests/package-options.nix { inherit nixvimConfiguration; }; | ||
|
||
lsp-all-servers = pkgs.callPackage ../tests/lsp-servers.nix { inherit nixvimConfiguration; }; | ||
} // import ../tests { inherit pkgs pkgsUnfree helpers; }; | ||
checks = import ../tests { | ||
inherit | ||
helpers | ||
lib | ||
pkgs | ||
pkgsUnfree | ||
self | ||
system | ||
; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,49 @@ | ||
{ | ||
lib ? pkgs.lib, | ||
helpers, | ||
pkgs, | ||
pkgsUnfree, | ||
helpers, | ||
lib, | ||
system, | ||
self, # The flake instance | ||
}: | ||
let | ||
fetchTests = import ./fetch-tests.nix { inherit lib pkgs helpers; }; | ||
test-derivation = import ../lib/tests.nix { inherit pkgs lib; }; | ||
inherit (test-derivation) mkTestDerivationFromNixvimModule; | ||
|
||
moduleToTest = | ||
file: name: module: | ||
mkTestDerivationFromNixvimModule { | ||
inherit name; | ||
module = { | ||
_file = file; | ||
imports = [ module ]; | ||
}; | ||
pkgs = pkgsUnfree; | ||
}; | ||
|
||
# List of files containing configurations | ||
testFiles = fetchTests ./test-sources; | ||
|
||
exampleFiles = { | ||
name = "examples"; | ||
file = ../example.nix; | ||
cases = | ||
let | ||
config = import ../example.nix { inherit pkgs; }; | ||
in | ||
{ | ||
main = builtins.removeAttrs config.programs.nixvim [ | ||
# This is not available to standalone modules, only HM & NixOS Modules | ||
"enable" | ||
# This is purely an example, it does not reflect a real usage | ||
"extraConfigLua" | ||
"extraConfigVim" | ||
]; | ||
}; | ||
autoArgs = pkgs // { | ||
inherit | ||
helpers | ||
lib | ||
pkgsUnfree | ||
self | ||
system | ||
; | ||
inherit (self.legacyPackages.${system}) | ||
makeNixvimWithModule | ||
nixvimConfiguration | ||
; | ||
inherit (self.lib.${system}.check) | ||
mkTestDerivationFromNvim | ||
mkTestDerivationFromNixvimModule | ||
; | ||
# Recursive: | ||
inherit callTest callTests; | ||
}; | ||
|
||
callTest = lib.callPackageWith autoArgs; | ||
callTests = lib.callPackagesWith autoArgs; | ||
in | ||
# We attempt to build & execute all configurations | ||
lib.pipe (testFiles ++ [ exampleFiles ]) [ | ||
(builtins.map ( | ||
{ | ||
name, | ||
file, | ||
cases, | ||
}: | ||
{ | ||
inherit name; | ||
path = pkgs.linkFarm name (builtins.mapAttrs (moduleToTest file) cases); | ||
} | ||
)) | ||
(helpers.groupListBySize 10) | ||
(lib.imap1 ( | ||
i: group: rec { | ||
name = "test-${toString i}"; | ||
value = pkgs.linkFarm name group; | ||
} | ||
)) | ||
builtins.listToAttrs | ||
] | ||
{ | ||
extra-args-tests = callTest ./extra-args.nix { }; | ||
extend = callTest ./extend.nix { }; | ||
extra-files = callTest ./extra-files.nix { }; | ||
enable-except-in-tests = callTest ./enable-except-in-tests.nix { }; | ||
failing-tests = callTest ./failing-tests.nix { }; | ||
no-flake = callTest ./no-flake.nix { }; | ||
lib-tests = callTest ./lib-tests.nix { }; | ||
maintainers = callTest ./maintainers.nix { }; | ||
plugins-by-name = callTest ./plugins-by-name.nix { }; | ||
generated = callTest ./generated.nix { }; | ||
package-options = callTest ./package-options.nix { }; | ||
lsp-all-servers = callTest ./lsp-servers.nix { }; | ||
} | ||
# Tests generated from ./test-sources | ||
# Grouped as a number of link-farms in the form { test-1, test-2, ... test-N } | ||
// callTests ./main.nix { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Collects the various test modules in tests/test-sources/ and groups them into a number of test derivations | ||
{ | ||
callPackage, | ||
callTest, | ||
helpers, | ||
lib ? pkgs.lib, | ||
linkFarm, | ||
pkgs, | ||
pkgsUnfree, | ||
}: | ||
let | ||
fetchTests = callTest ./fetch-tests.nix { }; | ||
test-derivation = callPackage ../lib/tests.nix { }; | ||
inherit (test-derivation) mkTestDerivationFromNixvimModule; | ||
|
||
moduleToTest = | ||
file: name: module: | ||
mkTestDerivationFromNixvimModule { | ||
inherit name; | ||
module = { | ||
_file = file; | ||
imports = [ module ]; | ||
}; | ||
pkgs = pkgsUnfree; | ||
}; | ||
|
||
# List of files containing configurations | ||
testFiles = fetchTests ./test-sources; | ||
|
||
exampleFiles = { | ||
name = "examples"; | ||
file = ../example.nix; | ||
cases = | ||
let | ||
config = import ../example.nix { inherit pkgs; }; | ||
in | ||
{ | ||
main = builtins.removeAttrs config.programs.nixvim [ | ||
# This is not available to standalone modules, only HM & NixOS Modules | ||
"enable" | ||
# This is purely an example, it does not reflect a real usage | ||
"extraConfigLua" | ||
"extraConfigVim" | ||
]; | ||
}; | ||
}; | ||
in | ||
# We attempt to build & execute all configurations | ||
lib.pipe (testFiles ++ [ exampleFiles ]) [ | ||
(builtins.map ( | ||
{ | ||
name, | ||
file, | ||
cases, | ||
}: | ||
{ | ||
inherit name; | ||
path = linkFarm name (builtins.mapAttrs (moduleToTest file) cases); | ||
} | ||
)) | ||
(helpers.groupListBySize 10) | ||
(lib.imap1 ( | ||
i: group: rec { | ||
name = "test-${toString i}"; | ||
value = linkFarm name group; | ||
} | ||
)) | ||
builtins.listToAttrs | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better name than
main.nix
?main.nix
could be confusing, asdefault.nix
is the "main" entrypoint to a directorymodules.nix
could make sense (the file is responsible for making tests from the modules intest-sources
), but we already have amodules.nix
that tests the wrapper modules...generated.nix
could make sense too, but we already have agenerated.nix
test that tests the ci-generated files are validMaybe
modules.nix
is the way to go, if we renamed the currentmodules.nix
towrappers.nix
? But this is making the diff much larger than it really should be for a minor refactoring PR...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
modules.nix
would be better. We can do it in another PR though.