summaryrefslogtreecommitdiffstats
path: root/pkgs/pkgs-lib
diff options
context:
space:
mode:
authorh7x4 <h7x4@nani.wtf>2023-07-30 01:45:03 +0200
committerh7x4 <h7x4@nani.wtf>2023-10-27 18:32:22 +0200
commit18ca8b21e2918340f77d868e509c59df90f73e45 (patch)
treef07ac678e09ea89afa21f51fef3b4b5e5dce3fd2 /pkgs/pkgs-lib
parent3530342dccf37c70dbf8b3b20b8ac0676033f6b5 (diff)
formats.libconfig: add tests
Co-authored-by: ckie <25263210+ckiee@users.noreply.github.com> Signed-off-by: h7x4 <h7x4@nani.wtf>
Diffstat (limited to 'pkgs/pkgs-lib')
-rw-r--r--pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix76
-rw-r--r--pkgs/pkgs-lib/formats/libconfig/test/comprehensive/expected.txt6
-rw-r--r--pkgs/pkgs-lib/formats/libconfig/test/default.nix4
-rw-r--r--pkgs/pkgs-lib/tests/default.nix1
4 files changed, 87 insertions, 0 deletions
diff --git a/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix b/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix
new file mode 100644
index 000000000000..3715e2e840d2
--- /dev/null
+++ b/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix
@@ -0,0 +1,76 @@
+{ lib, formats, stdenvNoCC, writeText, ... }:
+let
+ libconfig = formats.libconfig { };
+
+ include_expr = {
+ val = 1;
+ };
+
+ include_file = (writeText "libconfig-test-include" ''
+ val=1;
+ '').overrideAttrs {
+ outputHashAlgo = "sha256";
+ outputHashMode = "flat";
+ };
+
+ expression = {
+ simple_top_level_attr = "1.0";
+ nested.attrset.has.a.integer.value = 100;
+ some_floaty = 29.95;
+ ## Same syntax here on these two, but they should get serialized differently:
+ # > A list may have zero or more elements, each of which can be a scalar value, an array, a group, or another list.
+ list1d = libconfig.lib.mkList [ 1 "mixed!" 5 2 ];
+ # You might also omit the mkList, as a list will be a list (in contrast to an array) by default.
+ list2d = [ 1 [ 1 1.2 "foo" ] [ "bar" 1.2 1 ] ];
+ # > An array may have zero or more elements, but the elements must all be scalar values of the same type.
+ array1d = libconfig.lib.mkArray [ 1 5 2 ];
+ array2d = [
+ (libconfig.lib.mkArray [ 1 2 ])
+ (libconfig.lib.mkArray [ 2 1 ])
+ ];
+ nasty_string = "\"@\n\\\t^*\b\f\n\0\";'''$";
+
+ weirderTypes = {
+ _includes = [ include_file ];
+ pi = 3.141592654;
+ bigint = 9223372036854775807;
+ hex = libconfig.lib.mkHex "0x1FC3";
+ octal = libconfig.lib.mkOctal "0027";
+ float = libconfig.lib.mkFloat "1.2E-3";
+ array_of_ints = libconfig.lib.mkArray [
+ (libconfig.lib.mkOctal "0732")
+ (libconfig.lib.mkHex "0xA3")
+ 1234
+ ];
+ list_of_weird_types = [
+ 3.141592654
+ 9223372036854775807
+ (libconfig.lib.mkHex "0x1FC3")
+ (libconfig.lib.mkOctal "0027")
+ (libconfig.lib.mkFloat "1.2E-32")
+ (libconfig.lib.mkFloat "1")
+ ];
+ };
+ };
+
+ libconfig-test-cfg = libconfig.generate "libconfig-test.cfg" expression;
+in
+ stdenvNoCC.mkDerivation {
+ name = "pkgs.formats.libconfig-test-comprehensive";
+
+ dontUnpack = true;
+ dontBuild = true;
+
+ doCheck = true;
+ checkPhase = ''
+ diff -U3 ${./expected.txt} ${libconfig-test-cfg}
+ '';
+
+ installPhase = ''
+ mkdir $out
+ cp ${./expected.txt} $out/expected.txt
+ cp ${libconfig-test-cfg} $out/libconfig-test.cfg
+ cp ${libconfig-test-cfg.passthru.json} $out/libconfig-test.json
+ '';
+ }
+
diff --git a/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/expected.txt b/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/expected.txt
new file mode 100644
index 000000000000..3e9b1af821f1
--- /dev/null
+++ b/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/expected.txt
@@ -0,0 +1,6 @@
+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="\"@
+\\ ^*bf
+0\";'''$";nested={attrset={has={a={integer={value=100;};};};};};simple_top_level_attr="1.0";some_floaty=29.95;weirderTypes={
+@include "/nix/store/jdz5yhzbbj4j77yrr7l20x1cs4kbwkj2-libconfig-test-include"
+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;};
+
diff --git a/pkgs/pkgs-lib/formats/libconfig/test/default.nix b/pkgs/pkgs-lib/formats/libconfig/test/default.nix
new file mode 100644
index 000000000000..6cd03fe4854f
--- /dev/null
+++ b/pkgs/pkgs-lib/formats/libconfig/test/default.nix
@@ -0,0 +1,4 @@
+{ pkgs, ... }:
+{
+ comprehensive = pkgs.callPackage ./comprehensive { };
+}
diff --git a/pkgs/pkgs-lib/tests/default.nix b/pkgs/pkgs-lib/tests/default.nix
index ae91e15aa9ef..289780f57650 100644
--- a/pkgs/pkgs-lib/tests/default.nix
+++ b/pkgs/pkgs-lib/tests/default.nix
@@ -17,6 +17,7 @@ let
jdk11 = pkgs.callPackage ../formats/java-properties/test { jdk = pkgs.jdk11_headless; };
jdk17 = pkgs.callPackage ../formats/java-properties/test { jdk = pkgs.jdk17_headless; };
};
+ libconfig = recurseIntoAttrs (import ../formats/libconfig/test { inherit pkgs; });
};
flatten = prefix: as: