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

View File

@ -144,8 +144,7 @@ private:
settings._inlineSuppressions = true; settings._inlineSuppressions = true;
settings.addEnabled("information"); settings.addEnabled("information");
if (!suppression.empty()) { if (!suppression.empty()) {
std::string r = settings.nomsg.addSuppressionLine(suppression); ASSERT_EQUALS("", settings.nomsg.addSuppressionLine(suppression));
ASSERT_EQUALS("", r);
} }
ThreadExecutor executor(files, settings, *this); ThreadExecutor executor(files, settings, *this);
for (std::map<std::string, std::size_t>::const_iterator i = files.begin(); i != files.end(); ++i) 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++) for (int i = 0; i < 500; i++)
oss << " {char *a = malloc(10);}\n"; oss << " {char *a = malloc(10);}\n";
oss << " return 0;\n"; oss << " return 0;\n"
oss << "}\n"; << "}\n";
check(2, 3, 3, oss.str()); check(2, 3, 3, oss.str());
} }
void no_errors_more_files() { void no_errors_more_files() {
std::ostringstream oss; std::ostringstream oss;
oss << "int main()\n" oss << "int main()\n"
<< "{\n"; << "{\n"
oss << " return 0;\n"; << " return 0;\n"
oss << "}\n"; << "}\n";
check(2, 3, 0, oss.str()); check(2, 3, 0, oss.str());
} }
void no_errors_less_files() { void no_errors_less_files() {
std::ostringstream oss; std::ostringstream oss;
oss << "int main()\n" oss << "int main()\n"
<< "{\n"; << "{\n"
oss << " return 0;\n"; << " return 0;\n"
oss << "}\n"; << "}\n";
check(2, 1, 0, oss.str()); check(2, 1, 0, oss.str());
} }
void no_errors_equal_amount_files() { void no_errors_equal_amount_files() {
std::ostringstream oss; std::ostringstream oss;
oss << "int main()\n" oss << "int main()\n"
<< "{\n"; << "{\n"
oss << " return 0;\n"; << " return 0;\n"
oss << "}\n"; << "}\n";
check(2, 2, 0, oss.str()); check(2, 2, 0, oss.str());
} }
void one_error_less_files() { void one_error_less_files() {
std::ostringstream oss; std::ostringstream oss;
oss << "int main()\n" oss << "int main()\n"
<< "{\n"; << "{\n"
oss << " {char *a = malloc(10);}\n"; << " {char *a = malloc(10);}\n"
oss << " return 0;\n"; << " return 0;\n"
oss << "}\n"; << "}\n";
check(2, 1, 1, oss.str()); check(2, 1, 1, oss.str());
} }
void one_error_several_files() { void one_error_several_files() {
std::ostringstream oss; std::ostringstream oss;
oss << "int main()\n" oss << "int main()\n"
<< "{\n"; << "{\n"
oss << " {char *a = malloc(10);}\n"; << " {char *a = malloc(10);}\n"
oss << " return 0;\n"; << " return 0;\n"
oss << "}\n"; << "}\n";
check(2, 20, 20, oss.str()); check(2, 20, 20, oss.str());
} }
}; };