1 # The test template is taken from the `./keymap.nix`
2 { system ? builtins.currentSystem
4 , pkgs ? import ../.. { inherit system config; }
7 with import ../lib/testing-python.nix { inherit system pkgs; };
10 readyFile = "/tmp/readerReady";
11 resultFile = "/tmp/readerResult";
13 testReader = pkgs.writeScript "test-input-reader" ''
14 rm -f ${resultFile} ${resultFile}.tmp
15 logger "testReader: START: Waiting for $1 characters, expecting '$2'."
19 if [ "$chars" == "$2" ]; then
20 logger -s "testReader: PASS: Got '$2' as expected." 2>${resultFile}.tmp
22 logger -s "testReader: FAIL: Expected '$2' but got '$chars'." 2>${resultFile}.tmp
24 # rename after the file is written to prevent a race condition
25 mv ${resultFile}.tmp ${resultFile}
29 mkKeyboardTest = name: { default, test }: with pkgs.lib; makeTest {
35 keyboards = { inherit default; };
42 machine.wait_for_unit("keyd.service")
44 def run_test_case(cmd, test_case_name, inputs, expected):
45 with subtest(test_case_name):
46 assert len(inputs) == len(expected)
47 machine.execute("rm -f ${readyFile} ${resultFile}")
48 # set up process that expects all the keys to be entered
50 "{} {} {} {} >&2 &".format(
54 shlex.quote("".join(expected)),
57 # wait for reader to be ready
58 machine.wait_for_file("${readyFile}")
62 # wait for result and check
63 machine.wait_for_file("${resultFile}")
64 machine.succeed("grep -q 'PASS:' ${resultFile}")
65 test = ${builtins.toJSON test}
66 run_test_case("openvt -sw --", "${name}", test["press"], test["expect"])
71 pkgs.lib.mapAttrs mkKeyboardTest {
72 swap-ab_and_ctrl-as-shift = {
73 test.press = [ "a" "ctrl-b" "c" "alt_r-h" ];
74 test.expect = [ "b" "A" "c" "q" ];
80 "control" = "oneshot(shift)";
81 "rightalt" = "layer(rightalt)";