Skip to content

Commit

Permalink
Add exit code to tests program
Browse files Browse the repository at this point in the history
  • Loading branch information
lluiscamino committed Jul 2, 2024
1 parent 7b53fe7 commit 4f77ff5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/em/Token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Token::Location Token::location() const { return mLocation; }

std::ostream& operator<<(std::ostream& os, const Token& token) {
os << "(" << TokenTypeToString(token.mType) << ", '"
<< utils::string::wStringToString(token.mText) << "', ' "
<< utils::string::wStringToString(token.mText) << "', '"
<< token.mLocation.str().c_str() << "')";
return os;
}
Expand Down
6 changes: 5 additions & 1 deletion test/utils/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include "../../src/em/utils/StringUtils.h"

namespace test::utils {
inline void runSnapshotTests(
[[nodiscard]] inline bool runSnapshotTests(
const std::filesystem::path& snapshotsPath,
const std::string& inputFilesName,
const std::string& expectedOutputFilesName,
const std::function<std::wstring(const std::wstring& input)>& getOutput) {
using namespace em::utils;
auto result = true;
auto directories = file::getDirectories(snapshotsPath);
for (const auto& directory : directories) {
auto input = file::getFileContents(directory / inputFilesName);
Expand All @@ -22,6 +23,7 @@ inline void runSnapshotTests(
try {
auto output = getOutput(input);
if (output != expectedOutput) {
result = false;
std::replace(expectedOutput.begin(), expectedOutput.end(), '\n', ';');
std::replace(output.begin(), output.end(), '\n', ';');
std::cerr << directory.c_str() << ": \""
Expand All @@ -31,9 +33,11 @@ inline void runSnapshotTests(
std::cout << directory.c_str() << ": OK!\n";
}
} catch (const std::exception& exception) {
result = false;
std::cerr << directory.c_str() << ": Program failed with error: \""
<< exception.what() << "\"\n";
}
}
return result;
}
} // namespace test::utils

0 comments on commit 4f77ff5

Please sign in to comment.