diff --git a/modules/top-level/test.nix b/modules/top-level/test.nix index 95dc945ca9..63e6288876 100644 --- a/modules/top-level/test.nix +++ b/modules/top-level/test.nix @@ -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 { options.test = { @@ -116,9 +129,22 @@ in }; warnings = lib.mkOption { - type = lib.types.listOf expectationType; - description = "A list of expectations for `warnings`."; - defaultText = lib.literalMD "Expect `count == 0`"; + type = expectationListType; + description = '' + 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 = [ { expect = "count"; @@ -128,9 +154,22 @@ in }; assertions = lib.mkOption { - type = lib.types.listOf expectationType; - description = "A list of expectations for `assertions`."; - defaultText = lib.literalMD "Expect `count == 0`"; + type = expectationListType; + description = '' + 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 = [ { expect = "count"; diff --git a/tests/test-sources/plugins/by-name/nvim-osc52/default.nix b/tests/test-sources/plugins/by-name/nvim-osc52/default.nix index b256babed7..c275e81875 100644 --- a/tests/test-sources/plugins/by-name/nvim-osc52/default.nix +++ b/tests/test-sources/plugins/by-name/nvim-osc52/default.nix @@ -1,8 +1,6 @@ let - expect = expect: value: { inherit expect value; }; - # This plugin is deprecated - warnings = [ + warnings = expect: [ (expect "count" 1) (expect "any" "this plugin is obsolete and will be removed after 24.11.") ]; diff --git a/tests/test-sources/plugins/by-name/rust-tools/default.nix b/tests/test-sources/plugins/by-name/rust-tools/default.nix index c891998db9..4b1b62be59 100644 --- a/tests/test-sources/plugins/by-name/rust-tools/default.nix +++ b/tests/test-sources/plugins/by-name/rust-tools/default.nix @@ -1,8 +1,6 @@ let - expect = expect: value: { inherit expect value; }; - # This plugin is deprecated - warnings = [ + warnings = expect: [ (expect "count" 1) (expect "any" "The `rust-tools` project has been abandoned.") ];