Skip to content

Commit

Permalink
testrunner: make sure the error output is consumed (#6117)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored Mar 13, 2024
1 parent 1fe7485 commit 1bace58
Show file tree
Hide file tree
Showing 47 changed files with 9,538 additions and 9,832 deletions.
11 changes: 4 additions & 7 deletions test/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,11 @@ void TestFixture::teardownTest()
{
teardownTestInternal();

// TODO: enable
/*
{
const std::string s = errout.str();
{
const std::string s = errout_str();
if (!s.empty())
throw std::runtime_error("unconsumed ErrorLogger err: " + s);
}
*/
}
{
const std::string s = output_str();
if (!s.empty())
Expand Down Expand Up @@ -429,7 +426,7 @@ void TestFixture::reportErr(const ErrorMessage &msg)
if (msg.severity == Severity::information && msg.id == "normalCheckLevelMaxBranches")
return;
const std::string errormessage(msg.toString(mVerbose, mTemplateFormat, mTemplateLocation));
errout << errormessage << std::endl;
mErrout << errormessage << std::endl;
}

void TestFixture::setTemplateFormat(const std::string &templateFormat)
Expand Down
7 changes: 6 additions & 1 deletion test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,17 @@ class TestFixture : public ErrorLogger {
return s;
}

std::ostringstream errout;
std::string errout_str() {
std::string s = mErrout.str();
mErrout.str("");
return s;
}

const Settings settingsDefault;

private:
std::ostringstream mOutput;
std::ostringstream mErrout;

void reportOut(const std::string &outmsg, Color c = Color::Reset) override;
void reportErr(const ErrorMessage &msg) override;
Expand Down
75 changes: 36 additions & 39 deletions test/test64bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ class Test64BitPortability : public TestFixture {

#define check(code) check_(code, __FILE__, __LINE__)
void check_(const char code[], const char* file, int line) {
// Clear the error buffer..
errout.str("");

// Tokenize..
Tokenizer tokenizer(settings, this);
std::istringstream istr(code);
Expand All @@ -63,13 +60,13 @@ class Test64BitPortability : public TestFixture {
"void f() {\n"
" CharArray foo = \"\";\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("struct T { std::vector<int>*a[2][2]; };\n" // #11560
"void f(T& t, int i, int j) {\n"
" t.a[i][j] = new std::vector<int>;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());
}

void novardecl() {
Expand All @@ -78,7 +75,7 @@ class Test64BitPortability : public TestFixture {
"{\n"
" a = p;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());
}

void functionpar() {
Expand All @@ -87,65 +84,65 @@ class Test64BitPortability : public TestFixture {
" int a = p;\n"
" return a + 4;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout_str());

check("int foo(int p[])\n"
"{\n"
" int a = p;\n"
" return a + 4;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout_str());

check("int foo(int p[])\n"
"{\n"
" int *a = p;\n"
" return a;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout_str());

check("void foo(int x)\n"
"{\n"
" int *p = x;\n"
" *p = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout_str());

check("int f(const char *p) {\n" // #4659
" return 6 + p[2] * 256;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("int foo(int *p) {\n" // #6096
" bool a = p;\n"
" return a;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("std::array<int,2> f();\n"
"void g() {\n"
" std::array<int, 2> a = f();\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("std::array<int,2> f(int x);\n"
"void g(int i) {\n"
" std::array<int, 2> a = f(i);\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("typedef std::array<int, 2> Array;\n"
"Array f(int x);\n"
"void g(int i) {\n"
" Array a = f(i);\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("typedef std::array<int, 2> Array;\n"
"Array f();\n"
"void g(int i) {\n"
" Array a = f();\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("struct S {\n" // #9951
" enum E { E0 };\n"
Expand All @@ -154,20 +151,20 @@ class Test64BitPortability : public TestFixture {
"void f() {\n"
" std::array<double, 1> a = S::g(S::E::E0);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("char* f(char* p) {\n"
" return p ? p : 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());
}

void structmember() {
check("struct Foo { int *p; };\n"
"void f(struct Foo *foo) {\n"
" int i = foo->p;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout_str());

check("struct S {\n" // #10145
" enum class E { e1, e2 };\n"
Expand All @@ -177,15 +174,15 @@ class Test64BitPortability : public TestFixture {
"void f(S& s) {\n"
" s.e = S::E::e1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());
}

void ptrcompare() {
// Ticket #2892
check("void foo(int *p) {\n"
" int a = (p != NULL);\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());
}

void ptrarithmetic() {
Expand All @@ -194,104 +191,104 @@ class Test64BitPortability : public TestFixture {
" int x = 10;\n"
" int *a = p + x;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("void foo(int *p) {\n"
" int x = 10;\n"
" int *a = x + p;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("void foo(int *p) {\n"
" int x = 10;\n"
" int *a = x * x;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout_str());

check("void foo(int *start, int *end) {\n"
" int len;\n"
" int len = end + 10 - start;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());
}

void returnIssues() {
check("void* foo(int i) {\n"
" return i;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an integer in a function with pointer return type is not portable.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an integer in a function with pointer return type is not portable.\n", errout_str());

check("void* foo(int* i) {\n"
" return i;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("void* foo() {\n"
" return 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("int foo(int i) {\n"
" return i;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("struct Foo {};\n"
"\n"
"int* dostuff(Foo foo) {\n"
" return foo;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("int foo(char* c) {\n"
" return c;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout_str());

check("int foo(char* c) {\n"
" return 1+c;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout_str());

check("std::string foo(char* c) {\n"
" return c;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("int foo(char *a, char *b) {\n" // #4486
" return a + 1 - b;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("struct s {\n" // 4642
" int i;\n"
"};\n"
"int func(struct s *p) {\n"
" return 1 + p->i;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("static void __iomem *f(unsigned int port_no) {\n"
" void __iomem *mmio = hpriv->mmio;\n"
" return mmio + (port_no * 0x80);\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

// #7247: don't check return statements in nested functions..
check("int foo() {\n"
" struct {\n"
" const char * name() { return \"abc\"; }\n"
" } table;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

// #7451: Lambdas
check("const int* test(std::vector<int> outputs, const std::string& text) {\n"
" auto it = std::find_if(outputs.begin(), outputs.end(),\n"
" [&](int ele) { return \"test\" == text; });\n"
" return nullptr;\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());

check("struct S {\n" // #12159
" std::future<int> f() const {\n"
Expand All @@ -303,7 +300,7 @@ class Test64BitPortability : public TestFixture {
" auto x = s->f();\n"
" return x.get();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout_str());
}
};

Expand Down
Loading

0 comments on commit 1bace58

Please sign in to comment.