micro: refactor tests

- create a directory for holding tests

  `packagesFromDirectoryRecursive` is really useful!

- add version test
- rename and rework expect test
This commit is contained in:
Anderson Torres 2024-07-28 22:13:12 -03:00
parent c54fb7baa9
commit 7e8c970b4f
5 changed files with 52 additions and 35 deletions

View File

@ -9,7 +9,6 @@
, makeWrapper
# Boolean flags
, withXclip ? stdenv.isLinux
, withWlclip ? null
, withWlClipboard ?
if withWlclip != null then
lib.warn ''
@ -17,6 +16,10 @@
use withWlClipboard instead.
'' withWlclip
else stdenv.isLinux
# Deprecated options
# Remove them before or right after next version update from Nixpkgs or this
# package itself
, withWlclip ? null
}:
let
@ -68,10 +71,9 @@ let
'';
passthru = {
tests = {
expect = callPackage ./test-with-expect.nix {
micro = self;
};
tests = lib.packagesFromDirectoryRecursive {
inherit callPackage;
directory = ./tests;
};
};

View File

@ -1,30 +0,0 @@
{ micro, expect, runCommand, writeScript }:
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
''

View File

@ -0,0 +1,13 @@
spawn micro file.txt
expect "file.txt"
send "Hello world!"
expect "Hello world!"
# ctrl-q (exit)
send "\021"
expect "Save changes to file.txt before closing?"
send "y"
expect eof

View File

@ -0,0 +1,26 @@
{
expect,
micro,
runCommand,
}:
let
expect-script = builtins.path {
name = "hello.tcl";
path = ./hello.tcl;
};
in
runCommand "micro-expect-hello-world"
{
nativeBuildInputs = [
expect
micro
];
}
# Micro needs a writable $HOME for throwing its configuration
''
export HOME=$(pwd)
expect -f ${expect-script}
grep "Hello world!" file.txt
cat file.txt > $out
''

View File

@ -0,0 +1,6 @@
{ micro, testers }:
testers.testVersion {
package = micro;
command = "micro -version";
}