From 46b92b499289f01938eb09c41e168d713cfb0368 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 26 May 2022 16:14:05 +0200 Subject: [PATCH] only run termios test if stdin is a tty --- src/Compat.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Compat.cpp b/src/Compat.cpp index b5a5149..1374d3e 100644 --- a/src/Compat.cpp +++ b/src/Compat.cpp @@ -24,18 +24,20 @@ void resetTermios(void) { } TEST_CASE("init and reset termios") { - struct termios original; - tcgetattr(0, &original); - SUBCASE("no echo") { - initTermios(false); + if (isatty(STDIN_FILENO)) { + struct termios original; + tcgetattr(0, &original); + SUBCASE("no echo") { + initTermios(false); + } + SUBCASE("yes echo") { + initTermios(true); + } + resetTermios(); + struct termios current; + tcgetattr(0, ¤t); + CHECK(std::memcmp(&original, ¤t, sizeof(struct termios)) == 0); } - SUBCASE("yes echo") { - initTermios(true); - } - resetTermios(); - struct termios current; - tcgetattr(0, ¤t); - CHECK(std::memcmp(&original, ¤t, sizeof(struct termios)) == 0); } char getch_(int echo) {