lib/types: Add coercedTo unsound tests
commitb16a69289aae7a8aeb7d0410649764d9d2328e2f
authorSilvan Mosberger <infinisil@icloud.com>
dateWed 4 Apr 2018, 16:51 (9 years ago)
parentef8996f
lib/tests/modules.sh+5
@@ -138,6 +138,11 @@ checkConfigOutput "\"42\"" config.value ./declare-coerced-value.nix
138138checkConfigOutput "\"24\"" config.value ./declare-coerced-value.nix ./define-value-string.nix
139139checkConfigError 'The option value .* in .* is not.*string or signed integer.*' config.value ./declare-coerced-value.nix ./define-value-list.nix
140140
141+# Check coerced value with unsound coercion
142+checkConfigOutput "12" config.value ./declare-coerced-value-unsound.nix
143+checkConfigError 'The option value .* in .* is not.*8 bit signed integer.* or string.*' config.value ./declare-coerced-value-unsound.nix ./define-value-string-bigint.nix
144+checkConfigError 'unrecognised JSON value' config.value ./declare-coerced-value-unsound.nix ./define-value-string-arbitrary.nix
145+
141146cat <<EOF
142147====== module tests ======
143148$pass Pass
lib/tests/modules/declare-coerced-value-unsound.nixnew file+10
@@ -0,0 +1,10 @@
1+{ lib, ... }:
2+
3+{
4+ options = {
5+ value = lib.mkOption {
6+ default = "12";
7+ type = lib.types.coercedTo lib.types.str lib.toInt lib.types.ints.s8;
8+ };
9+ };
10+}
lib/tests/modules/define-value-string-arbitrary.nixnew file+3
@@ -0,0 +1,3 @@
1+{
2+ value = "foobar";
3+}
lib/tests/modules/define-value-string-bigint.nixnew file+3
@@ -0,0 +1,3 @@
1+{
2+ value = "1000";
3+}