feat(package): hemar: some stages of parsing
This commit is contained in:
@@ -1 +1,3 @@
|
||||
{ system, inputs, self, pkgs }: (import ./migrator { inherit system inputs self pkgs; })
|
||||
{ system, inputs, self, pkgs }:
|
||||
(import ./migrator { inherit system inputs self pkgs; }) //
|
||||
(import ./hemar { inherit system inputs self pkgs; })
|
||||
|
||||
48
test/package/hemar/default.nix
Normal file
48
test/package/hemar/default.nix
Normal file
@@ -0,0 +1,48 @@
|
||||
{ inputs, self, pkgs, system, ... }: let
|
||||
lib = inputs.nixpkgs.lib;
|
||||
|
||||
# turn anything under ./test into a derivation that exposes $out/run.sh
|
||||
mkTestDrv = name: type:
|
||||
if type == "directory" then
|
||||
pkgs.runCommand "test-${name}" {} ''
|
||||
if ! [ -f ${./test + "/${name}" + /run.sh} ]; then
|
||||
echo no run.sh in test/${name}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$out"
|
||||
cp -r ${./test + "/${name}"}/* "$out/"
|
||||
chmod +x "$out/run.sh"
|
||||
''
|
||||
else if lib.hasSuffix ".sh" name then
|
||||
pkgs.runCommand "test-${lib.removeSuffix ".sh" name}" {} ''
|
||||
mkdir -p "$out"
|
||||
install -Dm755 ${./test + "/${name}"} "$out/run.sh"
|
||||
''
|
||||
else
|
||||
null;
|
||||
|
||||
testDir = builtins.readDir ./test;
|
||||
|
||||
# attrset: testName -> drv with run.sh
|
||||
testDrvs =
|
||||
lib.mapAttrs' (n: v:
|
||||
lib.nameValuePair (lib.removeSuffix ".sh" n) v
|
||||
) (lib.filterAttrs (_: v: v != null)
|
||||
(lib.mapAttrs (n: t: mkTestDrv n t) testDir));
|
||||
|
||||
hemar = self.packages.${system}.hemar;
|
||||
mkPgTest = testName: testDrv: pkgs.runCommand "hemar-test-${testName}"
|
||||
{
|
||||
nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused ];
|
||||
buildInputs = [ hemar pkgs.yq-go ];
|
||||
} ''
|
||||
${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log}
|
||||
test=${testDrv}
|
||||
${builtins.readFile ./lauch.sh}
|
||||
|
||||
# success marker for Nix
|
||||
# shellcheck disable=SC2154
|
||||
mkdir -p "$out"
|
||||
'';
|
||||
in lib.mapAttrs (name: drv: mkPgTest name drv) testDrvs
|
||||
24
test/package/hemar/lauch.sh
Normal file
24
test/package/hemar/lauch.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/dash
|
||||
|
||||
# $test - test and assertion file
|
||||
|
||||
json_diff() {
|
||||
temp1=$(mktemp)
|
||||
temp2=$(mktemp)
|
||||
|
||||
yq -I=0 -o=j -n "$1" >"$temp1"
|
||||
yq -I=0 -o=j -n "$2" >"$temp2"
|
||||
|
||||
if ! diff -q "$temp1" "$temp2"; then
|
||||
log error "$(yq -o=j -n "$1")" and "$(yq -o=j -n "$2")"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# run test
|
||||
mkdir './test'
|
||||
# shellcheck disable=SC2154
|
||||
cp -r "$test"/* './test/'
|
||||
# shellcheck disable=SC2164
|
||||
cd './test'
|
||||
. './run.sh'
|
||||
32
test/package/hemar/test/first.sh
Normal file
32
test/package/hemar/test/first.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
answer="$(echo 'some text' | hemar -c)"
|
||||
|
||||
expected="$(printf '[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "some text"
|
||||
}
|
||||
]')"
|
||||
|
||||
json_diff "$answer" "$expected"
|
||||
|
||||
answer="$(echo 'some [] {} text' | hemar -c)"
|
||||
|
||||
expected="$(printf '[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "some [] {} text"
|
||||
}
|
||||
]')"
|
||||
|
||||
json_diff "$answer" "$expected"
|
||||
|
||||
answer="$(echo 'some {' | hemar -c)"
|
||||
|
||||
expected="$(printf '[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "some {"
|
||||
}
|
||||
]')"
|
||||
|
||||
json_diff "$answer" "$expected"
|
||||
Reference in New Issue
Block a user