about summary refs log tree commit diff
path: root/pkgs/applications/editors/micro
diff options
context:
space:
mode:
authorPatrick Hilhorst <git@hilhorst.be>2022-02-27 16:55:03 +0100
committerPatrick Hilhorst <git@hilhorst.be>2022-02-27 16:56:35 +0100
commite2566775c76ae2e98617941c2555b439bc15de6d (patch)
tree51130a2f7ea0dc992812876a8c125b0dad920277 /pkgs/applications/editors/micro
parent5c713b5500a4f3ed16ea2c4a2a41a4ff6a64d091 (diff)
micro: add test with expect
Diffstat (limited to 'pkgs/applications/editors/micro')
-rw-r--r--pkgs/applications/editors/micro/default.nix4
-rw-r--r--pkgs/applications/editors/micro/test-with-expect.nix30
2 files changed, 33 insertions, 1 deletions
diff --git a/pkgs/applications/editors/micro/default.nix b/pkgs/applications/editors/micro/default.nix
index c3c42ac24cbab..d9805cbb36a94 100644
--- a/pkgs/applications/editors/micro/default.nix
+++ b/pkgs/applications/editors/micro/default.nix
@@ -1,4 +1,4 @@
-{ lib, buildGoModule, fetchFromGitHub, installShellFiles }:
+{ lib, buildGoModule, fetchFromGitHub, installShellFiles, callPackage }:
 
 buildGoModule rec {
   pname = "micro";
@@ -24,6 +24,8 @@ buildGoModule rec {
     install -Dt $out/share/applications assets/packaging/micro.desktop
   '';
 
+  passthru.tests.expect = callPackage ./test-with-expect.nix {};
+
   meta = with lib; {
     homepage = "https://micro-editor.github.io";
     description = "Modern and intuitive terminal-based text editor";
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 0000000000000..d3e1d60e08748
--- /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
+''