Skip to content

Commit

Permalink
Output result of failed tests when in suite mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cegonse committed Nov 21, 2024
1 parent d054f25 commit 91666a9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
22 changes: 14 additions & 8 deletions runner/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,23 @@ static int waitForChildren()

return status;
}

#include <iostream>
static int handleParentProcess(int pipe_fd[2], std::function<void(std::string)> on_output)
{
std::array<char, MAX_BUFFER> buffer;
std::string output = "";
close(pipe_fd[1]);

buffer.fill('\0');
close(pipe_fd[1]);
if (read(pipe_fd[0], buffer.data(), buffer.size()) < 0)
return -1;

on_output(std::string(buffer.data()));
ssize_t read_bytes = 0;
do
{
std::array<char, MAX_BUFFER> buffer;
buffer.fill('\0');
read_bytes = read(pipe_fd[0], buffer.data(), buffer.size());
buffer[read_bytes + 1] = '\0';
output += buffer.data();
} while (read_bytes != 0);

on_output(output);

return waitForChildren();
}
Expand Down
26 changes: 25 additions & 1 deletion src/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ namespace cest

if (test_case->failed)
{
std::cout << " Failed at line " << test_case->failure_line << ": " << test_case->failure_message << std::endl;
std::cout << std::endl << " Failed at line " << test_case->failure_line << ": " << test_case->failure_message << std::endl;
tryPrintFailedLines(test_case);
std::cout << std::endl;
}
}

Expand All @@ -150,5 +151,28 @@ namespace cest
const auto file = source_file.substr(file_separator_idx + 1);

std::cout << " " << ASCII_GRAY << directory << ASCII_RESET << ASCII_BOLD << file << ASCII_RESET << std::endl;

const auto failed_tests = findFailedTestCases(suite);

for (const auto test_case : failed_tests)
{
std::cout
<< std::endl
<< ASCII_BOLD
<< ASCII_RED
<< ASCII_CROSS
<< ASCII_RESET
<< ASCII_BOLD
<< " "
<< test_case->name
<< ASCII_RESET
<< std::endl
<< std::endl;

std::cout << " Failed at line " << test_case->failure_line << ": " << test_case->failure_message << std::endl << std::endl;
tryPrintFailedLines(test_case);

std::cout << std::endl;
}
}
}
19 changes: 19 additions & 0 deletions src/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,23 @@ namespace cest

return "";
}

std::vector<cest::TestCase *> findFailedTestCases(cest::TestSuite *suite)
{
std::vector<cest::TestCase *> out;

for (auto test_case : suite->test_cases)
{
if (test_case->failed)
out.push_back(test_case);
}

for (const auto &pair : suite->test_suites)
{
auto nested = findFailedTestCases(pair.second);
out.insert(out.end(), nested.begin(), nested.end());
}

return out;
}
}

0 comments on commit 91666a9

Please sign in to comment.