1
1
mirror of https://github.com/tstack/lnav.git synced 2024-11-09 16:46:04 +03:00

[tests] add more TUI tests

This commit is contained in:
Timothy Stack 2021-02-04 23:10:44 -08:00
parent 58f1c9df1c
commit 2750d23b07
6 changed files with 371 additions and 19 deletions

View File

@ -1510,12 +1510,12 @@ static void looper()
case LNM_EXEC: case LNM_EXEC:
case LNM_USER: case LNM_USER:
if (rlc.consume_ready_for_input()) { if (rlc.consume_ready_for_input()) {
log_debug("waiting for readline input") // log_debug("waiting for readline input")
view_curses::awaiting_user_input(); view_curses::awaiting_user_input();
} }
break; break;
default: default:
log_debug("waiting for paging input"); // log_debug("waiting for paging input");
view_curses::awaiting_user_input(); view_curses::awaiting_user_input();
break; break;
} }

View File

@ -41,20 +41,31 @@
#include "sql_util.hh" #include "sql_util.hh"
#include "vtab_module.hh" #include "vtab_module.hh"
static int64_t sql_log_top_line() static nonstd::optional<int64_t> sql_log_top_line()
{ {
return (int64_t) lnav_data.ld_views[LNV_LOG].get_top(); const auto& tc = lnav_data.ld_views[LNV_LOG];
if (tc.get_inner_height() == 0_vl) {
return nonstd::nullopt;
}
return (int64_t) tc.get_top();
} }
static std::string sql_log_top_datetime() static nonstd::optional<std::string> sql_log_top_datetime()
{ {
const auto& tc = lnav_data.ld_views[LNV_LOG];
if (tc.get_inner_height() == 0_vl) {
return nonstd::nullopt;
}
char buffer[64]; char buffer[64];
sql_strftime(buffer, sizeof(buffer), lnav_data.ld_log_source.time_for_row(lnav_data.ld_views[LNV_LOG].get_top())); sql_strftime(buffer, sizeof(buffer), lnav_data.ld_log_source.time_for_row(lnav_data.ld_views[LNV_LOG].get_top()));
return buffer; return buffer;
} }
static int64_t sql_error(const std::string str) static int64_t sql_error(const char *str)
{ {
throw sqlite_func_error("{}", str); throw sqlite_func_error("{}", str);
} }

View File

@ -71,8 +71,10 @@ struct sqlite_func_error : std::exception {
template<typename T> template<typename T>
struct from_sqlite { struct from_sqlite {
inline T operator()(int argc, sqlite3_value **val, int argi) { using U = typename std::remove_reference<T>::type;
return T();
inline U operator()(int argc, sqlite3_value **val, int argi) {
return U();
}; };
}; };

View File

@ -67,6 +67,14 @@ check_output "w3c headers are not captured?" <<EOF
] ]
EOF EOF
run_test ${lnav_test} -n \
-c ";SELECT raise_error('oops!')" \
${test_dir}/logfile_access_log.0
check_error_output "raise_error() does not work?" <<EOF
command-option:1: error: oops!
EOF
run_test ${lnav_test} -n \ run_test ${lnav_test} -n \
-c ";UPDATE lnav_file SET visible=0" \ -c ";UPDATE lnav_file SET visible=0" \
${test_dir}/logfile_access_log.0 ${test_dir}/logfile_access_log.0
@ -213,6 +221,16 @@ log_top_line()
2 2
EOF EOF
run_test ${lnav_test} -n \
-c ":goto 2" \
-c ";SELECT log_top_line()" \
${test_dir}/logfile_empty.0
check_output "log_top_line() for an empty log file is not working?" <<EOF
log_top_line()
<NULL>
EOF
run_test ${lnav_test} -n \ run_test ${lnav_test} -n \
-c ":goto 2" \ -c ":goto 2" \
-c ";SELECT log_top_datetime()" \ -c ";SELECT log_top_datetime()" \
@ -223,6 +241,16 @@ check_output "log_top_datetime() not working?" <<EOF
2016-03-13 22:49:15.000 2016-03-13 22:49:15.000
EOF EOF
run_test ${lnav_test} -n \
-c ":goto 2" \
-c ";SELECT log_top_datetime()" \
${test_dir}/logfile_empty.0
check_output "log_top_datetime() for an empty log file is not working?" <<EOF
log_top_datetime()
<NULL>
EOF
run_test ${lnav_test} -n \ run_test ${lnav_test} -n \
-c ";SELECT * FROM uwsgi_log LIMIT 1" \ -c ";SELECT * FROM uwsgi_log LIMIT 1" \
-c ':switch-to-view db' \ -c ':switch-to-view db' \
@ -512,7 +540,7 @@ EOF
# XXX The timestamp on the file is used to determine the year for syslog files. # XXX The timestamp on the file is used to determine the year for syslog files.
touch -t 201311030923 ${test_dir}/logfile_syslog.0 touch -t 200711030923 ${test_dir}/logfile_syslog.0
run_test ${lnav_test} -n \ run_test ${lnav_test} -n \
-c ";select * from syslog_log" \ -c ";select * from syslog_log" \
-c ':write-csv-to -' \ -c ':write-csv-to -' \
@ -520,10 +548,10 @@ run_test ${lnav_test} -n \
check_output "syslog_log table is not working" <<EOF check_output "syslog_log table is not working" <<EOF
log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_hostname,log_msgid,log_pid,log_pri,log_procname,log_struct,syslog_version log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_hostname,log_msgid,log_pid,log_pri,log_procname,log_struct,syslog_version
0,<NULL>,2013-11-03 09:23:38.000,0,error,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,7998,<NULL>,automount,<NULL>,<NULL> 0,<NULL>,2007-11-03 09:23:38.000,0,error,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,7998,<NULL>,automount,<NULL>,<NULL>
1,<NULL>,2013-11-03 09:23:38.000,0,info,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,16442,<NULL>,automount,<NULL>,<NULL> 1,<NULL>,2007-11-03 09:23:38.000,0,info,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,16442,<NULL>,automount,<NULL>,<NULL>
2,<NULL>,2013-11-03 09:23:38.000,0,error,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,7999,<NULL>,automount,<NULL>,<NULL> 2,<NULL>,2007-11-03 09:23:38.000,0,error,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,7999,<NULL>,automount,<NULL>,<NULL>
3,<NULL>,2013-11-03 09:47:02.000,1404000,info,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,<NULL>,<NULL>,sudo,<NULL>,<NULL> 3,<NULL>,2007-11-03 09:47:02.000,1404000,info,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,<NULL>,<NULL>,sudo,<NULL>,<NULL>
EOF EOF
@ -537,13 +565,13 @@ EOF
run_test ${lnav_test} -n \ run_test ${lnav_test} -n \
-c ";select * from syslog_log where log_time >= datetime('2013-11-03T09:47:02.000')" \ -c ";select * from syslog_log where log_time >= datetime('2007-11-03T09:47:02.000')" \
-c ':write-csv-to -' \ -c ':write-csv-to -' \
${test_dir}/logfile_syslog.0 ${test_dir}/logfile_syslog.0
check_output "log_time collation is wrong" <<EOF check_output "log_time collation is wrong" <<EOF
log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_hostname,log_msgid,log_pid,log_pri,log_procname,log_struct,syslog_version log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_hostname,log_msgid,log_pid,log_pri,log_procname,log_struct,syslog_version
3,<NULL>,2013-11-03 09:47:02.000,1404000,info,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,<NULL>,<NULL>,sudo,<NULL>,<NULL> 3,<NULL>,2007-11-03 09:47:02.000,1404000,info,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,<NULL>,<NULL>,sudo,<NULL>,<NULL>
EOF EOF
@ -555,7 +583,7 @@ run_test ${lnav_test} -n \
check_output "logline table is not working" <<EOF check_output "logline table is not working" <<EOF
log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_hostname,log_msgid,log_pid,log_pri,log_procname,log_struct,syslog_version,log_msg_instance,col_0,TTY,PWD,USER,COMMAND log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_hostname,log_msgid,log_pid,log_pri,log_procname,log_struct,syslog_version,log_msg_instance,col_0,TTY,PWD,USER,COMMAND
0,<NULL>,2013-11-03 09:47:02.000,0,info,0,<NULL>,<NULL>,[1],veridian,<NULL>,<NULL>,<NULL>,sudo,<NULL>,<NULL>,0,timstack,pts/6,/auto/wstimstack/rpms/lbuild/test,root,/usr/bin/tail /var/log/messages 0,<NULL>,2007-11-03 09:47:02.000,0,info,0,<NULL>,<NULL>,[1],veridian,<NULL>,<NULL>,<NULL>,sudo,<NULL>,<NULL>,0,timstack,pts/6,/auto/wstimstack/rpms/lbuild/test,root,/usr/bin/tail /var/log/messages
EOF EOF

View File

@ -5,7 +5,9 @@ unset SSH_CONNECTION
lnav_test="${top_builddir}/src/lnav-test" lnav_test="${top_builddir}/src/lnav-test"
run_test ./scripty -n -e ${srcdir}/tui-captures/tui_help.0 -- \ for fn in ${srcdir}/tui-captures/*; do
run_test ./scripty -n -e $fn -- \
${lnav_test} -H < /dev/null ${lnav_test} -H < /dev/null
on_error_fail_with "help screen does not work?" on_error_fail_with "TUI test ${fn} does not work?"
done

View File

@ -0,0 +1,309 @@
CSI Don't Send Mouse X & Y
CSI Dont Use Cell Motion Mouse Tracking
CSI Don't ...
CTRL Use alt charset
CTRL save cursor
CSI Use alternate screen buffer
CSI set scrolling region 1-24
S -1 ┋ ┋
A └ normal
CSI Replace mode
CSI Application cursor keys
CTRL =
OSC Set window title: LOG
S -1 ┋ ┋
A └ normal, normal, normal
CSI Erase all
S 1 ┋ Thu Jun 06 1 :: :: LOG ┋
A └ fg(#c0c0c0), bg(#008080)
S 2 ┋ x┋
A ···············································································├ normal
A └┛ alt
A ················································································└ normal
S 3 ┋ x┋
A └┛ alt
A ················································································└ normal
S 4 ┋ x┋
A └┛ alt
A ················································································└ normal
S 5 ┋ x┋
A └┛ alt
A ················································································└ normal
S 6 ┋ x┋
A └┛ alt
A ················································································└ normal
S 7 ┋ x┋
A └┛ alt
A ················································································└ normal
S 8 ┋ x┋
A └┛ alt
A ················································································└ normal
S 9 ┋ x┋
A └┛ alt
A ················································································└ normal
S 10 ┋ x┋
A └┛ alt
A ················································································└ normal
S 11 ┋ x┋
A └┛ alt
A ················································································└ normal
S 12 ┋ x┋
A └┛ alt
A ················································································└ normal
S 13 ┋ x┋
A └┛ alt
A ················································································└ normal
S 14 ┋ x┋
A └┛ alt
A ················································································└ normal
S 15 ┋ x┋
A └┛ alt
A ················································································└ normal
S 16 ┋ x┋
A └┛ alt
A ················································································└ normal
S 17 ┋ lqqqq No log messages; Files: 0; Error rate: 0.00/min; Time span: None qqqqk x┋
A └----┛ alt │ │ │ │ │ │ │ ││ │││
A ·······························└ bold │ │ │ │ ││ │││
A ·································└ normal │ │ │ │ ││ │││
A ···································└ fg(#800000), bold │ ││ │││
A ·············································└ normal │ ││ │││
A ···············································└ bold │ ││ │││
A ···················································└ normal │ ││ │││
A ····································································└ bold │││
A ········································································└ normal│
A ·········································································├ bold││
A └----┛ alt
A ··············································································└ normal
A └┛ alt
A ················································································└ normal
S 18 ┋ Files :: Text Filters :: Press q to exit ┋
A └ fg(#c0c0c0), bg(#000080), bold ││
A ·└ fg(#008080), bg(#000080), underline ││
A ··└ normal, fg(#c0c0c0), bg(#000080), bold ││
A ·······└ normal, fg(#c0c0c0), bg(#000080) ││
A ········└ fg(#000080), bg(#c0c0c0) ││
A ·········└ fg(#000000), bg(#c0c0c0), bold ││
A ··········└ fg(#800080), bg(#c0c0c0), underline ││
A ···········└ normal, fg(#000000), bg(#c0c0c0), bold ││
A ·······················└ normal, fg(#000000), bg(#c0c0c0) ││
A ······································································└ bold
A ·······································································└ normal, fg(#000000), bg(#c0c0c0)
S 19 ┋ ┋
S 20 ┋ x┋
A ···············································································├ normal
A └┛ alt
A ················································································└ normal
S 21 ┋ x┋
A └┛ alt
A ················································································└ normal
S 22 ┋ x┋
A └┛ alt
A ················································································└ normal
S 23 ┋ L0 0% ?:View Help ┋
A └ fg(#000000), bg(#c0c0c0)
S 22 ┋ ┋
A └ normal, normal
OSC Set window title: HELP
S 1 ┋ Thu Jun 06 1 :: :: HELP ┋
A └ fg(#000000), bg(#c0c0c0) │││ │││
A ················································└ fg(#008080), bg(#c0c0c0)
A ·················································└ fg(#c0c0c0), bg(#008080)
A ··················································└ fg(#000000), bg(#008080)
A ······································································└ fg(#000080), bg(#008080)
A ·······································································└ fg(#008080), bg(#000080)
A ········································································└ fg(#c0c0c0), bg(#000080), bold
S 2 ┋ x┋
A ···············································································└ normal, fg(#000000), bg(#c0c0c0)
A ················································································└ normal
A └┛ alt
A ················································································└ normal
S 3 ┋ lnav - A fancy log file viewer ┋
A ··└ fg(#000000), bg(#c0c0c0), normal
A ································└ carriage-return
S 5 ┋DESCRIPTION ┋
A ···········└ carriage-return
S 6 ┋=========== ┋
A ···········└ carriage-return
S 8 ┋The log file navigator, lnav, is an enhanced log file viewer that ┋
A ·································································└ carriage-return
S 9 ┋takes advantage of any semantic information that can be gleaned from ┋
A ····································································└ carriage-return
S 10 ┋the files being viewed, such as timestamps and log levels. Using this ┋
A ······································································└ carriage-return
S 11 ┋extra semantic information, lnav can do things like interleaving ┋
A ································································└ carriage-return
S 12 ┋messages from different files, generate histograms of messages over ┋
A ···································································└ carriage-return
S 13 ┋time, and providing hotkeys for navigating through the file. It is ┋
A ···································································└ carriage-return
S 14 ┋hoped that these features will allow the user to quickly and ┋
A ····························································└ carriage-return
S 15 ┋efficiently zero in on problems. ┋
A ································└ carriage-return
S 17 ┋ ┋
A ··············································································└ carriage-return
S 18 ┋OPENING PATHS/URLs x┋
A └┛ alt
A ················································································└ normal
S 19 ┋================== x┋
A └┛ alt
A ················································································└ normal
S 21 ┋The main arguments to lnav are the files, directories, glob patterns, ┋
A ·····································································└ carriage-return
S 22 ┋or URLs to be viewed. If no arguments are given, the default syslog ┋
S 24 ┋ Press e/E to move forward/backward through error message ┋
A ·····························└ bold │
A ······························└ normal │
A ·······························└ bold │
A ································└ normal │
A ···············································································└ backspace, backspace
A ··············································································└ [4h
CSI Replace mode
S 24 ┋ ┋
A ···············································································└ carriage-return
A └ normal
K 3a
CSI Erase Below
CSI Erase Below
S 24 ┋ Enter an lnav command: (Press CTRL+] to abort) ┋
A └ normal, [A │ │
A ·└ fg(#000000), bg(#c0c0c0) │ │
A ·······························└ bold│
A ·····································└ normal, fg(#000000), bg(#c0c0c0)
S 23 ┋ ┋
A ···································································└ carriage-return
S 24 ┋: ┋
A └ normal
A ·└ normal
K 65
S 24 ┋ e ┋
A ··└ normal
K 63
S 24 ┋ c ┋
A ···└ normal
K 68
S 24 ┋ h ┋
A ····└ normal
K 6f
S 24 ┋ Command Help :: ┋
A ····└ carriage-return
A └ [10A, fg(#c0c0c0), bg(#000080), bold
A ··············└ normal, fg(#c0c0c0), bg(#000080)
A ···············└ fg(#000080), bg(#c0c0c0)
A ················└ fg(#000000), bg(#c0c0c0)
S 15 ┋Synopsis ┋
A └ normal, underline
A ········└ normal, [K
S 16 ┋ :echo msg - Echo the given message ┋
A ···└ bold │ │
A ·······└ normal │
A ········└ underline │
A ···········└ normal │
A ····································└ [K, carriage-return
S 17 ┋Parameter ┋
A └ underline
A ·········└ normal, [K, carriage-return
S 18 ┋ msg The message to display ┋
A ··└ fg(#008080), bold │
A ·····└ normal │
A ······························└ [K, carriage-return
S 19 ┋See Also ┋
A └ underline
A ········└ normal, [K
S 20 ┋ :alt-msg, :eval, :redirect-to, :write-cols-to, :write-csv-to, ┋
A ··└ bold │ │ │ │ │ │ │ │ ││
A ··········└ normal │ │ │ │ │ ││
A ············└ bold │ │ │ │ │ ││
A ·················└ normal │ │ │ │ ││
A ···················└ bold │ │ │ │ ││
A ·······························└ normal │ │ ││
A ·································└ bold │ │ ││
A ···············································└ normal ││
A ·················································└ bold ││
A ······························································└ normal
A ·······························································└ [K, carriage-return
S 21 ┋ :write-json-to, :write-jsonlines-to, :write-raw-to, :write-screen-to, ┋
A ··└ bold │ │ │ │ │ │ ││
A ················└ normal │ │ │ │ ││
A ··················└ bold │ │ │ │ ││
A ·····································└ normal │ │ ││
A ·······································└ bold │ │ ││
A ····················································└ normal ││
A ······················································└ bold ││
A ······································································└ normal
A ·······································································└ [K, carriage-return
S 22 ┋ :write-to ┋
A ··└ bold │
A ···········└ normal, [K
S 24 ┋ o ┋
A ·····└ normal
K 20
S 24 ┋ echo ┋
A ·····└ backspace
A ····└ backspace
A ···└ backspace
A ··└ backspace
A ·└ fg(#000080), bold
A ······└ normal, normal
K 68
S 24 ┋ h ┋
A ·······└ normal
K 69
S 24 ┋ i ┋
A ········└ normal
K 0d
S 24 ┋ ┋
A ········└ carriage-return
CSI Erase Below
S 24 ┋hoped that these features will allow the user to quickly and x┋
A └ normal, [10A ││
A └┛ alt
A ················································································└ normal
S 15 ┋efficiently zero in on problems. x┋
A └┛ alt
A ················································································└ normal
S 16 ┋ x┋
A └┛ alt
A ················································································└ normal
S 17 ┋ x┋
A └┛ alt
A ················································································└ normal
S 18 ┋OPENING PATHS/URLs x┋
A └┛ alt
A ················································································└ normal
S 19 ┋================== x┋
A └┛ alt
A ················································································└ normal
S 20 ┋ x┋
A └┛ alt
A ················································································└ normal
S 21 ┋The main arguments to lnav are the files, directories, glob patterns, x┋
A └┛ alt
A ················································································└ normal
S 22 ┋or URLs to be viewed. If no arguments are given, the default syslog x┋
A └┛ alt
A ················································································└ normal
S 23 ┋ L0 0% ┋
A ·└ fg(#000000), bg(#c0c0c0)
S 23 ┋ ?:View Help ┋
A ···································································└ carriage-return
S 24 ┋✔ hi ┋
A └ normal, fg(#008000)
A ·└ normal
A ····└ carriage-return
A └ normal
K 71
OSC Set window title: LOG
S 1 ┋ LOG ┋
A ···········································································└ fg(#c0c0c0), bg(#000080), bold
A ···············································································└ carriage-return
S 24 ┋ ┋
A └ normal, normal
CSI Erase all
CSI Use normal screen buffer
CTRL restore cursor
S 24 ┋ ┋
A └ carriage-return
CSI Normal cursor keys
CTRL Normal keypad