diff --git a/src/lnav.cc b/src/lnav.cc index 88186ad844..e77f0c3f51 100644 --- a/src/lnav.cc +++ b/src/lnav.cc @@ -2674,7 +2674,9 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'), lnav_data.ld_files_view.set_selection(0_vl); } } - lnav_data.ld_views[LNV_LOG].set_top_for_last_row(); + if (!lnav_data.ld_views[LNV_LOG].get_selection().has_value()) { + lnav_data.ld_views[LNV_LOG].set_top_for_last_row(); + } lnav::session::restore_view_states(); lnav_data.ld_active_files.fc_files | lnav::itertools::for_each(&logfile::dump_stats); diff --git a/test/Makefile.am b/test/Makefile.am index 556bb45524..f93c7fd114 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -519,6 +519,7 @@ dist_noinst_DATA = \ UTF-8-test.txt \ view_colors_output.0 \ xpath_tui.0 \ + goto_tui.0 \ configs/installed/anno-test.json \ configs/installed/anno-test.sh \ configs/installed/hw-url-handler.json \ diff --git a/test/goto_tui.0 b/test/goto_tui.0 new file mode 100644 index 0000000000..26b0b22a66 --- /dev/null +++ b/test/goto_tui.0 @@ -0,0 +1,2 @@ +K 71 +# Key: q diff --git a/test/scripty.cc b/test/scripty.cc index 24d8234394..22ecdb6d59 100644 --- a/test/scripty.cc +++ b/test/scripty.cc @@ -1201,6 +1201,7 @@ usage() " -h Print this message, then exit.\n" " -n Do not pass the output to the console.\n" " -X Set TERM to xterm-256color.\n" + " -r Replay input without comparing the terminal output.\n" " -i Pass stdin to the child process instead of connecting\n" " the child to the tty.\n" " -a The file where the actual I/O from/to the child " @@ -1225,14 +1226,14 @@ int main(int argc, char* argv[]) { int c, fd, retval = EXIT_SUCCESS; - bool passout = true, prompt = false; + bool passout = true, prompt = false, compare_output = true; const char* term_type = "xterm"; auto force_update = getenv("SCRIPTY_FORCE_UPDATE") != nullptr; scripty_data.sd_program_name = argv[0]; scripty_data.sd_looping = true; - while ((c = getopt(argc, argv, "ha:e:nipSX")) != -1) { + while ((c = getopt(argc, argv, "ha:e:nipSXr")) != -1) { switch (c) { case 'h': usage(); @@ -1267,6 +1268,9 @@ main(int argc, char* argv[]) case 'n': passout = false; break; + case 'r': + compare_output = false; + break; case 'p': prompt = true; break; @@ -1521,7 +1525,9 @@ main(int argc, char* argv[]) } fprintf(stderr, "%s:done!\n", tstamp()); - if (retval == EXIT_SUCCESS && !scripty_data.sd_expected_name.empty()) { + if (retval == EXIT_SUCCESS && compare_output + && !scripty_data.sd_expected_name.empty()) + { auto cmd = fmt::format("diff -ua {} {}", scripty_data.sd_expected_name.string(), scripty_data.sd_actual_name.string()); diff --git a/test/test_tui.sh b/test/test_tui.sh index d902ddc9e8..d9e7c022d8 100644 --- a/test/test_tui.sh +++ b/test/test_tui.sh @@ -33,3 +33,29 @@ run_test ./scripty -nX -e ${srcdir}/xpath_tui.0 -- \ ${srcdir}/logfile_xml_msg.0 on_error_log "xpath() fields are not working?" + +# These checks exercise startup and session restoration without comparing transient +# screen redraws. scripty still checks that the child exits successfully. +run_test ./scripty -nrX -e ${srcdir}/goto_tui.0 -- \ + ${lnav_test} -d ./tui-home/goto-default.err ${srcdir}/logfile_partitions.0 +on_error_fail_with "Could not open the log at its default position" +run_test grep -E 'log view actual top/selection: [0-9]+/81$' ./tui-home/goto-default.err +on_error_fail_with "Default log selection should be the last line" + +run_test ./scripty -nrX -e ${srcdir}/goto_tui.0 -- \ + ${lnav_test} -d ./tui-home/goto-explicit.err -c ':goto 2' ${srcdir}/logfile_partitions.0 +on_error_fail_with "Could not run the initial goto command" +run_test grep -E 'log view actual top/selection: [0-9]+/2$' ./tui-home/goto-explicit.err +on_error_fail_with "Initial goto selection was lost when restoring the session" + +run_test ./scripty -nrX -e ${srcdir}/goto_tui.0 -- \ + ${lnav_test} -d ./tui-home/goto-restored.err ${srcdir}/logfile_partitions.0 +on_error_fail_with "Could not reopen the log" +run_test grep -E 'log view actual top/selection: [0-9]+/2$' ./tui-home/goto-restored.err +on_error_fail_with "Saved log selection was not restored" + +run_test ./scripty -nrX -e ${srcdir}/goto_tui.0 -- \ + ${lnav_test} -d ./tui-home/goto-override.err -c ':goto 5' ${srcdir}/logfile_partitions.0 +on_error_fail_with "Could not override the saved log selection" +run_test grep -E 'log view actual top/selection: [0-9]+/5$' ./tui-home/goto-override.err +on_error_fail_with "Initial goto should override the saved selection"