about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/editors/nano/test-with-expect.nix
blob: bd48eba4324bd9e4ad14c56e92a879bd960e89b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
''