diff options
author | linsui <linsui555@gmail.com> | 2023-09-23 02:40:03 +0800 |
---|---|---|
committer | Jan Tojnar <jtojnar@gmail.com> | 2023-09-28 16:30:05 +0200 |
commit | a50cea84be6f4706e563b6785418b85977b79a0c (patch) | |
tree | d2e126d06eeacd95a74d53aecf962abe4aafa144 /lib | |
parent | 8fe5ccd12e0c6a6cb7b21f156b12308d850d99b5 (diff) |
lib.gvariant: make the tests really work
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/tests/modules.sh | 3 | ||||
-rw-r--r-- | lib/tests/modules/gvariant.nix | 142 |
2 files changed, 58 insertions, 87 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 93fb1df933276..05c99e6de83ce 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -91,6 +91,9 @@ checkConfigOutput '^true$' config.result ./test-mergeAttrDefinitionsWithPrio.nix # is the option. checkConfigOutput '^true$' config.result ./module-argument-default.nix +# gvariant +checkConfigOutput '^true$' config.assertion ./gvariant.nix + # types.pathInStore 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 diff --git a/lib/tests/modules/gvariant.nix b/lib/tests/modules/gvariant.nix index a792ebf85b743..ba452c0287acc 100644 --- a/lib/tests/modules/gvariant.nix +++ b/lib/tests/modules/gvariant.nix @@ -1,93 +1,61 @@ { config, lib, ... }: -let inherit (lib) concatStringsSep mapAttrsToList mkMerge mkOption types gvariant; -in { - options.examples = mkOption { type = types.attrsOf gvariant; }; +{ + options = { + examples = lib.mkOption { type = lib.types.attrs; }; + assertion = lib.mkOption { type = lib.types.bool; }; + }; config = { - examples = with gvariant; - mkMerge [ - { bool = true; } - { bool = true; } - - { float = 3.14; } - - { int32 = mkInt32 (- 42); } - { int32 = mkInt32 (- 42); } - - { uint32 = mkUint32 42; } - { uint32 = mkUint32 42; } - - { int16 = mkInt16 (-42); } - { int16 = mkInt16 (-42); } - - { uint16 = mkUint16 42; } - { uint16 = mkUint16 42; } - - { int64 = mkInt64 (-42); } - { int64 = mkInt64 (-42); } - - { uint64 = mkUint64 42; } - { uint64 = mkUint64 42; } - - { array1 = [ "one" ]; } - { array1 = mkArray [ "two" ]; } - { array2 = mkArray [ (mkInt32 1) ]; } - { array2 = mkArray [ (nkUint32 2) ]; } - - { emptyArray1 = [ ]; } - { emptyArray2 = mkEmptyArray type.uint32; } - - { string = "foo"; } - { string = "foo"; } - { - escapedString = '' - '\ - ''; - } - - { tuple = mkTuple [ (mkInt32 1) [ "foo" ] ]; } - - { maybe1 = mkNothing type.string; } - { maybe2 = mkJust (mkUint32 4); } - - { variant1 = mkVariant "foo"; } - { variant2 = mkVariant 42; } - - { dictionaryEntry = mkDictionaryEntry (mkInt32 1) [ "foo" ]; } - ]; - - assertions = [ - { - assertion = ( - let - mkLine = n: v: "${n} = ${toString (gvariant.mkValue v)}"; - result = concatStringsSep "\n" (mapAttrsToList mkLine config.examples); - in - result + "\n" - ) == '' - array1 = @as ['one','two'] - array2 = @au [1,2] - bool = true - dictionaryEntry = @{ias} {1,@as ['foo']} - emptyArray1 = @as [] - emptyArray2 = @au [] - escapedString = '\'\\\n' - float = 3.140000 - int = -42 - int16 = @n -42 - int64 = @x -42 - maybe1 = @ms nothing - maybe2 = just @u 4 - string = 'foo' - tuple = @(ias) (1,@as ['foo']) - uint16 = @q 42 - uint32 = @u 42 - uint64 = @t 42 - variant1 = @v <'foo'> - variant2 = @v <42> - ''; - } - ]; + examples = with lib.gvariant; { + bool = true; + float = 3.14; + int32 = mkInt32 (- 42); + uint32 = mkUint32 42; + int16 = mkInt16 (-42); + uint16 = mkUint16 42; + int64 = mkInt64 (-42); + uint64 = mkUint64 42; + array1 = [ "one" ]; + array2 = mkArray [ (mkInt32 1) ]; + array3 = mkArray [ (mkUint32 2) ]; + emptyArray = mkEmptyArray type.uint32; + string = "foo"; + escapedString = '' + '\ + ''; + tuple = mkTuple [ (mkInt32 1) [ "foo" ] ]; + maybe1 = mkNothing type.string; + maybe2 = mkJust (mkUint32 4); + variant = mkVariant "foo"; + dictionaryEntry = mkDictionaryEntry (mkInt32 1) [ "foo" ]; + }; + + assertion = + let + mkLine = n: v: "${n} = ${toString (lib.gvariant.mkValue v)}"; + result = lib.concatStringsSep "\n" (lib.mapAttrsToList mkLine config.examples); + in + (result + "\n") == '' + array1 = @as ['one'] + array2 = @ai [1] + array3 = @au [@u 2] + bool = true + dictionaryEntry = @{ias} {1,@as ['foo']} + emptyArray = @au [] + escapedString = '\'\\\n' + float = 3.140000 + int16 = @n -42 + int32 = -42 + int64 = @x -42 + maybe1 = @ms nothing + maybe2 = just @u 4 + string = 'foo' + tuple = @(ias) (1,@as ['foo']) + uint16 = @q 42 + uint32 = @u 42 + uint64 = @t 42 + variant = <'foo'> + ''; }; } |