lol

formats.libconfig: add tests

Co-authored-by: ckie <25263210+ckiee@users.noreply.github.com>
Signed-off-by: h7x4 <h7x4@nani.wtf>

h7x4 18ca8b21 3530342d

+87
+76
pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix
··· 1 + { lib, formats, stdenvNoCC, writeText, ... }: 2 + let 3 + libconfig = formats.libconfig { }; 4 + 5 + include_expr = { 6 + val = 1; 7 + }; 8 + 9 + include_file = (writeText "libconfig-test-include" '' 10 + val=1; 11 + '').overrideAttrs { 12 + outputHashAlgo = "sha256"; 13 + outputHashMode = "flat"; 14 + }; 15 + 16 + expression = { 17 + simple_top_level_attr = "1.0"; 18 + nested.attrset.has.a.integer.value = 100; 19 + some_floaty = 29.95; 20 + ## Same syntax here on these two, but they should get serialized differently: 21 + # > A list may have zero or more elements, each of which can be a scalar value, an array, a group, or another list. 22 + list1d = libconfig.lib.mkList [ 1 "mixed!" 5 2 ]; 23 + # You might also omit the mkList, as a list will be a list (in contrast to an array) by default. 24 + list2d = [ 1 [ 1 1.2 "foo" ] [ "bar" 1.2 1 ] ]; 25 + # > An array may have zero or more elements, but the elements must all be scalar values of the same type. 26 + array1d = libconfig.lib.mkArray [ 1 5 2 ]; 27 + array2d = [ 28 + (libconfig.lib.mkArray [ 1 2 ]) 29 + (libconfig.lib.mkArray [ 2 1 ]) 30 + ]; 31 + nasty_string = "\"@\n\\\t^*\b\f\n\0\";'''$"; 32 + 33 + weirderTypes = { 34 + _includes = [ include_file ]; 35 + pi = 3.141592654; 36 + bigint = 9223372036854775807; 37 + hex = libconfig.lib.mkHex "0x1FC3"; 38 + octal = libconfig.lib.mkOctal "0027"; 39 + float = libconfig.lib.mkFloat "1.2E-3"; 40 + array_of_ints = libconfig.lib.mkArray [ 41 + (libconfig.lib.mkOctal "0732") 42 + (libconfig.lib.mkHex "0xA3") 43 + 1234 44 + ]; 45 + list_of_weird_types = [ 46 + 3.141592654 47 + 9223372036854775807 48 + (libconfig.lib.mkHex "0x1FC3") 49 + (libconfig.lib.mkOctal "0027") 50 + (libconfig.lib.mkFloat "1.2E-32") 51 + (libconfig.lib.mkFloat "1") 52 + ]; 53 + }; 54 + }; 55 + 56 + libconfig-test-cfg = libconfig.generate "libconfig-test.cfg" expression; 57 + in 58 + stdenvNoCC.mkDerivation { 59 + name = "pkgs.formats.libconfig-test-comprehensive"; 60 + 61 + dontUnpack = true; 62 + dontBuild = true; 63 + 64 + doCheck = true; 65 + checkPhase = '' 66 + diff -U3 ${./expected.txt} ${libconfig-test-cfg} 67 + ''; 68 + 69 + installPhase = '' 70 + mkdir $out 71 + cp ${./expected.txt} $out/expected.txt 72 + cp ${libconfig-test-cfg} $out/libconfig-test.cfg 73 + cp ${libconfig-test-cfg.passthru.json} $out/libconfig-test.json 74 + ''; 75 + } 76 +
+6
pkgs/pkgs-lib/formats/libconfig/test/comprehensive/expected.txt
··· 1 + array1d=[1, 5, 2];array2d=([1, 2], [2, 1]);list1d=(1, "mixed!", 5, 2);list2d=(1, (1, 1.2, "foo"), ("bar", 1.2, 1));nasty_string="\"@ 2 + \\ ^*bf 3 + 0\";'''$";nested={attrset={has={a={integer={value=100;};};};};};simple_top_level_attr="1.0";some_floaty=29.95;weirderTypes={ 4 + @include "/nix/store/jdz5yhzbbj4j77yrr7l20x1cs4kbwkj2-libconfig-test-include" 5 + array_of_ints=[0732, 0xa3, 1234];bigint=9223372036854775807;float=0.0012;hex=0x1fc3;list_of_weird_types=(3.141592654, 9223372036854775807, 0x1fc3, 027, 1.2e-32, 1.0);octal=027;pi=3.141592654;}; 6 +
+4
pkgs/pkgs-lib/formats/libconfig/test/default.nix
··· 1 + { pkgs, ... }: 2 + { 3 + comprehensive = pkgs.callPackage ./comprehensive { }; 4 + }
+1
pkgs/pkgs-lib/tests/default.nix
··· 17 17 jdk11 = pkgs.callPackage ../formats/java-properties/test { jdk = pkgs.jdk11_headless; }; 18 18 jdk17 = pkgs.callPackage ../formats/java-properties/test { jdk = pkgs.jdk17_headless; }; 19 19 }; 20 + libconfig = recurseIntoAttrs (import ../formats/libconfig/test { inherit pkgs; }); 20 21 }; 21 22 22 23 flatten = prefix: as: