Skip to content

Commit a48c7cc

Browse files
committed
Simplify GoogleTestFunction
1 parent 7bf12c4 commit a48c7cc

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

cpp/common/src/codingstandards/cpp/EncapsulatingFunctions.qll

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,21 @@ class MainFunction extends MainLikeFunction {
2626
* such functions, however, they have certain features that can be used for
2727
* identification. This can be refined based on experiments/real-world use.
2828
*/
29-
class GTestFunction extends MainLikeFunction {
30-
GTestFunction() {
29+
class GoogleTestFunction extends MainLikeFunction {
30+
GoogleTestFunction() {
3131
// A GoogleTest function is named "TestBody" and
3232
this.hasName("TestBody") and
33-
// is enclosed by a class that inherits from a base class
34-
this.getEnclosingAccessHolder() instanceof Class and
33+
// it's parent class inherits a base class
3534
exists(Class base |
36-
base = this.getEnclosingAccessHolder().(Class).getABaseClass() and
35+
base = this.getEnclosingAccessHolder().(Class).getABaseClass+() and
36+
// with a name "Test" inside a namespace called "testing"
3737
(
38-
// called "Test" or
39-
exists(Class c | base.getABaseClass() = c and c.hasName("Test"))
40-
or
41-
// defined under a namespace called "testing" or
42-
exists(Namespace n | n = base.getNamespace() | n.hasName("testing"))
43-
or
44-
// is templatized by a parameter called "gtest_TypeParam_"
45-
exists(TemplateParameter tp |
46-
tp = base.getATemplateArgument() and
47-
tp.hasName("gtest_TypeParam_")
48-
)
38+
base.hasName("Test") and
39+
base.getNamespace().hasName("testing")
4940
)
41+
or
42+
// or at a location in a file called "gtest.h".
43+
base.getDefinitionLocation().getFile().getBaseName() = "gtest.h"
5044
)
5145
}
5246
}

0 commit comments

Comments
 (0)