add a test_mode where the isatty() check is bypassed and history not read

this is enabled when the LAMMPS_SHELL_TESTING environment variable is set
This commit is contained in:
Axel Kohlmeyer 2020-10-13 17:09:11 -04:00
parent 114dd48779
commit 290763a844
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
1 changed files with 6 additions and 4 deletions

View File

@ -531,16 +531,18 @@ static void init_commands()
rl_readline_name = "lammps-shell";
rl_basic_word_break_characters = " \t\n\"\\'`@><=;|&(";
// attempt completions only if we are connected to a tty,
// attempt completions only if we are connected to a tty or are running tests.
// otherwise any tabs in redirected input will cause havoc.
if (isatty(fileno(stdin))) {
const char *test_mode = getenv("LAMMPS_SHELL_TESTING");
if (test_mode) std::cout << "*TESTING* using LAMMPS Shell in test mode *TESTING*\n";
if (isatty(fileno(stdin)) || test_mode) {
rl_attempted_completion_function = cmd_completion;
} else {
rl_bind_key('\t', rl_insert);
}
// read old history
read_history(".lammps_history");
// read saved history, but not in test mode.
if (!test_mode) read_history(".lammps_history");
#if !defined(_WIN32)
signal(SIGINT, ctrl_c_handler);