tvl-depot/users/Profpatsch/netstring/tests/default.nix
Profpatsch 7e888c3c7b feat(nix): add basic netstring nix generation functions
Moving to toplevel so I can use them with `runExecline`. They should
be pretty atomic, and are proven to work (tests are still in my user
dir, since they test the producers indirectly via the python parser
and I don’t want to pull it out right now).

Change-Id: Id0baa3adcb2ec646458a104c7868c2889b8c64f5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3054
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
2021-04-24 09:54:34 +00:00

66 lines
1.5 KiB
Nix

{ depot, lib, pkgs, ... }:
let
inherit (depot.users.Profpatsch.netstring)
python-netstring
rust-netstring
;
python-netstring-test = depot.users.Profpatsch.writers.python3 {
name = "python-netstring-test";
libraries = p: [
python-netstring
];
} ''
import netstring
def assEq(left, right):
assert left == right, "{} /= {}".format(str(left), str(right))
assEq(
netstring.read_netstring(b"""${depot.nix.netstring.fromString "hi!"}"""),
(b"hi!", b"")
)
assEq(
netstring.read_netstring_key_val(
b"""${depot.nix.netstring.attrsToKeyValList { foo = "42"; }}"""
),
(b'foo', b'42', b"")
)
assEq(
netstring.read_netstring_key_val_list(
b"""${depot.nix.netstring.attrsToKeyValList { foo = "42"; bar = "hi"; }}"""
),
{ b'foo': b'42', b'bar': b'hi' }
)
'';
rust-netstring-test = depot.users.Profpatsch.writers.rustSimple {
name = "rust-netstring-test";
dependencies = [
rust-netstring
];
} ''
extern crate netstring;
fn main() {
assert_eq!(
std::str::from_utf8(&netstring::to_netstring(b"hello")).unwrap(),
r##"${depot.nix.netstring.fromString "hello"}"##
);
assert_eq!(
std::str::from_utf8(&netstring::to_netstring("".as_bytes())).unwrap(),
r##"${depot.nix.netstring.fromString ""}"##
);
}
'';
in depot.nix.utils.drvTargets {
inherit
python-netstring-test
rust-netstring-test
;
}