Improve coding style in test utilities

This commit is contained in:
Martchus 2017-10-24 01:02:07 +02:00
parent 2203e0a335
commit dab05bdade
2 changed files with 86 additions and 82 deletions

View File

@ -1,5 +1,5 @@
#ifndef CPPUNIT_H
#define CPPUNIT_H
#ifndef TESTUTILS_CPPUNIT_H
#define TESTUTILS_CPPUNIT_H
#include "./testutils.h"
@ -19,7 +19,10 @@ using namespace CPPUNIT_NS;
int main(int argc, char **argv)
{
TestApplication testApp(argc, argv);
if (testApp) {
if (!testApp) {
return -1;
}
// run tests
TextUi::TestRunner runner;
TestFactoryRegistry &registry = TestFactoryRegistry::getRegistry();
@ -38,9 +41,6 @@ int main(int argc, char **argv)
}
}
return !runner.run(string(), false);
} else {
return -1;
}
}
#endif // CPPUNIT_H
#endif // TESTUTILS_CPPUNIT_H

View File

@ -3,6 +3,7 @@
#include "../application/failure.h"
#include "../conversion/stringbuilder.h"
#include "../conversion/stringconversion.h"
#include "../io/ansiescapecodes.h"
#include "../io/catchiofailure.h"
#include <cstdlib>
@ -22,6 +23,7 @@
using namespace std;
using namespace ApplicationUtilities;
using namespace ConversionUtilities;
using namespace EscapeCodes;
using namespace IoUtilities;
/*!
@ -77,6 +79,11 @@ TestApplication::TestApplication(int argc, char **argv)
// parse arguments
try {
m_parser.parseArgs(argc, argv);
} catch (const Failure &failure) {
cerr << failure;
m_valid = false;
return;
}
// print help
if (m_helpArg.isPresent()) {
@ -127,11 +134,7 @@ TestApplication::TestApplication(int argc, char **argv)
}
m_valid = true;
cerr << "Executing test cases ..." << endl;
} catch (const Failure &failure) {
cerr << "Invalid arguments specified: " << failure.what() << endl;
m_valid = false;
}
cerr << TextAttribute::Bold << "Executing test cases ..." << Phrases::EndFlush;
}
/*!
@ -171,7 +174,7 @@ string TestApplication::testFilePath(const string &name) const
file.clear();
file.open(path = "./testfiles/" + name, ios_base::in);
if (!file.good()) {
cerr << "Warning: The testfile \"" << path << "\" can not be located." << endl;
cerr << Phrases::Warning << "The testfile \"" << path << "\" can not be located." << Phrases::EndFlush;
}
return path;
}
@ -192,7 +195,7 @@ string TestApplication::workingCopyPathMode(const string &name, WorkingCopyMode
struct stat currentStat;
if (stat(m_workingDir.c_str(), &currentStat) || !S_ISDIR(currentStat.st_mode)) {
if (mkdir(m_workingDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
cerr << "Unable to create working copy for \"" << name << "\": can't create working directory." << endl;
cerr << Phrases::Error << "Unable to create working copy for \"" << name << "\": can't create working directory." << Phrases::EndFlush;
return string();
}
}
@ -208,7 +211,8 @@ string TestApplication::workingCopyPathMode(const string &name, WorkingCopyMode
currentLevel += *i;
if (stat(currentLevel.c_str(), &currentStat) || !S_ISDIR(currentStat.st_mode)) {
if (mkdir(currentLevel.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
cerr << "Unable to create working copy for \"" << name << "\": can't create working directory." << endl;
cerr << Phrases::Error << "Unable to create working copy for \"" << name << "\": can't create working directory."
<< Phrases::EndFlush;
return string();
}
}
@ -225,7 +229,7 @@ string TestApplication::workingCopyPathMode(const string &name, WorkingCopyMode
return path;
} catch (...) {
catchIoFailure();
cerr << "Unable to create working copy for \"" << name << "\": an IO error occured." << endl;
cerr << Phrases::Error << "Unable to create working copy for \"" << name << "\": an IO error occured." << Phrases::EndFlush;
}
} else {
return m_workingDir + name;
@ -288,7 +292,7 @@ int execAppInternal(const char *appPath, const char *const *args, std::string &o
// poll succeeds
if (fileDescriptorSet[0].revents & POLLIN) {
if ((count = read(readCoutPipe, buffer, sizeof(buffer))) > 0) {
output.append(buffer, count);
output.append(buffer, static_cast<size_t>(count));
}
} else if (fileDescriptorSet[0].revents & POLLHUP) {
close(readCoutPipe);
@ -296,7 +300,7 @@ int execAppInternal(const char *appPath, const char *const *args, std::string &o
}
if (fileDescriptorSet[1].revents & POLLIN) {
if ((count = read(readCerrPipe, buffer, sizeof(buffer))) > 0) {
errors.append(buffer, count);
errors.append(buffer, static_cast<size_t>(count));
}
} else if (fileDescriptorSet[1].revents & POLLHUP) {
close(readCerrPipe);
@ -333,7 +337,7 @@ int execAppInternal(const char *appPath, const char *const *args, std::string &o
// -> execute application
execv(appPath, const_cast<char *const *>(args));
cerr << "Unable to execute \"" << appPath << "\": execv() failed" << endl;
cerr << Phrases::Error << "Unable to execute \"" << appPath << "\": execv() failed" << Phrases::EndFlush;
exit(-101);
}
}