mirror of
https://github.com/tstack/lnav.git
synced 2024-08-17 08:50:41 +03:00
[headless] report output from commands/queries that were executed
Also, add some negative test cases.
This commit is contained in:
parent
9848582239
commit
fea18347f1
@ -34,7 +34,7 @@ LAST_TEST=""
|
||||
#
|
||||
run_test() {
|
||||
LAST_TEST="test: $@"
|
||||
"$@" > ${test_file_base}_${test_num}.tmp 2>&1
|
||||
"$@" > ${test_file_base}_${test_num}.tmp 2> ${test_file_base}_${test_num}.err
|
||||
}
|
||||
|
||||
#
|
||||
@ -58,11 +58,22 @@ check_output() {
|
||||
echo $LAST_TEST
|
||||
echo $1
|
||||
cat ${test_file_base}_${test_num}.diff
|
||||
exit 1
|
||||
exit 1
|
||||
fi
|
||||
test_num=`expr ${test_num} \+ 1`
|
||||
}
|
||||
|
||||
check_error_output() {
|
||||
diff -u ${test_file_base}_${test_num}.err - \
|
||||
> ${test_file_base}_${test_num}.err.diff
|
||||
if test $? -ne 0; then
|
||||
echo $LAST_TEST
|
||||
echo $1
|
||||
cat ${test_file_base}_${test_num}.err.diff
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Grep for a string in the output generated by a run_test() call.
|
||||
#
|
||||
|
55
src/lnav.cc
55
src/lnav.cc
@ -846,7 +846,9 @@ public:
|
||||
this->tds_lines.push_back(text.substr(start, end - start));
|
||||
start = end + 1;
|
||||
}
|
||||
this->tds_lines.push_back(text.substr(start));
|
||||
if (start < text.length()) {
|
||||
this->tds_lines.push_back(text.substr(start));
|
||||
}
|
||||
};
|
||||
|
||||
size_t text_line_count()
|
||||
@ -2070,7 +2072,7 @@ string execute_sql(string sql, string &alt_msg)
|
||||
if (retcode != SQLITE_OK) {
|
||||
const char *errmsg = sqlite3_errmsg(lnav_data.ld_db);
|
||||
|
||||
retval = errmsg;
|
||||
retval = "error: " + string(errmsg);
|
||||
alt_msg = "";
|
||||
}
|
||||
else if (stmt == NULL) {
|
||||
@ -2112,9 +2114,9 @@ string execute_sql(string sql, string &alt_msg)
|
||||
default: {
|
||||
const char *errmsg;
|
||||
|
||||
log_error("code %d", retcode);
|
||||
log_error("sqlite3_step error code: %d", retcode);
|
||||
errmsg = sqlite3_errmsg(lnav_data.ld_db);
|
||||
retval = errmsg;
|
||||
retval = "error: " + string(errmsg);
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
@ -2158,7 +2160,7 @@ string execute_sql(string sql, string &alt_msg)
|
||||
"in the log view");
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (sqlite3_stmt_readonly(stmt.in())) {
|
||||
retval = "No rows matched";
|
||||
alt_msg = "";
|
||||
}
|
||||
@ -2243,7 +2245,7 @@ static void execute_file(string path)
|
||||
}
|
||||
}
|
||||
|
||||
void execute_init_commands(readline_curses *rc)
|
||||
void execute_init_commands(vector<pair<string, string> > &msgs)
|
||||
{
|
||||
if (lnav_data.ld_commands.empty()) {
|
||||
return;
|
||||
@ -2267,10 +2269,8 @@ void execute_init_commands(readline_curses *rc)
|
||||
execute_file(iter->substr(1));
|
||||
break;
|
||||
}
|
||||
if (rc != NULL) {
|
||||
rc->set_value(msg);
|
||||
rc->set_alt_value(alt_msg);
|
||||
}
|
||||
|
||||
msgs.push_back(make_pair(msg, alt_msg));
|
||||
}
|
||||
lnav_data.ld_commands.clear();
|
||||
}
|
||||
@ -3313,7 +3313,18 @@ static void looper(void)
|
||||
session_loaded = true;
|
||||
}
|
||||
|
||||
execute_init_commands(lnav_data.ld_rl_view);
|
||||
{
|
||||
vector<pair<string, string> > msgs;
|
||||
|
||||
execute_init_commands(msgs);
|
||||
|
||||
if (!msgs.empty()) {
|
||||
pair<string, string> last_msg = msgs.back();
|
||||
|
||||
lnav_data.ld_rl_view->set_value(last_msg.first);
|
||||
lnav_data.ld_rl_view->set_alt_value(last_msg.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (FD_ISSET(STDIN_FILENO, &ready_rfds)) {
|
||||
@ -4097,9 +4108,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (lnav_data.ld_flags & LNF_HEADLESS) {
|
||||
std::vector<pair<string, string> > msgs;
|
||||
std::vector<pair<string, string> >::iterator msg_iter;
|
||||
textview_curses *tc;
|
||||
attr_line_t al;
|
||||
const std::string &line = al.get_string();
|
||||
bool found_error = false;
|
||||
|
||||
alerter::singleton().enabled(false);
|
||||
|
||||
@ -4108,9 +4122,24 @@ int main(int argc, char *argv[])
|
||||
|
||||
lnav_data.ld_views[LNV_LOG].set_top(vis_line_t(0));
|
||||
|
||||
execute_init_commands(NULL);
|
||||
execute_init_commands(msgs);
|
||||
if (rescan_files()) {
|
||||
rebuild_indexes(true);
|
||||
}
|
||||
|
||||
if (!lnav_data.ld_view_stack.empty() &&
|
||||
for (msg_iter = msgs.begin();
|
||||
msg_iter != msgs.end();
|
||||
++msg_iter) {
|
||||
if (strncmp("error:", msg_iter->first.c_str(), 6) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s\n", msg_iter->first.c_str());
|
||||
found_error = true;
|
||||
}
|
||||
|
||||
if (!found_error &&
|
||||
!lnav_data.ld_view_stack.empty() &&
|
||||
!lnav_data.ld_stdout_used) {
|
||||
bool suppress_empty_lines = false;
|
||||
list_overlay_source *los;
|
||||
|
@ -129,11 +129,13 @@ scripty_SOURCES = scripty.cc
|
||||
|
||||
dist_noinst_SCRIPTS = \
|
||||
parser_debugger.py \
|
||||
test_cmds.sh \
|
||||
test_data_parser.sh \
|
||||
test_grep_proc.sh \
|
||||
test_line_buffer.sh \
|
||||
test_listview.sh \
|
||||
test_logfile.sh \
|
||||
test_sql.sh \
|
||||
test_sql_coll_func.sh \
|
||||
test_sql_str_func.sh \
|
||||
test_sql_fs_func.sh \
|
||||
@ -162,6 +164,7 @@ dist_noinst_DATA = \
|
||||
logfile_empty.0 \
|
||||
logfile_generic.0 \
|
||||
logfile_glog.0 \
|
||||
logfile_multiline.0 \
|
||||
logfile_strace_log.0 \
|
||||
logfile_syslog.0 \
|
||||
logfile_syslog.1 \
|
||||
@ -185,6 +188,7 @@ TESTS = \
|
||||
test_auto_fd \
|
||||
test_auto_mem \
|
||||
test_bookmarks \
|
||||
test_cmds.sh \
|
||||
test_line_buffer.sh \
|
||||
test_line_buffer2 \
|
||||
test_listview.sh \
|
||||
|
@ -92,7 +92,7 @@ check_PROGRAMS = drive_data_scanner$(EXEEXT) \
|
||||
test_pcrepp$(EXEEXT) test_top_status$(EXEEXT) \
|
||||
test_yajlpp$(EXEEXT)
|
||||
TESTS = test_ansi_scrubber$(EXEEXT) test_auto_fd$(EXEEXT) \
|
||||
test_auto_mem$(EXEEXT) test_bookmarks$(EXEEXT) \
|
||||
test_auto_mem$(EXEEXT) test_bookmarks$(EXEEXT) test_cmds.sh \
|
||||
test_line_buffer.sh test_line_buffer2$(EXEEXT) \
|
||||
test_listview.sh test_grep_proc.sh test_grep_proc2$(EXEEXT) \
|
||||
test_hist_source$(EXEEXT) test_pcrepp$(EXEEXT) test_sql.sh \
|
||||
@ -684,11 +684,13 @@ slicer_LDADD = ../src/libdiag.a
|
||||
scripty_SOURCES = scripty.cc
|
||||
dist_noinst_SCRIPTS = \
|
||||
parser_debugger.py \
|
||||
test_cmds.sh \
|
||||
test_data_parser.sh \
|
||||
test_grep_proc.sh \
|
||||
test_line_buffer.sh \
|
||||
test_listview.sh \
|
||||
test_logfile.sh \
|
||||
test_sql.sh \
|
||||
test_sql_coll_func.sh \
|
||||
test_sql_str_func.sh \
|
||||
test_sql_fs_func.sh \
|
||||
@ -717,6 +719,7 @@ dist_noinst_DATA = \
|
||||
logfile_empty.0 \
|
||||
logfile_generic.0 \
|
||||
logfile_glog.0 \
|
||||
logfile_multiline.0 \
|
||||
logfile_strace_log.0 \
|
||||
logfile_syslog.0 \
|
||||
logfile_syslog.1 \
|
||||
@ -1138,6 +1141,13 @@ test_bookmarks.log: test_bookmarks$(EXEEXT)
|
||||
--log-file $$b.log --trs-file $$b.trs \
|
||||
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
|
||||
"$$tst" $(AM_TESTS_FD_REDIRECT)
|
||||
test_cmds.sh.log: test_cmds.sh
|
||||
@p='test_cmds.sh'; \
|
||||
b='test_cmds.sh'; \
|
||||
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
|
||||
--log-file $$b.log --trs-file $$b.trs \
|
||||
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
|
||||
"$$tst" $(AM_TESTS_FD_REDIRECT)
|
||||
test_line_buffer.sh.log: test_line_buffer.sh
|
||||
@p='test_line_buffer.sh'; \
|
||||
b='test_line_buffer.sh'; \
|
||||
|
3
test/logfile_multiline.0
Normal file
3
test/logfile_multiline.0
Normal file
@ -0,0 +1,3 @@
|
||||
2009-07-20 22:59:27,672:DEBUG:Hello, World!
|
||||
How are you today?
|
||||
2009-07-20 22:59:30,221:ERROR:Goodbye, World!
|
98
test/test_cmds.sh
Normal file
98
test/test_cmds.sh
Normal file
@ -0,0 +1,98 @@
|
||||
#! /bin/bash
|
||||
|
||||
lnav_test="${top_builddir}/src/lnav-test"
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":adjust-log-time 2010-01-01T00:00:00" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "adjust-log-time is not working" <<EOF
|
||||
192.168.202.254 - - [01/Jan/2010:00:00:00 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
|
||||
192.168.202.254 - - [01/Jan/2010:00:00:03 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
|
||||
192.168.202.254 - - [01/Jan/2010:00:00:03 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":goto 1" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "goto 1 is not working" <<EOF
|
||||
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
|
||||
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":goto -1" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "goto -1 is not working" <<EOF
|
||||
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":filter-in vmk" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "filter-in vmk is not working" <<EOF
|
||||
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
|
||||
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":filter-in today" \
|
||||
${test_dir}/logfile_multiline.0
|
||||
|
||||
check_output "filter-in multiline is not working" <<EOF
|
||||
2009-07-20 22:59:27,672:DEBUG:Hello, World!
|
||||
How are you today?
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":filter-out vmk" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "filter-out vmk is not working" <<EOF
|
||||
192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":filter-out today" \
|
||||
${test_dir}/logfile_multiline.0
|
||||
|
||||
check_output "filter-out multiline is not working" <<EOF
|
||||
2009-07-20 22:59:30,221:ERROR:Goodbye, World!
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":switch-to-view help" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "switch-to-view help is not working" < ${top_srcdir}/src/help.txt
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":close" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "close is not working" <<EOF
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":close" \
|
||||
-c ":open ${test_dir}/logfile_multiline.0" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "open is not working" <<EOF
|
||||
2009-07-20 22:59:27,672:DEBUG:Hello, World!
|
||||
How are you today?
|
||||
2009-07-20 22:59:30,221:ERROR:Goodbye, World!
|
||||
EOF
|
@ -41,7 +41,10 @@ EOF
|
||||
|
||||
run_test grep_capture '(\w+), World' gp.dat
|
||||
|
||||
check_output "grep_proc didn't capture matches?" <<EOF
|
||||
check_error_output "grep_proc didn't capture matches?" <<EOF
|
||||
0(0:5)Hello
|
||||
1(0:7)Goodbye
|
||||
EOF
|
||||
|
||||
check_output "grep_proc didn't capture matches?" <<EOF
|
||||
EOF
|
||||
|
@ -104,3 +104,27 @@ CREATE TABLE http_status_codes (
|
||||
FOREIGN KEY(status) REFERENCES access_log(sc_status)
|
||||
);
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ";select * from nonexistent_table" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_error_output "errors are not reported" <<EOF
|
||||
error: no such table: nonexistent_table
|
||||
EOF
|
||||
|
||||
check_output "errors are not reported" <<EOF
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ";delete from access_log" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_error_output "errors are not reported" <<EOF
|
||||
error: attempt to write a readonly database
|
||||
EOF
|
||||
|
||||
check_output "errors are not reported" <<EOF
|
||||
EOF
|
||||
|
Loading…
Reference in New Issue
Block a user