mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-20 11:05:14 +00:00
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:
parent
c54fb7baa9
commit
7e8c970b4f
@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
''
|
13
pkgs/by-name/mi/micro/tests/_001-hello-expect/hello.tcl
Normal file
13
pkgs/by-name/mi/micro/tests/_001-hello-expect/hello.tcl
Normal 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
|
26
pkgs/by-name/mi/micro/tests/_001-hello-expect/package.nix
Normal file
26
pkgs/by-name/mi/micro/tests/_001-hello-expect/package.nix
Normal 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
|
||||
''
|
6
pkgs/by-name/mi/micro/tests/version.nix
Normal file
6
pkgs/by-name/mi/micro/tests/version.nix
Normal file
@ -0,0 +1,6 @@
|
||||
{ micro, testers }:
|
||||
|
||||
testers.testVersion {
|
||||
package = micro;
|
||||
command = "micro -version";
|
||||
}
|
Loading…
Reference in New Issue
Block a user