Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
e3d1ca0d
Commit
e3d1ca0d
authored
Apr 02, 2015
by
Hisham Muhammad
Browse files
83.9% test coverage!
parent
e5b08447
Changes
1
Hide whitespace changes
Inline
Side-by-side
test_spec.lua
View file @
e3d1ca0d
...
@@ -76,7 +76,7 @@ local function show(key)
...
@@ -76,7 +76,7 @@ local function show(key)
end
end
end
end
local
function
send
(
key
,
times
)
local
function
send
(
key
,
times
,
quick
)
if
times
==
0
then
return
end
if
times
==
0
then
return
end
for
_
=
1
,
times
or
1
do
for
_
=
1
,
times
or
1
do
delay
(
0
.
003
)
-- 30ms delay to avoid clobbering Esc sequences
delay
(
0
.
003
)
-- 30ms delay to avoid clobbering Esc sequences
...
@@ -87,6 +87,11 @@ local function send(key, times)
...
@@ -87,6 +87,11 @@ local function send(key, times)
else
else
rt
:
keyPress
(
key
)
rt
:
keyPress
(
key
)
end
end
if
not
quick
then
show
(
key
)
end
end
if
quick
then
show
(
key
)
show
(
key
)
end
end
end
end
...
@@ -146,6 +151,8 @@ end
...
@@ -146,6 +151,8 @@ end
local
attrs
=
{
local
attrs
=
{
black_on_cyan
=
6
,
black_on_cyan
=
6
,
red_on_cyan
=
22
,
red_on_cyan
=
22
,
white_on_black
=
176
,
yellow_on_black
=
112
,
}
}
local
function
find_selected_y
(
from
)
local
function
find_selected_y
(
from
)
...
@@ -168,6 +175,15 @@ local function find_command_x()
...
@@ -168,6 +175,15 @@ local function find_command_x()
return
64
return
64
end
end
local
function
set_display_option
(
n
)
send
(
"S"
)
send
(
curses
.
KEY_DOWN
)
send
(
curses
.
KEY_RIGHT
)
send
(
curses
.
KEY_DOWN
,
n
)
send
(
"
\n
"
)
send
(
curses
.
KEY_F10
)
end
describe
(
"htop test suite"
,
function
()
describe
(
"htop test suite"
,
function
()
running_it
(
"performs incremental filter"
,
function
()
running_it
(
"performs incremental filter"
,
function
()
...
@@ -375,6 +391,19 @@ describe("htop test suite", function()
...
@@ -375,6 +391,19 @@ describe("htop test suite", function()
send
(
" \n"
)
send
(
" \n"
)
send
(
ESC
)
send
(
ESC
)
end
)
end
)
running_it
(
"renices for a process"
,
function
()
send
(
"/"
)
send
(
"busted"
)
send
(
"
\n
"
)
local
line
=
find_selected_y
()
local
before
=
check_string_at
(
22
,
line
,
" 0"
)
send
(
curses
.
KEY_F8
)
delay
(
0
.
3
)
local
after
=
check_string_at
(
22
,
line
,
" 1"
)
assert
.
equal
(
check
(
before
))
assert
.
equal
(
check
(
after
))
end
)
running_it
(
"changes IO priority for a process"
,
function
()
running_it
(
"changes IO priority for a process"
,
function
()
send
(
"/"
)
send
(
"/"
)
...
@@ -385,6 +414,15 @@ describe("htop test suite", function()
...
@@ -385,6 +414,15 @@ describe("htop test suite", function()
send
(
"
\n
"
)
send
(
"
\n
"
)
send
(
ESC
)
send
(
ESC
)
end
)
end
)
running_it
(
"shows help"
,
function
()
send
(
curses
.
KEY_F1
)
send
(
"
\n
"
)
set_display_option
(
9
)
send
(
curses
.
KEY_F1
)
send
(
"
\n
"
)
set_display_option
(
9
)
end
)
local
meters
=
{
local
meters
=
{
{
name
=
"clock"
,
down
=
0
,
string
=
"Time"
},
{
name
=
"clock"
,
down
=
0
,
string
=
"Time"
},
...
@@ -453,12 +491,7 @@ describe("htop test suite", function()
...
@@ -453,12 +491,7 @@ describe("htop test suite", function()
for
_
,
item
in
ipairs
(
display_options
)
do
for
_
,
item
in
ipairs
(
display_options
)
do
running_it
(
"checks display option to "
..
item
.
name
,
function
()
running_it
(
"checks display option to "
..
item
.
name
,
function
()
for
_
=
1
,
2
do
for
_
=
1
,
2
do
send
(
"S"
)
set_display_option
(
item
.
down
)
send
(
curses
.
KEY_DOWN
)
send
(
curses
.
KEY_RIGHT
)
send
(
curses
.
KEY_DOWN
,
item
.
down
)
send
(
"
\n
"
)
send
(
curses
.
KEY_F10
)
delay
(
0
.
1
)
delay
(
0
.
1
)
end
end
end
)
end
)
...
@@ -477,15 +510,73 @@ describe("htop test suite", function()
...
@@ -477,15 +510,73 @@ describe("htop test suite", function()
delay
(
0
.
1
)
delay
(
0
.
1
)
end
end
end
)
end
)
running_it
(
"expands and collapses tree"
,
function
()
send
(
curses
.
KEY_F5
)
-- tree view
send
(
curses
.
KEY_HOME
)
send
(
curses
.
KEY_DOWN
)
-- second process in the tree
send
(
"-"
)
send
(
"+"
)
send
(
curses
.
KEY_F5
)
end
)
running_it
(
"sets sort key"
,
function
()
send
(
"."
)
send
(
"
\n
"
)
end
)
running_it
(
"tags all children"
,
function
()
send
(
curses
.
KEY_F5
)
-- tree view
send
(
curses
.
KEY_HOME
)
-- ensure we're at init
send
(
"c"
)
local
taggedattrs
=
{}
rt
:
update
()
for
y
=
y_panelhdr
+
2
,
23
do
table.insert
(
taggedattrs
,
rt
:
cellAttr
(
y
-
1
,
4
))
end
delay
(
0
.
2
)
send
(
"U"
)
local
untaggedattrs
=
{}
rt
:
update
()
for
y
=
y_panelhdr
+
2
,
23
do
table.insert
(
untaggedattrs
,
rt
:
cellAttr
(
y
-
1
,
4
))
end
send
(
curses
.
KEY_F5
)
for
_
,
taggedattr
in
ipairs
(
taggedattrs
)
do
assert
.
equal
(
attrs
.
yellow_on_black
,
taggedattr
)
end
for
_
,
untaggedattr
in
ipairs
(
untaggedattrs
)
do
assert
.
equal
(
attrs
.
white_on_black
,
untaggedattr
)
end
end
)
for
i
=
1
,
62
do
for
i
=
1
,
62
do
running_it
(
"show column "
..
i
,
function
()
running_it
(
"show column "
..
i
,
function
()
send
(
"S"
)
send
(
"S"
)
send
(
curses
.
KEY_END
)
send
(
curses
.
KEY_END
)
send
(
curses
.
KEY_RIGHT
,
2
)
send
(
curses
.
KEY_RIGHT
,
1
)
send
(
curses
.
KEY_DOWN
,
i
)
if
i
>
1
then
send
(
curses
.
KEY_DC
)
end
send
(
curses
.
KEY_RIGHT
,
1
)
local
down
=
i
while
down
>
13
do
send
(
curses
.
KEY_NPAGE
)
down
=
down
-
13
end
send
(
curses
.
KEY_DOWN
,
down
,
"quick"
)
send
(
"
\n
"
)
send
(
"
\n
"
)
send
(
curses
.
KEY_F10
)
send
(
curses
.
KEY_F10
)
if
i
==
62
then
send
(
"S"
)
send
(
curses
.
KEY_END
)
send
(
curses
.
KEY_RIGHT
,
1
)
if
i
>
1
then
send
(
curses
.
KEY_DC
)
end
send
(
curses
.
KEY_F10
)
end
end
)
end
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment