Reuse constant objects in testpathmatch.cpp, small simplification in testsuppressions.cpp and testthreadexecutor.cpp

This commit is contained in:
PKEuS 2013-08-07 17:55:31 +02:00
parent a65e08b648
commit 36dba8373b
3 changed files with 57 additions and 106 deletions

View File

@ -23,10 +23,19 @@
class TestPathMatch : public TestFixture {
public:
TestPathMatch() : TestFixture("TestPathMatch") {
TestPathMatch()
: TestFixture("TestPathMatch")
, emptyMatcher(std::vector<std::string>())
, srcMatcher(std::vector<std::string>(1, "src/"))
, fooCppMatcher(std::vector<std::string>(1, "foo.cpp"))
, srcFooCppMatcher(std::vector<std::string>(1, "src/foo.cpp")) {
}
private:
const PathMatch emptyMatcher;
const PathMatch srcMatcher;
const PathMatch fooCppMatcher;
const PathMatch srcFooCppMatcher;
void run() {
TEST_CASE(emptymaskemptyfile);
@ -58,105 +67,68 @@ private:
TEST_CASE(filemaskpath4);
}
// Test empty PathMatch
void emptymaskemptyfile() const {
std::vector<std::string> masks;
PathMatch match(masks);
ASSERT(!match.Match(""));
ASSERT(!emptyMatcher.Match(""));
}
void emptymaskpath1() const {
std::vector<std::string> masks;
PathMatch match(masks);
ASSERT(!match.Match("src/"));
ASSERT(!emptyMatcher.Match("src/"));
}
void emptymaskpath2() const {
std::vector<std::string> masks;
PathMatch match(masks);
ASSERT(!match.Match("../src/"));
ASSERT(!emptyMatcher.Match("../src/"));
}
void emptymaskpath3() const {
std::vector<std::string> masks;
PathMatch match(masks);
ASSERT(!match.Match("/home/user/code/src/"));
ASSERT(!emptyMatcher.Match("/home/user/code/src/"));
}
// Test PathMatch containing "src/"
void onemaskemptypath() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match(""));
ASSERT(!srcMatcher.Match(""));
}
void onemasksamepath() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("src/"));
ASSERT(srcMatcher.Match("src/"));
}
void onemasksamepathdifferentcase() const {
std::vector<std::string> masks;
masks.push_back("sRc/");
std::vector<std::string> masks(1, "sRc/");
PathMatch match(masks, false);
ASSERT(match.Match("srC/"));
}
void onemasksamepathwithfile() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("src/file.txt"));
ASSERT(srcMatcher.Match("src/file.txt"));
}
void onemaskdifferentdir1() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match("srcfiles/file.txt"));
ASSERT(!srcMatcher.Match("srcfiles/file.txt"));
}
void onemaskdifferentdir2() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match("proj/srcfiles/file.txt"));
ASSERT(!srcMatcher.Match("proj/srcfiles/file.txt"));
}
void onemaskdifferentdir3() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match("proj/mysrc/file.txt"));
ASSERT(!srcMatcher.Match("proj/mysrc/file.txt"));
}
void onemaskdifferentdir4() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match("proj/mysrcfiles/file.txt"));
ASSERT(!srcMatcher.Match("proj/mysrcfiles/file.txt"));
}
void onemasklongerpath1() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("/tmp/src/"));
ASSERT(srcMatcher.Match("/tmp/src/"));
}
void onemasklongerpath2() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("src/module/"));
ASSERT(srcMatcher.Match("src/module/"));
}
void onemasklongerpath3() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("project/src/module/"));
ASSERT(srcMatcher.Match("project/src/module/"));
}
void twomasklongerpath1() const {
@ -191,60 +163,40 @@ private:
ASSERT(match.Match("project/src/module/"));
}
// Test PathMatch containing "foo.cpp"
void filemask1() const {
std::vector<std::string> masks;
masks.push_back("foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("foo.cpp"));
ASSERT(fooCppMatcher.Match("foo.cpp"));
}
void filemaskdifferentcase() const {
std::vector<std::string> masks;
masks.push_back("foo.cPp");
std::vector<std::string> masks(1, "foo.cPp");
PathMatch match(masks, false);
ASSERT(match.Match("fOo.cpp"));
}
void filemask2() const {
std::vector<std::string> masks;
masks.push_back("foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("../foo.cpp"));
ASSERT(fooCppMatcher.Match("../foo.cpp"));
}
void filemask3() const {
std::vector<std::string> masks;
masks.push_back("foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("src/foo.cpp"));
ASSERT(fooCppMatcher.Match("src/foo.cpp"));
}
// Test PathMatch containing "src/foo.cpp"
void filemaskpath1() const {
std::vector<std::string> masks;
masks.push_back("src/foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("src/foo.cpp"));
ASSERT(srcFooCppMatcher.Match("src/foo.cpp"));
}
void filemaskpath2() const {
std::vector<std::string> masks;
masks.push_back("src/foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("proj/src/foo.cpp"));
ASSERT(srcFooCppMatcher.Match("proj/src/foo.cpp"));
}
void filemaskpath3() const {
std::vector<std::string> masks;
masks.push_back("src/foo.cpp");
PathMatch match(masks);
ASSERT(!match.Match("foo.cpp"));
ASSERT(!srcFooCppMatcher.Match("foo.cpp"));
}
void filemaskpath4() const {
std::vector<std::string> masks;
masks.push_back("src/foo.cpp");
PathMatch match(masks);
ASSERT(!match.Match("bar/foo.cpp"));
ASSERT(!srcFooCppMatcher.Match("bar/foo.cpp"));
}
};

View File

@ -144,8 +144,7 @@ private:
settings._inlineSuppressions = true;
settings.addEnabled("information");
if (!suppression.empty()) {
std::string r = settings.nomsg.addSuppressionLine(suppression);
ASSERT_EQUALS("", r);
ASSERT_EQUALS("", settings.nomsg.addSuppressionLine(suppression));
}
ThreadExecutor executor(files, settings, *this);
for (std::map<std::string, std::size_t>::const_iterator i = files.begin(); i != files.end(); ++i)

View File

@ -83,55 +83,55 @@ private:
for (int i = 0; i < 500; i++)
oss << " {char *a = malloc(10);}\n";
oss << " return 0;\n";
oss << "}\n";
oss << " return 0;\n"
<< "}\n";
check(2, 3, 3, oss.str());
}
void no_errors_more_files() {
std::ostringstream oss;
oss << "int main()\n"
<< "{\n";
oss << " return 0;\n";
oss << "}\n";
<< "{\n"
<< " return 0;\n"
<< "}\n";
check(2, 3, 0, oss.str());
}
void no_errors_less_files() {
std::ostringstream oss;
oss << "int main()\n"
<< "{\n";
oss << " return 0;\n";
oss << "}\n";
<< "{\n"
<< " return 0;\n"
<< "}\n";
check(2, 1, 0, oss.str());
}
void no_errors_equal_amount_files() {
std::ostringstream oss;
oss << "int main()\n"
<< "{\n";
oss << " return 0;\n";
oss << "}\n";
<< "{\n"
<< " return 0;\n"
<< "}\n";
check(2, 2, 0, oss.str());
}
void one_error_less_files() {
std::ostringstream oss;
oss << "int main()\n"
<< "{\n";
oss << " {char *a = malloc(10);}\n";
oss << " return 0;\n";
oss << "}\n";
<< "{\n"
<< " {char *a = malloc(10);}\n"
<< " return 0;\n"
<< "}\n";
check(2, 1, 1, oss.str());
}
void one_error_several_files() {
std::ostringstream oss;
oss << "int main()\n"
<< "{\n";
oss << " {char *a = malloc(10);}\n";
oss << " return 0;\n";
oss << "}\n";
<< "{\n"
<< " {char *a = malloc(10);}\n"
<< " return 0;\n"
<< "}\n";
check(2, 20, 20, oss.str());
}
};