about summary refs log tree commit diff
path: root/pkgs/applications/editors/micro/test-with-expect.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/applications/editors/micro/test-with-expect.nix')
-rw-r--r--pkgs/applications/editors/micro/test-with-expect.nix30
1 files changed, 30 insertions, 0 deletions
diff --git a/pkgs/applications/editors/micro/test-with-expect.nix b/pkgs/applications/editors/micro/test-with-expect.nix
new file mode 100644
index 000000000000..d3e1d60e0874
--- /dev/null
+++ b/pkgs/applications/editors/micro/test-with-expect.nix
@@ -0,0 +1,30 @@
+{ micro, expect, runCommand, writeScript, runtimeShell }:
+
+let expect-script = writeScript "expect-script" ''
+  #!${expect}/bin/expect -f
+
+  spawn micro file.txt
+  expect "file.txt"
+
+  send "Hello world!"
+  expect "Hello world!"
+
+  # Send ctrl-q (exit)
+  send "\021"
+
+  expect "Save changes to file.txt before closing?"
+  send "y"
+
+  expect eof
+''; in
+runCommand "micro-test-expect"
+{
+  nativeBuildInputs = [ micro expect ];
+  passthru = { inherit expect-script; };
+} ''
+  # Micro really wants a writable $HOME for its config directory.
+  export HOME=$(pwd)
+  expect -f ${expect-script}
+  grep "Hello world!" file.txt
+  touch $out
+''