From 36dba8373b4746bd5622c9ad0ab04c7841537915 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 7 Aug 2013 17:55:31 +0200 Subject: [PATCH] Reuse constant objects in testpathmatch.cpp, small simplification in testsuppressions.cpp and testthreadexecutor.cpp --- test/testpathmatch.cpp | 122 +++++++++++------------------------- test/testsuppressions.cpp | 3 +- test/testthreadexecutor.cpp | 38 +++++------ 3 files changed, 57 insertions(+), 106 deletions(-) diff --git a/test/testpathmatch.cpp b/test/testpathmatch.cpp index 894bbf87e..d060d9128 100644 --- a/test/testpathmatch.cpp +++ b/test/testpathmatch.cpp @@ -23,10 +23,19 @@ class TestPathMatch : public TestFixture { public: - TestPathMatch() : TestFixture("TestPathMatch") { + TestPathMatch() + : TestFixture("TestPathMatch") + , emptyMatcher(std::vector()) + , srcMatcher(std::vector(1, "src/")) + , fooCppMatcher(std::vector(1, "foo.cpp")) + , srcFooCppMatcher(std::vector(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 masks; - PathMatch match(masks); - ASSERT(!match.Match("")); + ASSERT(!emptyMatcher.Match("")); } void emptymaskpath1() const { - std::vector masks; - PathMatch match(masks); - ASSERT(!match.Match("src/")); + ASSERT(!emptyMatcher.Match("src/")); } void emptymaskpath2() const { - std::vector masks; - PathMatch match(masks); - ASSERT(!match.Match("../src/")); + ASSERT(!emptyMatcher.Match("../src/")); } void emptymaskpath3() const { - std::vector 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 masks; - masks.push_back("src/"); - PathMatch match(masks); - ASSERT(!match.Match("")); + ASSERT(!srcMatcher.Match("")); } void onemasksamepath() const { - std::vector masks; - masks.push_back("src/"); - PathMatch match(masks); - ASSERT(match.Match("src/")); + ASSERT(srcMatcher.Match("src/")); } void onemasksamepathdifferentcase() const { - std::vector masks; - masks.push_back("sRc/"); + std::vector masks(1, "sRc/"); PathMatch match(masks, false); ASSERT(match.Match("srC/")); } void onemasksamepathwithfile() const { - std::vector 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 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 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 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 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 masks; - masks.push_back("src/"); - PathMatch match(masks); - ASSERT(match.Match("/tmp/src/")); + ASSERT(srcMatcher.Match("/tmp/src/")); } void onemasklongerpath2() const { - std::vector masks; - masks.push_back("src/"); - PathMatch match(masks); - ASSERT(match.Match("src/module/")); + ASSERT(srcMatcher.Match("src/module/")); } void onemasklongerpath3() const { - std::vector 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 masks; - masks.push_back("foo.cpp"); - PathMatch match(masks); - ASSERT(match.Match("foo.cpp")); + ASSERT(fooCppMatcher.Match("foo.cpp")); } void filemaskdifferentcase() const { - std::vector masks; - masks.push_back("foo.cPp"); + std::vector masks(1, "foo.cPp"); PathMatch match(masks, false); ASSERT(match.Match("fOo.cpp")); } void filemask2() const { - std::vector masks; - masks.push_back("foo.cpp"); - PathMatch match(masks); - ASSERT(match.Match("../foo.cpp")); + ASSERT(fooCppMatcher.Match("../foo.cpp")); } void filemask3() const { - std::vector 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 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 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 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 masks; - masks.push_back("src/foo.cpp"); - PathMatch match(masks); - ASSERT(!match.Match("bar/foo.cpp")); + ASSERT(!srcFooCppMatcher.Match("bar/foo.cpp")); } }; diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index f5d44be8d..d7f8e337b 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -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::const_iterator i = files.begin(); i != files.end(); ++i) diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index b84b96dae..b7ce9bb51 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -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()); } };