mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
modules/test: provide access to expect
function
Allow `test.warnings` and `test.assertions` to be defined as either a list, or a function coerced to a list. When defined as a function, it is supplied an `expect` function which provides some syntactic-sugar for defining simple expectations. This is an alternative to the current approach of defining that `expect` function on an ad-hoc basis. I prefer this to adding `expect` to nixvim's lib because: 1. That would require having access to `lib` 2. IDK where in `lib` such a specialized function should live
This commit is contained in:
parent
16662760a9
commit
ff29c97723
3 changed files with 47 additions and 12 deletions
|
@ -76,6 +76,19 @@ let
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
expectationListType =
|
||||||
|
let
|
||||||
|
fnType = lib.mkOptionType {
|
||||||
|
name = "function";
|
||||||
|
description = "function";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = builtins.isFunction;
|
||||||
|
};
|
||||||
|
# Supply the function with an `expect` function
|
||||||
|
coerceFn = fn: fn (expect: value: { inherit expect value; });
|
||||||
|
in
|
||||||
|
lib.types.coercedTo fnType coerceFn (lib.types.listOf expectationType);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.test = {
|
options.test = {
|
||||||
|
@ -116,9 +129,22 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
warnings = lib.mkOption {
|
warnings = lib.mkOption {
|
||||||
type = lib.types.listOf expectationType;
|
type = expectationListType;
|
||||||
description = "A list of expectations for `warnings`.";
|
description = ''
|
||||||
defaultText = lib.literalMD "Expect `count == 0`";
|
A list of expectations for `warnings`.
|
||||||
|
|
||||||
|
Function definitions will be supplied a `mkExpectation` function that
|
||||||
|
enables defining simple expectations less verbosely.
|
||||||
|
'';
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
expect: [
|
||||||
|
(expect "count" 1)
|
||||||
|
(expect "any" "Hello, world!")
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
defaultText = lib.literalExpression ''
|
||||||
|
expect: [ (expect "count" 0) ]
|
||||||
|
'';
|
||||||
default = [
|
default = [
|
||||||
{
|
{
|
||||||
expect = "count";
|
expect = "count";
|
||||||
|
@ -128,9 +154,22 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
assertions = lib.mkOption {
|
assertions = lib.mkOption {
|
||||||
type = lib.types.listOf expectationType;
|
type = expectationListType;
|
||||||
description = "A list of expectations for `assertions`.";
|
description = ''
|
||||||
defaultText = lib.literalMD "Expect `count == 0`";
|
A list of expectations for `warnings`.
|
||||||
|
|
||||||
|
Function definitions will be supplied a `mkExpectation` function that
|
||||||
|
enables defining simple expectations less verbosely.
|
||||||
|
'';
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
expect: [
|
||||||
|
(expect "count" 1)
|
||||||
|
(expect "any" "Hello, world!")
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
defaultText = lib.literalExpression ''
|
||||||
|
expect: [ (expect "count" 0) ]
|
||||||
|
'';
|
||||||
default = [
|
default = [
|
||||||
{
|
{
|
||||||
expect = "count";
|
expect = "count";
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
let
|
let
|
||||||
expect = expect: value: { inherit expect value; };
|
|
||||||
|
|
||||||
# This plugin is deprecated
|
# This plugin is deprecated
|
||||||
warnings = [
|
warnings = expect: [
|
||||||
(expect "count" 1)
|
(expect "count" 1)
|
||||||
(expect "any" "this plugin is obsolete and will be removed after 24.11.")
|
(expect "any" "this plugin is obsolete and will be removed after 24.11.")
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
let
|
let
|
||||||
expect = expect: value: { inherit expect value; };
|
|
||||||
|
|
||||||
# This plugin is deprecated
|
# This plugin is deprecated
|
||||||
warnings = [
|
warnings = expect: [
|
||||||
(expect "count" 1)
|
(expect "count" 1)
|
||||||
(expect "any" "The `rust-tools` project has been abandoned.")
|
(expect "any" "The `rust-tools` project has been abandoned.")
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue