Skip to content

Commit 87df375

Browse files
committed
Extend googletest for ACTION macros
They seem to fail when they are in a namespace with a statement before the macro. Motivating examples: ``` namespace{int x;ACTION_P(B, p){}} namespace{int x;ACTION(B){}} namespace{int x;ACTION_P3(B, p0, p1, p3){}} // Regression ACTION(Foo) { int *p = 0; return *p; } ```
1 parent 530e59f commit 87df375

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎cfg/googletest.cfg‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,15 @@
5959
<define name="MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)" value="bool name##MatcherP9&lt;p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, p7##_type, p8##_type&gt;::gmock_Impl&lt;arg_type&gt;::MatchAndExplain(GTEST_REFERENCE_TO_CONST_(arg_type) arg,::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_) const"/>
6060
<define name="MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)" value="bool name##MatcherP10&lt;p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type&gt;::gmock_Impl&lt;arg_type&gt;::MatchAndExplain(GTEST_REFERENCE_TO_CONST_(arg_type) arg,::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_) const"/>
6161
<define name="MOCK_METHOD(...)" value=""/>
62+
<define name="ACTION(name)" value="auto name(int arg0, int arg1)"/>
63+
<define name="ACTION_P(name,p0)" value="template&lt;class p0##_type&gt; auto name(p0##_type p0, int arg0)"/>
64+
<define name="ACTION_P2(name,p0,p1)" value="template&lt;class p0##_type, class p1##_type&gt; auto name(p0##_type p0, p1##_type p1, int arg0)"/>
65+
<define name="ACTION_P3(name,p0,p1,p2)" value="template&lt;class p0##_type, class p1##_type, class p2##_type&gt; auto name(p0##_type p0, p1##_type p1, p2##_type p2, int arg0)"/>
66+
<define name="ACTION_P4(name,p0,p1,p2,p3)" value="template&lt;class p0##_type, class p1##_type, class p2##_type, class p3##_type&gt; auto name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, int arg0)"/>
67+
<define name="ACTION_P5(name,p0,p1,p2,p3,p4)" value="template&lt;class p0##_type, class p1##_type, class p2##_type, class p3##_type, class p4##_type&gt; auto name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, int arg0)"/>
68+
<define name="ACTION_P6(name,p0,p1,p2,p3,p4,p5)" value="template&lt;class p0##_type, class p1##_type, class p2##_type, class p3##_type, class p4##_type, class p5##_type&gt; auto name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, int arg0)"/>
69+
<define name="ACTION_P7(name,p0,p1,p2,p3,p4,p5,p6)" value="template&lt;class p0##_type, class p1##_type, class p2##_type, class p3##_type, class p4##_type, class p5##_type, class p6##_type&gt; auto name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, p6##_type p6, int arg0)"/>
70+
<define name="ACTION_P8(name,p0,p1,p2,p3,p4,p5,p6,p7)" value="template&lt;class p0##_type, class p1##_type, class p2##_type, class p3##_type, class p4##_type, class p5##_type, class p6##_type, class p7##_type&gt; auto name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, int arg0)"/>
71+
<define name="ACTION_P9(name,p0,p1,p2,p3,p4,p5,p6,p7,p8)" value="template&lt;class p0##_type, class p1##_type, class p2##_type, class p3##_type, class p4##_type, class p5##_type, class p6##_type, class p7##_type, class p8##_type&gt; auto name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, int arg0)"/>
72+
<define name="ACTION_P10(name,p0,p1,p2,p3,p4,p5,p6,p7,p8,p9)" value="template&lt;class p0##_type, class p1##_type, class p2##_type, class p3##_type, class p4##_type, class p5##_type, class p6##_type, class p7##_type, class p8##_type, class p9##_type&gt; auto name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, p9##_type p9, int arg0)"/>
6273
</def>

‎test/cfg/googletest.cpp‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,47 @@ namespace ExampleNamespace {
4242
}
4343
}
4444

45+
namespace ActionNamespace {
46+
int x;
47+
// cppcheck-suppress autoNoType
48+
ACTION(ExampleAction)
49+
{
50+
return x;
51+
}
52+
53+
int y;
54+
// cppcheck-suppress autoNoType
55+
ACTION_P(ExampleActionP, p)
56+
{
57+
return p + y;
58+
}
59+
60+
int z;
61+
// cppcheck-suppress autoNoType
62+
ACTION_P3(ExampleActionP3, p0, p1, p2)
63+
{
64+
return p0 + p1 + p2 + z;
65+
}
66+
}
67+
68+
namespace {
69+
int w;
70+
// cppcheck-suppress autoNoType
71+
ACTION_P2(ExampleActionP2, p0, p1)
72+
{
73+
return p0 + p1 + w;
74+
}
75+
}
76+
77+
// cppcheck-suppress autoNoType
78+
ACTION(ExampleActionNullPointer)
79+
{
80+
// cppcheck-suppress constVariablePointer
81+
int *p = 0;
82+
// cppcheck-suppress nullPointer
83+
return *p;
84+
}
85+
4586
TEST(ASSERT, ASSERT)
4687
{
4788
int *a = (int*)calloc(10,sizeof(int)); // cppcheck-suppress cstyleCast

0 commit comments

Comments
 (0)