2021-11-25 20:51:13 +00:00
#!/usr/bin/env bash
2023-07-18 15:20:28 +00:00
2015-02-08 20:48:38 +00:00
# This script is used to test that the module system is working as expected.
2023-07-18 15:20:28 +00:00
# Executing it runs tests for `lib.modules`, `lib.options` and `lib.types`.
2015-02-08 20:48:38 +00:00
# By default it test the version of nixpkgs which is defined in the NIX_PATH.
2023-07-18 15:20:28 +00:00
#
# Run:
# [nixpkgs]$ lib/tests/modules.sh
# or:
# [nixpkgs]$ nix-build lib/tests/release.nix
2015-02-08 20:48:38 +00:00
2021-11-25 20:53:57 +00:00
set -o errexit -o noclobber -o nounset -o pipefail
shopt -s failglob inherit_errexit
2020-03-14 19:06:04 +00:00
# https://stackoverflow.com/a/246128/6605742
2024-08-12 11:15:50 +00:00
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " >/dev/null && pwd ) "
2020-03-14 19:06:04 +00:00
cd " $DIR " /modules
2015-02-08 20:48:38 +00:00
pass = 0
fail = 0
2024-08-12 11:25:30 +00:00
# loc
# prints the location of the call of to the function that calls it
# loc n
# prints the location n levels up the call stack
2024-08-12 10:52:26 +00:00
loc( ) {
local caller depth
depth = 1
2024-08-12 11:25:30 +00:00
if [ [ $# -gt 0 ] ] ; then
depth = $1
fi
2024-08-12 10:52:26 +00:00
# ( lineno fnname file ) of the caller
caller = ( $( caller $depth ) )
echo " ${ caller [2] } : ${ caller [0] } "
}
2024-08-12 11:36:13 +00:00
line( ) {
echo "----------------------------------------"
}
logStartFailure( ) {
line
}
logEndFailure( ) {
line
echo
}
logFailure( ) {
# bold red
printf '\033[1;31mTEST FAILED\033[0m at %s\n' " $( loc 2) "
}
2015-02-08 20:48:38 +00:00
evalConfig( ) {
local attr = $1
2021-11-25 21:41:43 +00:00
shift
2021-11-25 21:01:24 +00:00
local script = " import ./default.nix { modules = [ $* ];} "
2023-12-18 20:04:36 +00:00
nix-instantiate --timeout 1 -E " $script " -A " $attr " --eval-only --show-trace --read-write-mode --json
2015-02-08 20:48:38 +00:00
}
reportFailure( ) {
local attr = $1
2021-11-25 21:41:43 +00:00
shift
2021-11-25 21:01:24 +00:00
local script = " import ./default.nix { modules = [ $* ];} "
2024-08-12 11:15:50 +00:00
echo " $ nix-instantiate -E ' $script ' -A ' $attr ' --eval-only --json "
2021-11-25 20:53:57 +00:00
evalConfig " $attr " " $@ " || true
( ( ++fail) )
2015-02-08 20:48:38 +00:00
}
2020-12-18 15:42:42 +00:00
checkConfigOutput( ) {
2015-02-08 20:48:38 +00:00
local outputContains = $1
2021-11-25 21:41:43 +00:00
shift
2022-12-28 22:39:05 +00:00
if evalConfig " $@ " 2>/dev/null | grep -E --silent " $outputContains " ; then
2021-11-25 20:53:57 +00:00
( ( ++pass) )
2020-12-18 15:42:42 +00:00
else
2024-08-12 11:36:13 +00:00
logStartFailure
echo "ACTUAL:"
2020-09-02 20:33:29 +00:00
reportFailure " $@ "
2024-08-12 11:36:13 +00:00
echo " EXPECTED: result matching ' $outputContains ' "
logFailure
logEndFailure
2020-09-02 20:33:29 +00:00
fi
2015-02-08 20:48:38 +00:00
}
checkConfigError( ) {
local errorContains = $1
2020-12-18 15:42:42 +00:00
local err = ""
2021-11-25 21:41:43 +00:00
shift
2021-11-25 20:58:35 +00:00
if err = " $( evalConfig " $@ " 2>& 1 >/dev/null) " ; then
2024-08-12 11:36:13 +00:00
logStartFailure
echo "ACTUAL: exit code 0, output:"
2020-12-18 15:42:42 +00:00
reportFailure " $@ "
2024-08-12 11:36:13 +00:00
echo "EXPECTED: non-zero exit code"
logFailure
logEndFailure
2020-12-18 15:42:42 +00:00
else
if echo " $err " | grep -zP --silent " $errorContains " ; then
2021-11-25 20:53:57 +00:00
( ( ++pass) )
2020-12-18 15:42:42 +00:00
else
2024-08-12 11:36:13 +00:00
logStartFailure
echo "ACTUAL:"
2020-12-18 15:42:42 +00:00
reportFailure " $@ "
2024-08-12 11:36:13 +00:00
echo " EXPECTED: error matching ' $errorContains ' "
logFailure
logEndFailure
2020-12-18 15:42:42 +00:00
fi
fi
2015-02-08 20:48:38 +00:00
}
2022-06-06 14:05:21 +00:00
# Shorthand meta attribute does not duplicate the config
checkConfigOutput '^"one two"$' config.result ./shorthand-meta.nix
2023-06-16 19:43:12 +00:00
checkConfigOutput '^true$' config.result ./test-mergeAttrDefinitionsWithPrio.nix
2023-07-12 19:54:57 +00:00
# Check that a module argument is passed, also when a default is available
# (but not needed)
#
# When the default is needed, we currently fail to do what the users expect, as
# we pass our own argument anyway, even if it *turns out* not to exist.
#
# The reason for this is that we don't know at invocation time what is in the
# _module.args option. That value is only available *after* all modules have been
# invoked.
#
# Hypothetically, Nix could help support this by giving access to the default
# values, through a new built-in function.
# However the default values are allowed to depend on other arguments, so those
# would have to be passed in somehow, making this not just a getter but
# something more complicated.
#
# At that point we have to wonder whether the extra complexity is worth the cost.
# Another - subjective - reason not to support it is that default values
# contradict the notion that an option has a single value, where _module.args
# is the option.
checkConfigOutput '^true$' config.result ./module-argument-default.nix
2023-09-22 18:40:03 +00:00
# gvariant
checkConfigOutput '^true$' config.assertion ./gvariant.nix
2024-07-03 08:41:01 +00:00
checkConfigOutput '"ok"' config.result ./specialArgs-lib.nix
2023-12-07 15:53:01 +00:00
# https://github.com/NixOS/nixpkgs/pull/131205
2023-12-09 19:38:29 +00:00
# We currently throw this error already in `config`, but throwing in `config.wrong1` would be acceptable.
2023-12-07 15:53:01 +00:00
checkConfigError 'It seems as if you.re trying to declare an option by placing it into .config. rather than .options.' config.wrong1 ./error-mkOption-in-config.nix
2023-12-09 19:38:29 +00:00
# We currently throw this error already in `config`, but throwing in `config.nest.wrong2` would be acceptable.
checkConfigError 'It seems as if you.re trying to declare an option by placing it into .config. rather than .options.' config.nest.wrong2 ./error-mkOption-in-config.nix
2023-12-07 15:53:01 +00:00
checkConfigError 'The option .sub.wrong2. does not exist. Definition values:' config.sub ./error-mkOption-in-submodule-config.nix
checkConfigError '.*This can happen if you e.g. declared your options in .types.submodule.' config.sub ./error-mkOption-in-submodule-config.nix
2024-01-30 18:32:34 +00:00
checkConfigError '.*A definition for option .bad. is not of type .non-empty .list of .submodule...\.' config.bad ./error-nonEmptyListOf-submodule.nix
2023-12-07 15:53:01 +00:00
2024-01-27 23:30:36 +00:00
# types.attrTag
checkConfigOutput '^true$' config.okChecks ./types-attrTag.nix
2024-01-29 08:03:08 +00:00
checkConfigError 'A definition for option .intStrings\.syntaxError. is not of type .attribute-tagged union' config.intStrings.syntaxError ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.syntaxError2. is not of type .attribute-tagged union' config.intStrings.syntaxError2 ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.syntaxError3. is not of type .attribute-tagged union' config.intStrings.syntaxError3 ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.syntaxError4. is not of type .attribute-tagged union' config.intStrings.syntaxError4 ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.mergeError. is not of type .attribute-tagged union' config.intStrings.mergeError ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.badTagError. is not of type .attribute-tagged union' config.intStrings.badTagError ./types-attrTag.nix
2024-01-27 23:30:36 +00:00
checkConfigError 'A definition for option .intStrings\.badTagTypeError\.left. is not of type .signed integer.' config.intStrings.badTagTypeError.left ./types-attrTag.nix
checkConfigError 'A definition for option .nested\.right\.left. is not of type .signed integer.' config.nested.right.left ./types-attrTag.nix
2024-04-04 08:29:56 +00:00
checkConfigError 'In attrTag, each tag value must be an option, but tag int was a bare type, not wrapped in mkOption.' config.opt.int ./types-attrTag-wrong-decl.nix
2024-01-27 23:30:36 +00:00
2023-06-26 10:50:01 +00:00
# types.pathInStore
2023-07-05 09:31:58 +00:00
checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./types.nix
checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15"' config.pathInStore.ok2 ./types.nix
checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash"' config.pathInStore.ok3 ./types.nix
2023-06-26 10:50:01 +00:00
checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ""' config.pathInStore.bad1 ./types.nix
checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store"' config.pathInStore.bad2 ./types.nix
checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/"' config.pathInStore.bad3 ./types.nix
checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/.links"' config.pathInStore.bad4 ./types.nix
checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: "/foo/bar"' config.pathInStore.bad5 ./types.nix
2015-03-16 21:38:41 +00:00
# Check boolean option.
2021-11-25 22:02:41 +00:00
checkConfigOutput '^false$' config.enable ./declare-enable.nix
2021-11-03 23:19:08 +00:00
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix
2022-12-02 10:49:10 +00:00
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*' config.enable ./define-enable-throw.nix
checkConfigError 'while evaluating a definition from `.*/define-enable-abort.nix' config.enable ./define-enable-abort.nix
checkConfigError 'while evaluating the error message for definitions for .enable., which is an option that does not exist' config.enable ./define-enable-abort.nix
2015-03-16 21:38:41 +00:00
2023-12-07 21:08:00 +00:00
# Check boolByOr type.
checkConfigOutput '^false$' config.value.falseFalse ./boolByOr.nix
checkConfigOutput '^true$' config.value.trueFalse ./boolByOr.nix
checkConfigOutput '^true$' config.value.falseTrue ./boolByOr.nix
checkConfigOutput '^true$' config.value.trueTrue ./boolByOr.nix
2022-01-24 14:58:17 +00:00
checkConfigOutput '^1$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix
checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix
checkConfigOutput '^42$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix
checkConfigOutput '^420$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix
2022-02-28 21:57:03 +00:00
checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./define-shorthandOnlyDefinesConfig-true.nix
2022-03-07 10:20:30 +00:00
checkConfigError 'The option .bare-submodule.deep. in .*/declare-bare-submodule-deep-option.nix. is already declared in .*/declare-bare-submodule-deep-option-duplicate.nix' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./declare-bare-submodule-deep-option-duplicate.nix
2022-01-24 14:58:17 +00:00
2017-10-31 13:23:05 +00:00
# Check integer types.
# unsigned
2021-11-25 22:02:41 +00:00
checkConfigOutput '^42$' config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix
2021-11-03 23:19:08 +00:00
checkConfigError 'A definition for option .* is not of type.*unsigned integer.*. Definition values:\n\s*- In .*: -23' config.value ./declare-int-unsigned-value.nix ./define-value-int-negative.nix
2017-10-31 16:30:15 +00:00
# positive
2021-11-03 23:19:08 +00:00
checkConfigError 'A definition for option .* is not of type.*positive integer.*. Definition values:\n\s*- In .*: 0' config.value ./declare-int-positive-value.nix ./define-value-int-zero.nix
2017-10-31 13:23:05 +00:00
# between
2021-11-25 22:02:41 +00:00
checkConfigOutput '^42$' config.value ./declare-int-between-value.nix ./define-value-int-positive.nix
2021-11-03 23:19:08 +00:00
checkConfigError 'A definition for option .* is not of type.*between.*-21 and 43.*inclusive.*. Definition values:\n\s*- In .*: -23' config.value ./declare-int-between-value.nix ./define-value-int-negative.nix
2017-10-31 13:23:05 +00:00
2019-08-01 13:55:33 +00:00
# Check either types
# types.either
2021-11-25 22:02:41 +00:00
checkConfigOutput '^42$' config.value ./declare-either.nix ./define-value-int-positive.nix
checkConfigOutput '^"24"$' config.value ./declare-either.nix ./define-value-string.nix
2019-08-01 13:55:33 +00:00
# types.oneOf
2021-11-25 22:02:41 +00:00
checkConfigOutput '^42$' config.value ./declare-oneOf.nix ./define-value-int-positive.nix
2023-12-18 20:04:36 +00:00
checkConfigOutput '^\[\]$' config.value ./declare-oneOf.nix ./define-value-list.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"24"$' config.value ./declare-oneOf.nix ./define-value-string.nix
2019-08-01 13:55:33 +00:00
2015-03-16 21:38:41 +00:00
# Check mkForce without submodules.
2015-02-08 20:48:38 +00:00
set -- config.enable ./declare-enable.nix ./define-enable.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' " $@ "
checkConfigOutput '^false$' " $@ " ./define-force-enable.nix
checkConfigOutput '^false$' " $@ " ./define-enable-force.nix
2015-02-08 20:48:38 +00:00
2015-03-16 21:38:41 +00:00
# Check mkForce with option and submodules.
2019-06-13 21:53:03 +00:00
checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^false$' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix
2019-06-13 21:53:03 +00:00
set -- config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo-enable.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' " $@ "
checkConfigOutput '^false$' " $@ " ./define-force-attrsOfSub-foo-enable.nix
checkConfigOutput '^false$' " $@ " ./define-attrsOfSub-force-foo-enable.nix
checkConfigOutput '^false$' " $@ " ./define-attrsOfSub-foo-force-enable.nix
checkConfigOutput '^false$' " $@ " ./define-attrsOfSub-foo-enable-force.nix
2015-02-08 20:48:38 +00:00
2015-03-16 21:38:41 +00:00
# Check overriding effect of mkForce on submodule definitions.
2019-06-13 21:53:03 +00:00
checkConfigError 'attribute .*bar.* .* not found' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^false$' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar.nix
2019-06-13 21:53:03 +00:00
set -- config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar-enable.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' " $@ "
2019-06-13 21:53:03 +00:00
checkConfigError 'attribute .*bar.* .* not found' " $@ " ./define-force-attrsOfSub-foo-enable.nix
checkConfigError 'attribute .*bar.* .* not found' " $@ " ./define-attrsOfSub-force-foo-enable.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' " $@ " ./define-attrsOfSub-foo-force-enable.nix
checkConfigOutput '^true$' " $@ " ./define-attrsOfSub-foo-enable-force.nix
2015-02-08 20:48:38 +00:00
2015-03-16 21:38:41 +00:00
# Check mkIf with submodules.
2019-06-13 21:53:03 +00:00
checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-any-enable.nix
set -- config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-any-enable.nix
checkConfigError 'attribute .*foo.* .* not found' " $@ " ./define-if-attrsOfSub-foo-enable.nix
checkConfigError 'attribute .*foo.* .* not found' " $@ " ./define-attrsOfSub-if-foo-enable.nix
checkConfigError 'attribute .*foo.* .* not found' " $@ " ./define-attrsOfSub-foo-if-enable.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^false$' " $@ " ./define-attrsOfSub-foo-enable-if.nix
checkConfigOutput '^true$' " $@ " ./define-enable.nix ./define-if-attrsOfSub-foo-enable.nix
checkConfigOutput '^true$' " $@ " ./define-enable.nix ./define-attrsOfSub-if-foo-enable.nix
checkConfigOutput '^true$' " $@ " ./define-enable.nix ./define-attrsOfSub-foo-if-enable.nix
checkConfigOutput '^true$' " $@ " ./define-enable.nix ./define-attrsOfSub-foo-enable-if.nix
2015-03-16 21:38:41 +00:00
2024-08-30 23:12:43 +00:00
# Check importApply
checkConfigOutput '"abc"' config.value ./importApply.nix
# importApply does not set a key.
# Disabling the function file is not sufficient, because importApply can't reasonably assume that the key is unique.
# e.g. user may call it multiple times with different arguments and expect each of the module to apply.
# While this is excusable for the disabledModules aspect, it is not for the deduplication of modules.
checkConfigOutput '"abc"' config.value ./importApply-disabling.nix
2017-02-14 22:18:44 +00:00
# Check disabledModules with config definitions and option declarations.
set -- config.enable ./define-enable.nix ./declare-enable.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' " $@ "
checkConfigOutput '^false$' " $@ " ./disable-define-enable.nix
2022-08-25 12:03:57 +00:00
checkConfigOutput '^false$' " $@ " ./disable-define-enable-string-path.nix
2021-11-03 23:19:08 +00:00
checkConfigError "The option .*enable.* does not exist. Definition values:\n\s*- In .*: true" " $@ " ./disable-declare-enable.nix
2017-02-14 22:18:44 +00:00
checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" " $@ " ./disable-define-enable.nix ./disable-declare-enable.nix
checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" " $@ " ./disable-enable-modules.nix
2023-01-20 23:58:47 +00:00
checkConfigOutput '^true$' 'config.positive.enable' ./disable-module-with-key.nix
checkConfigOutput '^false$' 'config.negative.enable' ./disable-module-with-key.nix
checkConfigError 'Module ..*disable-module-bad-key.nix. contains a disabledModules item that is an attribute set, presumably a module, that does not have a .key. attribute. .*' 'config.enable' ./disable-module-bad-key.nix
# Not sure if we want to keep supporting module keys that aren't strings, paths or v?key, but we shouldn't remove support accidentally.
checkConfigOutput '^true$' 'config.positive.enable' ./disable-module-with-toString-key.nix
checkConfigOutput '^false$' 'config.negative.enable' ./disable-module-with-toString-key.nix
2015-03-16 21:38:41 +00:00
# Check _module.args.
2015-05-13 20:44:04 +00:00
set -- config.enable ./declare-enable.nix ./define-enable-with-custom-arg.nix
checkConfigError 'while evaluating the module argument .*custom.* in .*define-enable-with-custom-arg.nix.*:' " $@ "
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' " $@ " ./define-_module-args-custom.nix
2015-05-13 20:44:04 +00:00
# Check that using _module.args on imports cause infinite recursions, with
# the proper error context.
set -- " $@ " ./define-_module-args-custom.nix ./import-custom-arg.nix
checkConfigError 'while evaluating the module argument .*custom.* in .*import-custom-arg.nix.*:' " $@ "
checkConfigError 'infinite recursion encountered' " $@ "
2015-03-16 21:38:41 +00:00
# Check _module.check.
2019-06-13 21:53:03 +00:00
set -- config.enable ./declare-enable.nix ./define-enable.nix ./define-attrsOfSub-foo.nix
2021-11-03 23:19:08 +00:00
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*' " $@ "
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' " $@ " ./define-module-check.nix
2015-03-16 21:38:41 +00:00
2017-02-01 22:52:40 +00:00
# Check coerced value.
2023-02-07 19:39:56 +00:00
set --
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"42"$' config.value ./declare-coerced-value.nix
checkConfigOutput '^"24"$' config.value ./declare-coerced-value.nix ./define-value-string.nix
2021-11-03 23:19:08 +00:00
checkConfigError 'A definition for option .* is not.*string or signed integer convertible to it.*. Definition values:\n\s*- In .*: \[ \]' config.value ./declare-coerced-value.nix ./define-value-list.nix
2017-02-01 22:52:40 +00:00
2024-09-10 21:45:27 +00:00
# Check coerced option merging.
checkConfigError 'The option .value. in .*/declare-coerced-value.nix. is already declared in .*/declare-coerced-value-no-default.nix.' config.value ./declare-coerced-value.nix ./declare-coerced-value-no-default.nix
2018-04-04 14:51:46 +00:00
# Check coerced value with unsound coercion
2021-11-25 22:02:41 +00:00
checkConfigOutput '^12$' config.value ./declare-coerced-value-unsound.nix
2021-11-03 23:19:08 +00:00
checkConfigError 'A definition for option .* is not of type .*. Definition values:\n\s*- In .*: "1000"' config.value ./declare-coerced-value-unsound.nix ./define-value-string-bigint.nix
2022-07-10 00:12:31 +00:00
checkConfigError 'toInt: Could not convert .* to int' config.value ./declare-coerced-value-unsound.nix ./define-value-string-arbitrary.nix
2018-04-04 14:51:46 +00:00
2019-01-24 03:58:33 +00:00
# Check mkAliasOptionModule.
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.enable ./alias-with-priority.nix
checkConfigOutput '^true$' config.enableAlias ./alias-with-priority.nix
checkConfigOutput '^false$' config.enable ./alias-with-priority-can-override.nix
checkConfigOutput '^false$' config.enableAlias ./alias-with-priority-can-override.nix
2019-01-04 07:34:59 +00:00
2023-05-20 16:23:41 +00:00
# Check mkPackageOption
checkConfigOutput '^"hello"$' config.package.pname ./declare-mkPackageOption.nix
2023-10-06 11:28:46 +00:00
checkConfigOutput '^"hello"$' config.namedPackage.pname ./declare-mkPackageOption.nix
checkConfigOutput '^".*Hello.*"$' options.namedPackage.description ./declare-mkPackageOption.nix
checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix
checkConfigOutput '^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text ./declare-mkPackageOption.nix
checkConfigOutput '^".*Example extra description\..*"$' options.packageWithExtraDescription.description ./declare-mkPackageOption.nix
2024-08-30 09:31:26 +00:00
checkConfigError 'The option .undefinedPackage. was accessed but has no value defined. Try setting the option.' config.undefinedPackage ./declare-mkPackageOption.nix
2023-05-20 16:23:41 +00:00
checkConfigOutput '^null$' config.nullablePackage ./declare-mkPackageOption.nix
2023-10-06 11:28:46 +00:00
checkConfigOutput '^"null or package"$' options.nullablePackageWithDefault.type.description ./declare-mkPackageOption.nix
2023-10-06 11:32:49 +00:00
checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./declare-mkPackageOption.nix
checkConfigOutput '^"hello-other"$' options.packageFromOtherSet.default.pname ./declare-mkPackageOption.nix
2023-05-20 16:23:41 +00:00
2020-01-01 00:11:45 +00:00
# submoduleWith
## specialArgs should work
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"foo"$' config.submodule.foo ./declare-submoduleWith-special.nix
2020-01-01 00:11:45 +00:00
## shorthandOnlyDefines config behaves as expected
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-shorthand.nix
2020-01-01 00:11:45 +00:00
checkConfigError 'is not of type `boolean' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-noshorthand.nix
2023-07-11 10:48:16 +00:00
checkConfigError "In module ..*define-submoduleWith-shorthand.nix., you're trying to define a value of type \`bool'\n\s*rather than an attribute set for the option" config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-shorthand.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-noshorthand.nix
2020-01-01 00:11:45 +00:00
## submoduleWith should merge all modules in one swoop
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.submodule.inner ./declare-submoduleWith-modules.nix
checkConfigOutput '^true$' config.submodule.outer ./declare-submoduleWith-modules.nix
2020-09-29 23:49:58 +00:00
# Should also be able to evaluate the type name (which evaluates freeformType,
# which evaluates all the modules defined by the type)
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submoduleWith-modules.nix
2020-01-01 00:11:45 +00:00
2021-10-27 18:42:05 +00:00
## submodules can be declared using (evalModules {...}).type
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.submodule.inner ./declare-submodule-via-evalModules.nix
checkConfigOutput '^true$' config.submodule.outer ./declare-submodule-via-evalModules.nix
2021-10-27 18:42:05 +00:00
# Should also be able to evaluate the type name (which evaluates freeformType,
# which evaluates all the modules defined by the type)
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submodule-via-evalModules.nix
2021-10-27 18:42:05 +00:00
2020-01-01 00:11:45 +00:00
## Paths should be allowed as values and work as expected
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.submodule.enable ./declare-submoduleWith-path.nix
2020-01-01 00:11:45 +00:00
2022-05-18 16:42:18 +00:00
## deferredModule
# default module is merged into nodes.foo
2022-03-10 21:45:41 +00:00
checkConfigOutput '"beta"' config.nodes.foo.settingsDict.c ./deferred-module.nix
2022-05-18 16:42:18 +00:00
# errors from the default module are reported with accurate location
2022-05-18 16:46:35 +00:00
checkConfigError 'In `the-file-that-contains-the-bad-config.nix, via option default' \' ': "bogus"' config.nodes.foo.bottom ./deferred-module.nix
2022-06-14 21:12:46 +00:00
checkConfigError '.*lib/tests/modules/deferred-module-error.nix, via option deferred [(]:anon-1:anon-1:anon-1[)] does not look like a module.' config.result ./deferred-module-error.nix
2022-03-10 21:45:41 +00:00
2020-09-27 15:15:57 +00:00
# Check the file location information is propagated into submodules
checkConfigOutput the-file.nix config.submodule.internalFiles.0 ./submoduleFiles.nix
2020-01-04 01:01:21 +00:00
# Check that disabledModules works recursively and correctly
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.enable ./disable-recursive/main.nix
checkConfigOutput '^true$' config.enable ./disable-recursive/{ main.nix,disable-foo.nix}
checkConfigOutput '^true$' config.enable ./disable-recursive/{ main.nix,disable-bar.nix}
2021-11-03 23:19:08 +00:00
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./disable-recursive/{ main.nix,disable-foo.nix,disable-bar.nix}
2020-01-04 01:01:21 +00:00
2020-01-10 03:11:53 +00:00
# Check that imports can depend on derivations
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.enable ./import-from-store.nix
2020-01-10 03:11:53 +00:00
2020-03-17 19:21:10 +00:00
# Check that configs can be conditional on option existence
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.enable ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix
checkConfigOutput '^360$' config.value ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix
checkConfigOutput '^7$' config.value ./define-option-dependently.nix ./declare-int-positive-value.nix
checkConfigOutput '^true$' config.set.enable ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix
checkConfigOutput '^360$' config.set.value ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix
checkConfigOutput '^7$' config.set.value ./define-option-dependently-nested.nix ./declare-int-positive-value-nested.nix
2020-03-17 19:21:10 +00:00
2019-10-12 18:37:21 +00:00
# Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only
# attrsOf should work with conditional definitions
# In addition, lazyAttrsOf should honor an options emptyValue
checkConfigError "is not lazy" config.isLazy ./declare-attrsOf.nix ./attrsOf-lazy-check.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.isLazy ./declare-lazyAttrsOf.nix ./attrsOf-lazy-check.nix
checkConfigOutput '^true$' config.conditionalWorks ./declare-attrsOf.nix ./attrsOf-conditional-check.nix
checkConfigOutput '^false$' config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
checkConfigOutput '^"empty"$' config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
2019-10-12 18:37:21 +00:00
2020-03-16 20:08:39 +00:00
2020-03-16 20:10:05 +00:00
# Even with multiple assignments, a type error should be thrown if any of them aren't valid
2020-09-17 11:36:38 +00:00
checkConfigError 'A definition for option .* is not of type .*' \
2020-03-16 20:10:05 +00:00
config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix
2020-03-22 19:55:54 +00:00
## Freeform modules
# Assigning without a declared option should work
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix
2023-04-10 15:26:25 +00:00
# Shorthand modules interpret `meta` and `class` as config items
checkConfigOutput '^true$' options._module.args.value.result ./freeform-attrsOf.nix ./define-freeform-keywords-shorthand.nix
2022-12-17 23:59:29 +00:00
# No freeform assignments shouldn't make it error
2023-12-18 20:04:36 +00:00
checkConfigOutput '^{}$' config ./freeform-attrsOf.nix
2020-03-22 19:55:54 +00:00
# but only if the type matches
2020-09-17 11:36:38 +00:00
checkConfigError 'A definition for option .* is not of type .*' config.value ./freeform-attrsOf.nix ./define-value-list.nix
2020-03-22 19:55:54 +00:00
# and properties should be applied
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"yes"$' config.value ./freeform-attrsOf.nix ./define-value-string-properties.nix
2020-03-22 19:55:54 +00:00
# Options should still be declarable, and be able to have a type that doesn't match the freeform type
2021-11-25 22:02:41 +00:00
checkConfigOutput '^false$' config.enable ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix
checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix
2020-03-22 19:55:54 +00:00
# and this should work too with nested values
2021-11-25 22:02:41 +00:00
checkConfigOutput '^false$' config.nest.foo ./freeform-attrsOf.nix ./freeform-nested.nix
checkConfigOutput '^"bar"$' config.nest.bar ./freeform-attrsOf.nix ./freeform-nested.nix
2020-03-22 19:55:54 +00:00
# Check whether a declared option can depend on an freeform-typed one
2021-11-25 22:02:41 +00:00
checkConfigOutput '^null$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix
checkConfigOutput '^"24"$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix ./define-value-string.nix
2020-03-22 19:55:54 +00:00
# Check whether an freeform-typed value can depend on a declared option, this can only work with lazyAttrsOf
checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.nix ./freeform-unstr-dep-str.nix
2024-08-30 09:31:26 +00:00
checkConfigError 'The option .* was accessed but has no value defined. Try setting the option.' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"24"$' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix
2021-12-08 18:13:14 +00:00
# submodules in freeformTypes should have their locations annotated
checkConfigOutput '/freeform-submodules.nix"$' config.fooDeclarations.0 ./freeform-submodules.nix
# freeformTypes can get merged using `types.type`, including submodules
checkConfigOutput '^10$' config.free.xxx.foo ./freeform-submodules.nix
checkConfigOutput '^10$' config.free.yyy.bar ./freeform-submodules.nix
2020-03-22 19:55:54 +00:00
2020-09-04 13:27:26 +00:00
## types.anything
# Check that attribute sets are merged recursively
2021-11-25 22:02:41 +00:00
checkConfigOutput '^null$' config.value.foo ./types-anything/nested-attrs.nix
checkConfigOutput '^null$' config.value.l1.foo ./types-anything/nested-attrs.nix
checkConfigOutput '^null$' config.value.l1.l2.foo ./types-anything/nested-attrs.nix
checkConfigOutput '^null$' config.value.l1.l2.l3.foo ./types-anything/nested-attrs.nix
2020-09-04 13:27:26 +00:00
# Attribute sets that are coercible to strings shouldn't be recursed into
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"foo"$' config.value.outPath ./types-anything/attrs-coercible.nix
2024-09-06 19:23:42 +00:00
# Multiple lists aren't concatenated together if their definitions are not equal
checkConfigError 'The option .* has conflicting definition values' config.value ./types-anything/lists.nix
2020-09-04 13:27:26 +00:00
# Check that all equalizable atoms can be used as long as all definitions are equal
2021-11-25 22:02:41 +00:00
checkConfigOutput '^0$' config.value.int ./types-anything/equal-atoms.nix
checkConfigOutput '^false$' config.value.bool ./types-anything/equal-atoms.nix
checkConfigOutput '^""$' config.value.string ./types-anything/equal-atoms.nix
2023-12-18 20:04:36 +00:00
checkConfigOutput '^"/[^"]+"$' config.value.path ./types-anything/equal-atoms.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^null$' config.value.null ./types-anything/equal-atoms.nix
checkConfigOutput '^0.1$' config.value.float ./types-anything/equal-atoms.nix
2024-09-06 19:23:42 +00:00
checkConfigOutput '^\[1,"a",{"x":null}\]$' config.value.list ./types-anything/equal-atoms.nix
2020-09-04 13:27:26 +00:00
# Functions can't be merged together
2021-10-02 14:37:22 +00:00
checkConfigError "The option .value.multiple-lambdas.<function body>. has conflicting option types" config.applied.multiple-lambdas ./types-anything/functions.nix
2023-12-18 20:04:36 +00:00
checkConfigOutput '^true$' config.valueIsFunction.single-lambda ./types-anything/functions.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^null$' config.applied.merging-lambdas.x ./types-anything/functions.nix
checkConfigOutput '^null$' config.applied.merging-lambdas.y ./types-anything/functions.nix
2020-09-04 13:27:26 +00:00
# Check that all mk* modifiers are applied
checkConfigError 'attribute .* not found' config.value.mkiffalse ./types-anything/mk-mods.nix
2023-12-18 20:04:36 +00:00
checkConfigOutput '^{}$' config.value.mkiftrue ./types-anything/mk-mods.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^1$' config.value.mkdefault ./types-anything/mk-mods.nix
2023-12-18 20:04:36 +00:00
checkConfigOutput '^{}$' config.value.mkmerge ./types-anything/mk-mods.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^true$' config.value.mkbefore ./types-anything/mk-mods.nix
checkConfigOutput '^1$' config.value.nested.foo ./types-anything/mk-mods.nix
checkConfigOutput '^"baz"$' config.value.nested.bar.baz ./types-anything/mk-mods.nix
2020-09-04 13:27:26 +00:00
2021-01-26 21:30:07 +00:00
## types.functionTo
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"input is input"$' config.result ./functionTo/trivial.nix
checkConfigOutput '^"a b"$' config.result ./functionTo/merging-list.nix
2022-10-07 07:58:55 +00:00
checkConfigError 'A definition for option .fun.<function body>. is not of type .string.. Definition values:\n\s*- In .*wrong-type.nix' config.result ./functionTo/wrong-type.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"b a"$' config.result ./functionTo/list-order.nix
checkConfigOutput '^"a c"$' config.result ./functionTo/merging-attrs.nix
2022-05-13 07:09:16 +00:00
checkConfigOutput '^"a bee"$' config.result ./functionTo/submodule-options.nix
2022-10-07 07:58:55 +00:00
checkConfigOutput '^"fun.<function body>.a fun.<function body>.b"$' config.optionsResult ./functionTo/submodule-options.nix
2018-08-07 16:44:58 +00:00
2021-11-22 13:39:10 +00:00
# moduleType
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"a b"$' config.resultFoo ./declare-variants.nix ./define-variant.nix
2022-04-23 22:07:59 +00:00
checkConfigOutput '^"a b y z"$' config.resultFooBar ./declare-variants.nix ./define-variant.nix
2021-11-25 22:02:41 +00:00
checkConfigOutput '^"a b c"$' config.resultFooFoo ./declare-variants.nix ./define-variant.nix
2021-11-22 13:39:10 +00:00
2021-10-15 14:48:38 +00:00
## emptyValue's
2023-12-18 20:04:36 +00:00
checkConfigOutput "\[\]" config.list.a ./emptyValues.nix
checkConfigOutput "{}" config.attrs.a ./emptyValues.nix
2021-10-15 14:48:38 +00:00
checkConfigOutput "null" config.null.a ./emptyValues.nix
2023-12-18 20:04:36 +00:00
checkConfigOutput "{}" config.submodule.a ./emptyValues.nix
2021-10-15 14:48:38 +00:00
# These types don't have empty values
2024-08-30 09:31:26 +00:00
checkConfigError 'The option .int.a. was accessed but has no value defined. Try setting the option.' config.int.a ./emptyValues.nix
checkConfigError 'The option .nonEmptyList.a. was accessed but has no value defined. Try setting the option.' config.nonEmptyList.a ./emptyValues.nix
2021-10-15 14:48:38 +00:00
2024-01-28 13:09:27 +00:00
# types.unique
# requires a single definition
checkConfigError 'The option .examples\.merged. is defined multiple times while it.s expected to be unique' config.examples.merged.a ./types-unique.nix
# user message is printed
checkConfigError 'We require a single definition, because seeing the whole value at once helps us maintain critical invariants of our system.' config.examples.merged.a ./types-unique.nix
# let the inner merge function check the values (on demand)
checkConfigError 'A definition for option .examples\.badLazyType\.a. is not of type .string.' config.examples.badLazyType.a ./types-unique.nix
# overriding still works (unlike option uniqueness)
checkConfigOutput '^"bee"$' config.examples.override.b ./types-unique.nix
2021-08-02 19:42:45 +00:00
## types.raw
2023-12-18 20:04:36 +00:00
checkConfigOutput '^true$' config.unprocessedNestingEvaluates.success ./raw.nix
2021-08-02 19:42:45 +00:00
checkConfigOutput "10" config.processedToplevel ./raw.nix
checkConfigError "The option .multiple. is defined multiple times" config.multiple ./raw.nix
checkConfigOutput "bar" config.priorities ./raw.nix
2022-02-28 21:39:56 +00:00
## Option collision
checkConfigError \
2022-05-02 08:41:47 +00:00
'The option .set. in module .*/declare-set.nix. would be a parent of the following options, but its type .attribute set of signed integer. does not support nested options.\n\s*- option[(]s[)] with prefix .set.enable. in module .*/declare-enable-nested.nix.' \
2022-02-28 21:39:56 +00:00
config.set \
./declare-set.nix ./declare-enable-nested.nix
2023-07-08 20:18:36 +00:00
# Options: accidental use of an option-type instead of option (or other tagged type; unlikely)
2023-08-18 09:36:51 +00:00
checkConfigError 'In module .*/options-type-error-typical.nix: expected an option declaration at option path .result. but got an attribute set with type option-type' config.result ./options-type-error-typical.nix
checkConfigError 'In module .*/options-type-error-typical-nested.nix: expected an option declaration at option path .result.here. but got an attribute set with type option-type' config.result.here ./options-type-error-typical-nested.nix
checkConfigError 'In module .*/options-type-error-configuration.nix: expected an option declaration at option path .result. but got an attribute set with type configuration' config.result ./options-type-error-configuration.nix
2023-07-08 20:18:36 +00:00
2023-07-24 23:53:30 +00:00
# Check that that merging of option collisions doesn't depend on type being set
checkConfigError 'The option .group..*would be a parent of the following options, but its type .<no description>. does not support nested options.\n\s*- option.s. with prefix .group.enable..*' config.group.enable ./merge-typeless-option.nix
2021-12-08 18:02:29 +00:00
# Test that types.optionType merges types correctly
checkConfigOutput '^10$' config.theOption.int ./optionTypeMerging.nix
checkConfigOutput '^"hello"$' config.theOption.str ./optionTypeMerging.nix
# Test that types.optionType correctly annotates option locations
checkConfigError 'The option .theOption.nested. in .other.nix. is already declared in .optionTypeFile.nix.' config.theOption.nested ./optionTypeFile.nix
2022-03-10 19:25:49 +00:00
# Test that types.optionType leaves types untouched as long as they don't need to be merged
checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survives-type-merge.nix
2022-04-23 22:07:59 +00:00
# Anonymous submodules don't get nixed by import resolution/deduplication
# because of an `extendModules` bug, issue 168767.
checkConfigOutput '^1$' config.sub.specialisation.value ./extendModules-168767-imports.nix
2023-04-17 18:00:07 +00:00
# Class checks, evalModules
2023-12-18 20:04:36 +00:00
checkConfigOutput '^{}$' config.ok.config ./class-check.nix
2023-04-27 18:03:44 +00:00
checkConfigOutput '"nixos"' config.ok.class ./class-check.nix
2022-10-24 12:30:19 +00:00
checkConfigError 'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.fail.config ./class-check.nix
checkConfigError 'The module foo.nix#darwinModules.default was imported into nixos instead of darwin.' config.fail-anon.config ./class-check.nix
2023-04-17 18:00:07 +00:00
# Class checks, submoduleWith
2023-12-18 20:04:36 +00:00
checkConfigOutput '^{}$' config.sub.nixosOk ./class-check.nix
2023-04-17 18:00:07 +00:00
checkConfigError 'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.sub.nixosFail.config ./class-check.nix
# submoduleWith type merge with different class
2023-05-26 16:31:35 +00:00
checkConfigError 'A submoduleWith option is declared multiple times with conflicting class values "darwin" and "nixos".' config.sub.mergeFail.config ./class-check.nix
2023-04-17 18:00:07 +00:00
2023-02-07 19:41:29 +00:00
# _type check
2024-09-26 16:31:39 +00:00
checkConfigError 'Expected a module, but found a value of type .*"flake".*, while trying to load a module into .*/module-imports-_type-check.nix' config.ok.config ./module-imports-_type-check.nix
2024-10-05 14:10:14 +00:00
checkConfigOutput '^true$' config.enable ./declare-enable.nix ./define-enable-with-top-level-mkIf.nix
2024-09-26 16:31:39 +00:00
checkConfigError 'Expected a module, but found a value of type .*"configuration".*, while trying to load a module into .*/import-configuration.nix.' config ./import-configuration.nix
checkConfigError 'please only import the modules that make up the configuration' config ./import-configuration.nix
2023-02-07 19:41:29 +00:00
2022-11-03 12:11:04 +00:00
# doRename works when `warnings` does not exist.
checkConfigOutput '^1234$' config.c.d.e ./doRename-basic.nix
# doRename adds a warning.
checkConfigOutput '^"The option `a\.b. defined in `.*/doRename-warnings\.nix. has been renamed to `c\.d\.e.\."$' \
config.result \
./doRename-warnings.nix
2024-02-01 19:15:26 +00:00
checkConfigOutput " ^true $" config.result ./doRename-condition.nix ./doRename-condition-enable.nix
checkConfigOutput " ^true $" config.result ./doRename-condition.nix ./doRename-condition-no-enable.nix
checkConfigOutput " ^true $" config.result ./doRename-condition.nix ./doRename-condition-migrated.nix
2022-11-03 12:11:04 +00:00
2023-01-20 23:58:47 +00:00
# Anonymous modules get deduplicated by key
checkConfigOutput '^"pear"$' config.once.raw ./merge-module-with-key.nix
checkConfigOutput '^"pear\\npear"$' config.twice.raw ./merge-module-with-key.nix
2022-12-28 22:39:05 +00:00
# Declaration positions
# Line should be present for direct options
2024-07-12 01:20:47 +00:00
checkConfigOutput '^14$' options.imported.line14.declarationPositions.0.line ./declaration-positions.nix
checkConfigOutput '/declaration-positions.nix"$' options.imported.line14.declarationPositions.0.file ./declaration-positions.nix
2022-12-28 22:39:05 +00:00
# Generated options may not have line numbers but they will at least get the
# right file
2024-07-12 01:20:47 +00:00
checkConfigOutput '/declaration-positions.nix"$' options.generated.line22.declarationPositions.0.file ./declaration-positions.nix
checkConfigOutput '^null$' options.generated.line22.declarationPositions.0.line ./declaration-positions.nix
2022-12-28 22:39:05 +00:00
# Submodules don't break it
2024-07-12 01:20:47 +00:00
checkConfigOutput '^45$' config.submoduleLine38.submodDeclLine45.0.line ./declaration-positions.nix
checkConfigOutput '/declaration-positions.nix"$' config.submoduleLine38.submodDeclLine45.0.file ./declaration-positions.nix
2022-12-28 22:39:05 +00:00
# New options under freeform submodules get collected into the parent submodule
# (consistent with .declarations behaviour, but weird; notably appears in system.build)
2024-07-12 01:20:47 +00:00
checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.0.line ./declaration-positions.nix
checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.1.line ./declaration-positions.nix
2022-12-28 22:39:05 +00:00
# nested options work
2024-07-12 01:20:47 +00:00
checkConfigOutput '^34$' options.nested.nestedLine34.declarationPositions.0.line ./declaration-positions.nix
2022-12-28 22:39:05 +00:00
2015-02-08 20:48:38 +00:00
cat <<EOF
= = = = = = module tests = = = = = =
$pass Pass
$fail Fail
EOF
2021-11-25 22:03:40 +00:00
if [ " $fail " -ne 0 ] ; then
2015-02-08 20:48:38 +00:00
exit 1
fi
exit 0