Files
codeql/cpp/ql/src/Metrics/Files/FNumberOfTests.ql
Brian Gianforcaro a6bcbe7974 C++: Detect GoogleTest tests cases in FNumberOfTests.ql
Co-authored-by: Jonas Jensen <jbj@github.com>
2020-08-13 12:06:00 -07:00

29 lines
859 B
Plaintext

/**
* @name Number of tests
* @description The number of test methods defined in a file.
* @kind treemap
* @treemap.warnOn lowValues
* @metricType file
* @metricAggregate avg sum max
* @precision medium
* @id cpp/tests-in-files
* @tags maintainability
*/
import cpp
Expr getTest() {
// cppunit tests; https://freedesktop.org/wiki/Software/cppunit/
result.(FunctionCall).getTarget().hasQualifiedName("CppUnit", _, "addTest")
or
// boost tests; http://www.boost.org/
result.(FunctionCall).getTarget().hasQualifiedName("boost::unit_test", "make_test_case")
or
// googletest tests; https://github.com/google/googletest/
result.(FunctionCall).getTarget().hasQualifiedName("testing::internal", "MakeAndRegisterTestInfo")
}
from File f, int n
where n = strictcount(Expr e | e = getTest() and e.getFile() = f)
select f, n order by n desc