micro: refactor tests

- create a directory for holding tests

`packagesFromDirectoryRecursive` is really useful!

- add version test
- rename and rework expect test

+52 -35
+7 -5
pkgs/by-name/mi/micro/package.nix
··· 9 9 , makeWrapper 10 10 # Boolean flags 11 11 , withXclip ? stdenv.isLinux 12 - , withWlclip ? null 13 12 , withWlClipboard ? 14 13 if withWlclip != null then 15 14 lib.warn '' ··· 17 16 use withWlClipboard instead. 18 17 '' withWlclip 19 18 else stdenv.isLinux 19 + # Deprecated options 20 + # Remove them before or right after next version update from Nixpkgs or this 21 + # package itself 22 + , withWlclip ? null 20 23 }: 21 24 22 25 let ··· 68 71 ''; 69 72 70 73 passthru = { 71 - tests = { 72 - expect = callPackage ./test-with-expect.nix { 73 - micro = self; 74 - }; 74 + tests = lib.packagesFromDirectoryRecursive { 75 + inherit callPackage; 76 + directory = ./tests; 75 77 }; 76 78 }; 77 79
-30
pkgs/by-name/mi/micro/test-with-expect.nix
··· 1 - { micro, expect, runCommand, writeScript }: 2 - 3 - let expect-script = writeScript "expect-script" '' 4 - #!${expect}/bin/expect -f 5 - 6 - spawn micro file.txt 7 - expect "file.txt" 8 - 9 - send "Hello world!" 10 - expect "Hello world!" 11 - 12 - # Send ctrl-q (exit) 13 - send "\021" 14 - 15 - expect "Save changes to file.txt before closing?" 16 - send "y" 17 - 18 - expect eof 19 - ''; in 20 - runCommand "micro-test-expect" 21 - { 22 - nativeBuildInputs = [ micro expect ]; 23 - passthru = { inherit expect-script; }; 24 - } '' 25 - # Micro really wants a writable $HOME for its config directory. 26 - export HOME=$(pwd) 27 - expect -f ${expect-script} 28 - grep "Hello world!" file.txt 29 - touch $out 30 - ''
+13
pkgs/by-name/mi/micro/tests/_001-hello-expect/hello.tcl
··· 1 + spawn micro file.txt 2 + expect "file.txt" 3 + 4 + send "Hello world!" 5 + expect "Hello world!" 6 + 7 + # ctrl-q (exit) 8 + send "\021" 9 + 10 + expect "Save changes to file.txt before closing?" 11 + send "y" 12 + 13 + expect eof
+26
pkgs/by-name/mi/micro/tests/_001-hello-expect/package.nix
··· 1 + { 2 + expect, 3 + micro, 4 + runCommand, 5 + }: 6 + 7 + let 8 + expect-script = builtins.path { 9 + name = "hello.tcl"; 10 + path = ./hello.tcl; 11 + }; 12 + in 13 + runCommand "micro-expect-hello-world" 14 + { 15 + nativeBuildInputs = [ 16 + expect 17 + micro 18 + ]; 19 + } 20 + # Micro needs a writable $HOME for throwing its configuration 21 + '' 22 + export HOME=$(pwd) 23 + expect -f ${expect-script} 24 + grep "Hello world!" file.txt 25 + cat file.txt > $out 26 + ''
+6
pkgs/by-name/mi/micro/tests/version.nix
··· 1 + { micro, testers }: 2 + 3 + testers.testVersion { 4 + package = micro; 5 + command = "micro -version"; 6 + }