mirror of https://github.com/tstack/lnav.git
[cover] add some tests for :unix-time
This commit is contained in:
parent
af9cea19e2
commit
c5ab97352d
|
@ -30,7 +30,19 @@ jobs:
|
|||
- name: upload cover
|
||||
env:
|
||||
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
|
||||
run: coveralls --gcov-options '\-lp'
|
||||
run: >
|
||||
coveralls
|
||||
--exclude doctest.hh
|
||||
--exclude fmtlib
|
||||
--exclude ghc
|
||||
--exclude k_merge_tree.h
|
||||
--exclude mapbox
|
||||
--exclude pugixml
|
||||
--exclude result.h
|
||||
--exclude safe
|
||||
--exclude spookyhash
|
||||
--exclude ww898
|
||||
--gcov-options '\-lp'
|
||||
- name: make distcheck
|
||||
run: make distcheck -j4 || (test -e lnav-*/_build/sub/test/test-suite.log && cat lnav-*/_build/sub/test/test-suite.log)
|
||||
- name: Upload a Build Artifact
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
# aminclude_static.am generated automatically by Autoconf
|
||||
# from AX_AM_MACROS_STATIC on Fri Jan 29 18:52:23 PST 2021
|
||||
# from AX_AM_MACROS_STATIC on Sat Jan 30 21:49:56 PST 2021
|
||||
|
||||
|
||||
# Code coverage
|
||||
|
|
|
@ -383,7 +383,7 @@ Result<string, string> execute_sql(exec_context &ec, const string &sql, string &
|
|||
}
|
||||
#ifdef HAVE_SQLITE3_STMT_READONLY
|
||||
else if (sqlite3_stmt_readonly(stmt.in())) {
|
||||
retval = "No rows matched";
|
||||
retval = "info: No rows matched";
|
||||
alt_msg = "";
|
||||
|
||||
if (lnav_data.ld_flags & LNF_HEADLESS) {
|
||||
|
|
20
src/lnav.cc
20
src/lnav.cc
|
@ -2583,7 +2583,7 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
|
|||
if (lnav_data.ld_flags & LNF_HEADLESS) {
|
||||
std::vector<pair<Result<string, string>, string>> cmd_results;
|
||||
textview_curses *log_tc, *text_tc, *tc;
|
||||
bool found_error = false;
|
||||
bool output_view = true;
|
||||
|
||||
view_colors::init();
|
||||
rescan_files(true);
|
||||
|
@ -2630,15 +2630,23 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
|
|||
for (auto &pair : cmd_results) {
|
||||
if (pair.first.isErr()) {
|
||||
fprintf(stderr, "%s\n", pair.first.unwrapErr().c_str());
|
||||
found_error = true;
|
||||
output_view = false;
|
||||
}
|
||||
else if (startswith(pair.first.unwrap(), "info:") &&
|
||||
lnav_data.ld_flags & LNF_VERBOSE) {
|
||||
printf("%s\n", pair.first.unwrap().c_str());
|
||||
else {
|
||||
auto msg = pair.first.unwrap();
|
||||
|
||||
if (startswith(msg, "info:")) {
|
||||
if (lnav_data.ld_flags & LNF_VERBOSE) {
|
||||
printf("%s\n", msg.c_str());
|
||||
}
|
||||
} else if (!msg.empty()) {
|
||||
printf("%s\n", msg.c_str());
|
||||
output_view = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_error &&
|
||||
if (output_view &&
|
||||
!(lnav_data.ld_flags & LNF_QUIET) &&
|
||||
!lnav_data.ld_view_stack.vs_views.empty() &&
|
||||
!lnav_data.ld_stdout_used) {
|
||||
|
|
|
@ -205,18 +205,17 @@ static Result<string, string> com_adjust_log_time(exec_context &ec, string cmdli
|
|||
|
||||
static Result<string, string> com_unix_time(exec_context &ec, string cmdline, vector<string> &args)
|
||||
{
|
||||
string retval = "error: ";
|
||||
string retval;
|
||||
|
||||
if (args.empty()) { }
|
||||
else if (args.size() >= 2) {
|
||||
char ftime[128] = "";
|
||||
bool parsed = false;
|
||||
struct tm log_time;
|
||||
time_t u_time;
|
||||
size_t millis;
|
||||
char * rest;
|
||||
|
||||
u_time = time(NULL);
|
||||
u_time = time(nullptr);
|
||||
log_time = *localtime(&u_time);
|
||||
|
||||
log_time.tm_isdst = -1;
|
||||
|
@ -228,11 +227,11 @@ static Result<string, string> com_unix_time(exec_context &ec, string cmdline, ve
|
|||
}
|
||||
if (((rest = strptime(args[1].c_str(),
|
||||
"%b %d %H:%M:%S %Y",
|
||||
&log_time)) != NULL &&
|
||||
&log_time)) != nullptr &&
|
||||
(rest - args[1].c_str()) >= 20) ||
|
||||
((rest = strptime(args[1].c_str(),
|
||||
"%Y-%m-%d %H:%M:%S",
|
||||
&log_time)) != NULL &&
|
||||
&log_time)) != nullptr &&
|
||||
(rest - args[1].c_str()) >= 19)) {
|
||||
u_time = mktime(&log_time);
|
||||
parsed = true;
|
||||
|
@ -243,6 +242,7 @@ static Result<string, string> com_unix_time(exec_context &ec, string cmdline, ve
|
|||
parsed = true;
|
||||
}
|
||||
if (parsed) {
|
||||
char ftime[128];
|
||||
int len;
|
||||
|
||||
strftime(ftime, sizeof(ftime),
|
||||
|
@ -250,7 +250,7 @@ static Result<string, string> com_unix_time(exec_context &ec, string cmdline, ve
|
|||
localtime(&u_time));
|
||||
len = strlen(ftime);
|
||||
snprintf(ftime + len, sizeof(ftime) - len,
|
||||
" -- %ld\n",
|
||||
" -- %ld",
|
||||
u_time);
|
||||
retval = string(ftime);
|
||||
} else {
|
||||
|
@ -949,7 +949,7 @@ static Result<string, string> com_save_to(exec_context &ec, string cmdline, vect
|
|||
lnav_data.ld_preview_status_source.get_description()
|
||||
.set_value("First lines of file: %s", fn.c_str());
|
||||
} else {
|
||||
retval = "Wrote " + to_string(line_count) + " rows to " + split_args[0];
|
||||
retval = "info: Wrote " + to_string(line_count) + " rows to " + split_args[0];
|
||||
}
|
||||
if (toclose != nullptr) {
|
||||
closer(toclose);
|
||||
|
@ -2202,7 +2202,7 @@ static Result<string, string> com_file_visibility(exec_context &ec, string cmdli
|
|||
};
|
||||
tc->get_sub_source()->text_filters_changed();
|
||||
}
|
||||
retval = fmt::format("{} file -- {}",
|
||||
retval = fmt::format("info: {} file -- {}",
|
||||
make_visible ? "showing" : "hiding",
|
||||
lf->get_filename());
|
||||
} else {
|
||||
|
@ -2251,7 +2251,7 @@ static Result<string, string> com_file_visibility(exec_context &ec, string cmdli
|
|||
if (!ec.ec_dry_run && text_file_count > 0) {
|
||||
lnav_data.ld_views[LNV_TEXT].get_sub_source()->text_filters_changed();
|
||||
}
|
||||
retval = fmt::format(FMT_STRING("{} {:L} log files and {:L} text files"),
|
||||
retval = fmt::format(FMT_STRING("info: {} {:L} log files and {:L} text files"),
|
||||
make_visible ? "showing" : "hiding",
|
||||
log_file_count,
|
||||
text_file_count);
|
||||
|
|
|
@ -1,6 +1,24 @@
|
|||
#! /bin/bash
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":unix-time" \
|
||||
"${test_dir}/logfile_access_log.*"
|
||||
|
||||
check_error_output ":unix-time works without arg?" <<EOF
|
||||
command-option:1: error: expecting a unix time value
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":unix-time 1612072409" \
|
||||
"${test_dir}/logfile_access_log.*"
|
||||
|
||||
check_output ":unix-time does not convert time correctly?" <<EOF
|
||||
Sat Jan 30 21:53:29 2021 -0800 PST -- 1612072409
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n -d /tmp/lnav.err \
|
||||
-c ";SELECT 1 AS c1, 'Hello ' || char(10) || 'World!' AS c2" \
|
||||
-c ":write-csv-to -" \
|
||||
|
|
Loading…
Reference in New Issue