git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #161707 from Synthetica9/nano-test-rewrite
commit8725b29aa0ff69753d2daef5beb6abb454d29cfc authorBen Siraphob <bensiraphob@gmail.com> dateThu 24 Feb 2022, 21:41 (5 years ago) parentaed1f2c7ef8df8
4 files changed+39−47
nixos/tests/all-tests.nix−1 nixos/tests/nano.nix−44 pkgs/applications/editors/nano/default.nix+4−2 pkgs/applications/editors/nano/test-with-expect.nix+35
nixos/tests/all-tests.nix−1
@@ -322,7 +322,6 @@ in
322322 mysql-replication = handleTest ./mysql/mysql-replication.nix {};
323323 n8n = handleTest ./n8n.nix {};
324324 nagios = handleTest ./nagios.nix {};
325− nano = handleTest ./nano.nix {};
326325 nar-serve = handleTest ./nar-serve.nix {};
327326 nat.firewall = handleTest ./nat.nix { withFirewall = true; };
328327 nat.firewall-conntrack = handleTest ./nat.nix { withFirewall = true; withConntrackHelpers = true; };
nixos/tests/nano.nixdeleted−44
@@ -1,44 +0,0 @@
1−import ./make-test-python.nix ({ pkgs, ...} : {
2− name = "nano";
3− meta = with pkgs.lib.maintainers; {
4− maintainers = [ nequissimus ];
5− };
6−
7− machine = { lib, ... }: {
8− environment.systemPackages = [ pkgs.nano ];
9− };
10−
11− testScript = { ... }: ''
12− start_all()
13−
14− with subtest("Create user and log in"):
15− machine.wait_for_unit("multi-user.target")
16− machine.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
17− machine.succeed("useradd -m alice")
18− machine.succeed("(echo foobar; echo foobar) | passwd alice")
19− machine.wait_until_tty_matches(1, "login: ")
20− machine.send_chars("alice\n")
21− machine.wait_until_tty_matches(1, "login: alice")
22− machine.wait_until_succeeds("pgrep login")
23− machine.wait_until_tty_matches(1, "Password: ")
24− machine.send_chars("foobar\n")
25− machine.wait_until_succeeds("pgrep -u alice bash")
26− machine.screenshot("prompt")
27−
28− with subtest("Use nano"):
29− machine.send_chars("nano /tmp/foo")
30− machine.send_key("ret")
31− machine.sleep(2)
32− machine.send_chars("42")
33− machine.sleep(1)
34− machine.send_key("ctrl-x")
35− machine.sleep(1)
36− machine.send_key("y")
37− machine.sleep(1)
38− machine.screenshot("nano")
39− machine.sleep(1)
40− machine.send_key("ret")
41− machine.wait_for_file("/tmp/foo")
42− assert "42" in machine.succeed("cat /tmp/foo")
43− '';
44−})
pkgs/applications/editors/nano/default.nix+4−2
@@ -1,5 +1,5 @@
11{ lib, stdenv, fetchurl, fetchFromGitHub, ncurses, texinfo, writeScript
2−, common-updater-scripts, git, nix, nixfmt, coreutils, gnused, nixosTests
2+, common-updater-scripts, git, nix, nixfmt, coreutils, gnused, callPackage
33, gettext ? null, enableNls ? true, enableTiny ? false }:
44
55assert enableNls -> (gettext != null);
@@ -41,7 +41,9 @@ in stdenv.mkDerivation rec {
4141 enableParallelBuilding = true;
4242
4343 passthru = {
44− tests = { inherit (nixosTests) nano; };
44+ tests = {
45+ expect = callPackage ./test-with-expect.nix {};
46+ };
4547
4648 updateScript = writeScript "update.sh" ''
4749 #!${stdenv.shell}
pkgs/applications/editors/nano/test-with-expect.nixnew file+35
@@ -0,0 +1,35 @@
1+{ nano, expect, runCommand, writeScriptBin, runtimeShell }:
2+
3+let expect-script = writeScriptBin "expect-script" ''
4+ #!${expect}/bin/expect -f
5+
6+ # Load nano
7+ spawn nano file.txt
8+ expect "GNU nano ${nano.version}"
9+
10+ # Add some text to the buffer
11+ send "Hello world!"
12+ expect "Hello world!"
13+
14+ # Send ctrl-x (exit)
15+ send "\030"
16+ expect "Save modified buffer?"
17+
18+ # Answer "yes"
19+ send "y"
20+ expect "File Name to Write"
21+
22+ # Send "return" to accept the file path.
23+ send "\r"
24+ sleep 1
25+ exit
26+''; in
27+runCommand "nano-test-expect"
28+{
29+ nativeBuildInputs = [ nano expect ];
30+ passthru = { inherit expect-script; };
31+} ''
32+ expect -f ${expect-script}/bin/expect-script
33+ grep "Hello world!" file.txt
34+ touch $out
35+''