mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Test: Corrected util.cpp/confirm calls to check std::cin::eof
This commit is contained in:
parent
3433770e9b
commit
5914418fb1
2 changed files with 17 additions and 13 deletions
26
src/util.cpp
26
src/util.cpp
|
@ -77,13 +77,13 @@ bool confirm (const std::string& question)
|
|||
std::string answer {""};
|
||||
std::getline (std::cin, answer);
|
||||
context.debug ("STDIN '" + answer + "'");
|
||||
answer = std::cin.eof() ? STRING_UTIL_CONFIRM_NO : lowerCase (trim (answer));
|
||||
answer = std::cin.eof () ? STRING_UTIL_CONFIRM_NO : lowerCase (trim (answer));
|
||||
|
||||
autoComplete (answer, options, matches, 1); // Hard-coded 1.
|
||||
}
|
||||
while (matches.size () != 1);
|
||||
while (! std::cin.eof () && matches.size () != 1);
|
||||
|
||||
return matches[0] == STRING_UTIL_CONFIRM_YES ? true : false;
|
||||
return matches.size () == 1 && matches[0] == STRING_UTIL_CONFIRM_YES ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -114,17 +114,21 @@ int confirm4 (const std::string& question)
|
|||
std::string answer {""};
|
||||
std::getline (std::cin, answer);
|
||||
context.debug ("STDIN '" + answer + "'");
|
||||
answer = trim (answer);
|
||||
answer = std::cin.eof () ? STRING_UTIL_CONFIRM_QUIT : lowerCase (trim (answer));
|
||||
autoComplete (answer, options, matches, 1); // Hard-coded 1.
|
||||
}
|
||||
while (matches.size () != 1);
|
||||
while (! std::cin.eof () && matches.size () != 1);
|
||||
|
||||
if (matches[0] == STRING_UTIL_CONFIRM_YES_U) return 1;
|
||||
else if (matches[0] == STRING_UTIL_CONFIRM_YES) return 1;
|
||||
else if (matches[0] == STRING_UTIL_CONFIRM_ALL_U) return 2;
|
||||
else if (matches[0] == STRING_UTIL_CONFIRM_ALL) return 2;
|
||||
else if (matches[0] == STRING_UTIL_CONFIRM_QUIT) return 3;
|
||||
else return 0;
|
||||
if (matches.size () == 1)
|
||||
{
|
||||
if (matches[0] == STRING_UTIL_CONFIRM_YES_U) return 1;
|
||||
else if (matches[0] == STRING_UTIL_CONFIRM_YES) return 1;
|
||||
else if (matches[0] == STRING_UTIL_CONFIRM_ALL_U) return 2;
|
||||
else if (matches[0] == STRING_UTIL_CONFIRM_ALL) return 2;
|
||||
else if (matches[0] == STRING_UTIL_CONFIRM_QUIT) return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -106,7 +106,7 @@ class TestDelete(TestCase):
|
|||
|
||||
# Would expect 2 yes via input only 1 sent
|
||||
code, out, err = self._validate_prompt_loop(input="y\n")
|
||||
self.assertEqual(code, 0)
|
||||
self.assertEqual(code, 1)
|
||||
|
||||
def test_delete_bulk_prompt_loop(self):
|
||||
"""Delete prompt with closed STDIN causes infinite loop and floods stdout (bulk)"""
|
||||
|
@ -121,7 +121,7 @@ class TestDelete(TestCase):
|
|||
# Would expect 3 yes via input only 2 sent
|
||||
code, out, err = self._validate_prompt_loop(input="y\ny\n")
|
||||
|
||||
self.assertEqual(code, 0)
|
||||
self.assertEqual(code, 1)
|
||||
|
||||
def _validate_prompt_loop(self, input=""):
|
||||
"""Helper method to check if task flooded stream on closed STDIN"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue