mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Suppress certain stderr-printing during tests
Tests that exercise error paths may result in output to stderr. This may make it look like the test failed when it did not. Introduce should_suppress_stderr_for_tests() to suppress this output so the test output looks clean.
This commit is contained in:
parent
254762f30f
commit
754b78a748
5 changed files with 16 additions and 5 deletions
|
@ -820,7 +820,7 @@ int builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
|
|
||||||
wcstring_list_t eval_errors;
|
wcstring_list_t eval_errors;
|
||||||
bool result = expr->evaluate(eval_errors);
|
bool result = expr->evaluate(eval_errors);
|
||||||
if (!eval_errors.empty()) {
|
if (!eval_errors.empty() && ! should_suppress_stderr_for_tests()) {
|
||||||
printf("test returned eval errors:\n");
|
printf("test returned eval errors:\n");
|
||||||
for (size_t i = 0; i < eval_errors.size(); i++) {
|
for (size_t i = 0; i < eval_errors.size(); i++) {
|
||||||
printf("\t%ls\n", eval_errors.at(i).c_str());
|
printf("\t%ls\n", eval_errors.at(i).c_str());
|
||||||
|
|
|
@ -533,11 +533,15 @@ ssize_t read_loop(int fd, void *buff, size_t count) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool should_suppress_stderr_for_tests() {
|
||||||
|
// Hack to not print error messages in the tests.
|
||||||
|
return program_name && !wcscmp(program_name, TESTS_PROGRAM_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
static bool should_debug(int level) {
|
static bool should_debug(int level) {
|
||||||
if (level > debug_level) return false;
|
if (level > debug_level) return false;
|
||||||
|
|
||||||
// Hack to not print error messages in the tests.
|
if (should_suppress_stderr_for_tests()) return false;
|
||||||
if (program_name && !wcscmp(program_name, L"(ignore)")) return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,6 +373,10 @@ string_fuzzy_match_t string_fuzzy_match_string(const wcstring &string,
|
||||||
/// Test if a list contains a string using a linear search.
|
/// Test if a list contains a string using a linear search.
|
||||||
bool list_contains_string(const wcstring_list_t &list, const wcstring &str);
|
bool list_contains_string(const wcstring_list_t &list, const wcstring &str);
|
||||||
|
|
||||||
|
// Check if we are running in the test mode, where we should suppress error output
|
||||||
|
#define TESTS_PROGRAM_NAME L"(ignore)"
|
||||||
|
bool should_suppress_stderr_for_tests();
|
||||||
|
|
||||||
void assert_is_main_thread(const char *who);
|
void assert_is_main_thread(const char *who);
|
||||||
#define ASSERT_IS_MAIN_THREAD_TRAMPOLINE(x) assert_is_main_thread(x)
|
#define ASSERT_IS_MAIN_THREAD_TRAMPOLINE(x) assert_is_main_thread(x)
|
||||||
#define ASSERT_IS_MAIN_THREAD() ASSERT_IS_MAIN_THREAD_TRAMPOLINE(__FUNCTION__)
|
#define ASSERT_IS_MAIN_THREAD() ASSERT_IS_MAIN_THREAD_TRAMPOLINE(__FUNCTION__)
|
||||||
|
|
|
@ -4072,7 +4072,9 @@ int main(int argc, char **argv) {
|
||||||
srand((unsigned int)time(NULL));
|
srand((unsigned int)time(NULL));
|
||||||
configure_thread_assertions_for_testing();
|
configure_thread_assertions_for_testing();
|
||||||
|
|
||||||
program_name = L"(ignore)";
|
// Set the program name to this sentinel value
|
||||||
|
// This will prevent some misleading stderr output during the tests
|
||||||
|
program_name = TESTS_PROGRAM_NAME;
|
||||||
s_arguments = argv + 1;
|
s_arguments = argv + 1;
|
||||||
|
|
||||||
struct utsname uname_info;
|
struct utsname uname_info;
|
||||||
|
|
|
@ -708,7 +708,8 @@ parse_execution_result_t parse_execution_context_t::report_errors(
|
||||||
parser->get_backtrace(src, error_list, &backtrace_and_desc);
|
parser->get_backtrace(src, error_list, &backtrace_and_desc);
|
||||||
|
|
||||||
// Print it.
|
// Print it.
|
||||||
fprintf(stderr, "%ls", backtrace_and_desc.c_str());
|
if (! should_suppress_stderr_for_tests())
|
||||||
|
fprintf(stderr, "%ls", backtrace_and_desc.c_str());
|
||||||
}
|
}
|
||||||
return parse_execution_errored;
|
return parse_execution_errored;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue