summary refs log tree commit diff
path: root/pkgs/applications/editors/nano
diff options
context:
space:
mode:
authorPatrick Hilhorst <git@hilhorst.be>2022-02-24 20:23:40 +0100
committerPatrick Hilhorst <git@hilhorst.be>2022-02-24 21:26:25 +0100
commit7ef8df8767914249192d09d9056f13e04e54a7e6 (patch)
tree6030e576cdaaf52724c6ddada64017c0330558df /pkgs/applications/editors/nano
parent4c6f337c48eb06c3cded4652bf1445241901d828 (diff)
nixosTests.nano: replace with script using GNU expect
Diffstat (limited to 'pkgs/applications/editors/nano')
-rw-r--r--pkgs/applications/editors/nano/default.nix6
-rw-r--r--pkgs/applications/editors/nano/test-with-expect.nix35
2 files changed, 39 insertions, 2 deletions
diff --git a/pkgs/applications/editors/nano/default.nix b/pkgs/applications/editors/nano/default.nix
index f7d6004b5816a..658c18e5cb5c4 100644
--- a/pkgs/applications/editors/nano/default.nix
+++ b/pkgs/applications/editors/nano/default.nix
@@ -1,5 +1,5 @@
 { lib, stdenv, fetchurl, fetchFromGitHub, ncurses, texinfo, writeScript
-, common-updater-scripts, git, nix, nixfmt, coreutils, gnused, nixosTests
+, common-updater-scripts, git, nix, nixfmt, coreutils, gnused, callPackage
 , gettext ? null, enableNls ? true, enableTiny ? false }:
 
 assert enableNls -> (gettext != null);
@@ -41,7 +41,9 @@ in stdenv.mkDerivation rec {
   enableParallelBuilding = true;
 
   passthru = {
-    tests = { inherit (nixosTests) nano; };
+    tests = {
+      expect = callPackage ./test-with-expect.nix {};
+    };
 
     updateScript = writeScript "update.sh" ''
       #!${stdenv.shell}
diff --git a/pkgs/applications/editors/nano/test-with-expect.nix b/pkgs/applications/editors/nano/test-with-expect.nix
new file mode 100644
index 0000000000000..bd48eba4324bd
--- /dev/null
+++ b/pkgs/applications/editors/nano/test-with-expect.nix
@@ -0,0 +1,35 @@
+{ nano, expect, runCommand, writeScriptBin, runtimeShell }:
+
+let expect-script = writeScriptBin "expect-script" ''
+  #!${expect}/bin/expect -f
+
+  # Load nano
+  spawn nano file.txt
+  expect "GNU nano ${nano.version}"
+
+  # Add some text to the buffer
+  send "Hello world!"
+  expect "Hello world!"
+
+  # Send ctrl-x (exit)
+  send "\030"
+  expect "Save modified buffer?"
+
+  # Answer "yes"
+  send "y"
+  expect "File Name to Write"
+
+  # Send "return" to accept the file path.
+  send "\r"
+  sleep 1
+  exit
+''; in
+runCommand "nano-test-expect"
+{
+  nativeBuildInputs = [ nano expect ];
+  passthru = { inherit expect-script; };
+} ''
+  expect -f ${expect-script}/bin/expect-script
+  grep "Hello world!" file.txt
+  touch $out
+''