mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-21 22:43:01 +00:00
formats.hocon: add tests
This commit is contained in:
parent
2554eba2ca
commit
b6cdfec16c
83
pkgs/pkgs-lib/formats/hocon/test/comprehensive/default.nix
Normal file
83
pkgs/pkgs-lib/formats/hocon/test/comprehensive/default.nix
Normal file
@ -0,0 +1,83 @@
|
||||
{ lib, formats, stdenvNoCC, writeText, ... }:
|
||||
let
|
||||
hocon = formats.hocon { };
|
||||
|
||||
include_file = (writeText "hocon-test-include.conf" ''
|
||||
"val" = 1
|
||||
'').overrideAttrs (_: _: {
|
||||
outputHashAlgo = "sha256";
|
||||
outputHashMode = "flat";
|
||||
outputHash = "sha256-UhkJLhT3bD6znq+IdDjs/ahP19mLzrLCy/R14pVrfew=";
|
||||
});
|
||||
|
||||
expression = {
|
||||
simple_top_level_attr = "1.0";
|
||||
nested.attrset.has.a.integer.value = 100;
|
||||
some_floaty = 29.95;
|
||||
|
||||
array2d = [
|
||||
[ 1 2 "a" ]
|
||||
[ 2 1 "b" ]
|
||||
];
|
||||
nasty_string = "\"@\n\\\t^*\b\f\n\0\";'''$";
|
||||
|
||||
"misc attrs" = {
|
||||
x = 1;
|
||||
y = hocon.lib.mkAppend { a = 1; };
|
||||
};
|
||||
|
||||
"cursed \" .attrs \" " = {
|
||||
"a" = 1;
|
||||
"a b" = hocon.lib.mkSubstitution "a";
|
||||
"a b c" = hocon.lib.mkSubstitution {
|
||||
value = "a b";
|
||||
required = false;
|
||||
};
|
||||
};
|
||||
|
||||
to_include = {
|
||||
_includes = [
|
||||
(hocon.lib.mkInclude include_file)
|
||||
(hocon.lib.mkInclude "https://example.com")
|
||||
(hocon.lib.mkInclude {
|
||||
required = true;
|
||||
type = "file";
|
||||
value = include_file;
|
||||
})
|
||||
(hocon.lib.mkInclude { value = include_file; })
|
||||
(hocon.lib.mkInclude {
|
||||
value = "https://example.com";
|
||||
type = "url";
|
||||
})
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
hocon-test-conf = hocon.generate "hocon-test.conf" expression;
|
||||
in
|
||||
stdenvNoCC.mkDerivation {
|
||||
name = "pkgs.formats.hocon-test-comprehensive";
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
|
||||
doCheck = true;
|
||||
checkPhase = ''
|
||||
runHook preCheck
|
||||
|
||||
diff -U3 ${./expected.txt} ${hocon-test-conf}
|
||||
|
||||
runHook postCheck
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir $out
|
||||
cp ${./expected.txt} $out/expected.txt
|
||||
cp ${hocon-test-conf} $out/hocon-test.conf
|
||||
cp ${hocon-test-conf.passthru.json} $out/hocon-test.json
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
}
|
47
pkgs/pkgs-lib/formats/hocon/test/comprehensive/expected.txt
Normal file
47
pkgs/pkgs-lib/formats/hocon/test/comprehensive/expected.txt
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"array2d" = [
|
||||
[
|
||||
1,
|
||||
2,
|
||||
"a"
|
||||
],
|
||||
[
|
||||
2,
|
||||
1,
|
||||
"b"
|
||||
]
|
||||
]
|
||||
"cursed \" .attrs \" " = {
|
||||
"a" = 1
|
||||
"a b" = ${?a}
|
||||
"a b c" = ${?a b}
|
||||
}
|
||||
"misc attrs" = {
|
||||
"x" = 1
|
||||
"y" += {
|
||||
"a" = 1
|
||||
}
|
||||
}
|
||||
"nasty_string" = "\"@\n\\\t^*bf\n0\";'''$"
|
||||
"nested" = {
|
||||
"attrset" = {
|
||||
"has" = {
|
||||
"a" = {
|
||||
"integer" = {
|
||||
"value" = 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"simple_top_level_attr" = "1.0"
|
||||
"some_floaty" = 29.95
|
||||
"to_include" = {
|
||||
include "/nix/store/ccnzr53dpipdacxgci3ii3bqacvb5hxm-hocon-test-include.conf"
|
||||
include "https://example.com"
|
||||
include required(file("/nix/store/ccnzr53dpipdacxgci3ii3bqacvb5hxm-hocon-test-include.conf"))
|
||||
include "/nix/store/ccnzr53dpipdacxgci3ii3bqacvb5hxm-hocon-test-include.conf"
|
||||
include url("https://example.com")
|
||||
}
|
||||
}
|
||||
|
4
pkgs/pkgs-lib/formats/hocon/test/default.nix
Normal file
4
pkgs/pkgs-lib/formats/hocon/test/default.nix
Normal file
@ -0,0 +1,4 @@
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
comprehensive = pkgs.callPackage ./comprehensive { };
|
||||
}
|
@ -17,7 +17,10 @@ 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; });
|
||||
|
||||
hocon = recurseIntoAttrs (import ../formats/hocon/test { inherit pkgs; });
|
||||
};
|
||||
|
||||
flatten = prefix: as:
|
||||
|
Loading…
Reference in New Issue
Block a user