Skip to content

Commit fe3c7bf

Browse files
committed
add cli test for boost header with anonymous namespace
1 parent 7017f4b commit fe3c7bf

File tree

3 files changed

+152
-2
lines changed

3 files changed

+152
-2
lines changed

samples/boost-sample/exclude.def

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
11
--recursive --exclude=headers/* src
22
1
3-
3
3+
4
4+
Done processing src/inspect/unnamed_namespace_check.hpp
45
Done processing src/tr1/c_policy.hpp
5-
Total errors found: 66
6+
Total errors found: 106
67

8+
src/inspect/unnamed_namespace_check.hpp:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_BOOST_SAMPLE_SRC_INSPECT_UNNAMED_NAMESPACE_CHECK_HPP_ [build/header_guard] [5]
9+
src/inspect/unnamed_namespace_check.hpp:14: Do not use unnamed namespaces in header files. See https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces for more information. [build/namespaces] [4]
10+
src/inspect/unnamed_namespace_check.hpp:18: At least two spaces is best between code and comments [whitespace/comments] [2]
11+
src/inspect/unnamed_namespace_check.hpp:19: Closing ) should be moved to the previous line [whitespace/parens] [2]
12+
src/inspect/unnamed_namespace_check.hpp:21: Anonymous namespace should be terminated with "// namespace" [readability/namespace] [5]
13+
src/inspect/unnamed_namespace_check.hpp:21: At least two spaces is best between code and comments [whitespace/comments] [2]
14+
src/inspect/unnamed_namespace_check.hpp:26: { should almost always be at the end of the previous line [whitespace/braces] [4]
15+
src/inspect/unnamed_namespace_check.hpp:27: Do not indent within a namespace [runtime/indentation_namespace] [4]
16+
src/inspect/unnamed_namespace_check.hpp:28: { should almost always be at the end of the previous line [whitespace/braces] [4]
17+
src/inspect/unnamed_namespace_check.hpp:29: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
18+
src/inspect/unnamed_namespace_check.hpp:30: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
19+
src/inspect/unnamed_namespace_check.hpp:30: { should almost always be at the end of the previous line [whitespace/braces] [4]
20+
src/inspect/unnamed_namespace_check.hpp:31: Extra space after ( in function call [whitespace/parens] [4]
21+
src/inspect/unnamed_namespace_check.hpp:31: Extra space before ) [whitespace/parens] [2]
22+
src/inspect/unnamed_namespace_check.hpp:32: At least two spaces is best between code and comments [whitespace/comments] [2]
23+
src/inspect/unnamed_namespace_check.hpp:32: Extra space after ( in function call [whitespace/parens] [4]
24+
src/inspect/unnamed_namespace_check.hpp:32: Extra space before ) [whitespace/parens] [2]
25+
src/inspect/unnamed_namespace_check.hpp:33: Extra space after ( in function call [whitespace/parens] [4]
26+
src/inspect/unnamed_namespace_check.hpp:33: Extra space before ) [whitespace/parens] [2]
27+
src/inspect/unnamed_namespace_check.hpp:34: At least two spaces is best between code and comments [whitespace/comments] [2]
28+
src/inspect/unnamed_namespace_check.hpp:34: Extra space after ( in function call [whitespace/parens] [4]
29+
src/inspect/unnamed_namespace_check.hpp:34: Extra space before ) [whitespace/parens] [2]
30+
src/inspect/unnamed_namespace_check.hpp:35: Extra space after ( in function call [whitespace/parens] [4]
31+
src/inspect/unnamed_namespace_check.hpp:35: Extra space before ) [whitespace/parens] [2]
32+
src/inspect/unnamed_namespace_check.hpp:36: Extra space after ( in function call [whitespace/parens] [4]
33+
src/inspect/unnamed_namespace_check.hpp:36: Extra space before ) [whitespace/parens] [2]
34+
src/inspect/unnamed_namespace_check.hpp:37: Extra space after ( in function call [whitespace/parens] [4]
35+
src/inspect/unnamed_namespace_check.hpp:37: Extra space before ) [whitespace/parens] [2]
36+
src/inspect/unnamed_namespace_check.hpp:38: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
37+
src/inspect/unnamed_namespace_check.hpp:40: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
38+
src/inspect/unnamed_namespace_check.hpp:44: { should almost always be at the end of the previous line [whitespace/braces] [4]
39+
src/inspect/unnamed_namespace_check.hpp:48: Lines should be <= 80 characters long [whitespace/line_length] [2]
40+
src/inspect/unnamed_namespace_check.hpp:49: Missing space before ( in for( [whitespace/parens] [5]
41+
src/inspect/unnamed_namespace_check.hpp:50: { should almost always be at the end of the previous line [whitespace/braces] [4]
42+
src/inspect/unnamed_namespace_check.hpp:54: Extra space after ( in function call [whitespace/parens] [4]
43+
src/inspect/unnamed_namespace_check.hpp:54: Extra space before ) [whitespace/parens] [2]
44+
src/inspect/unnamed_namespace_check.hpp:57: Redundant blank line at the end of a code block should be deleted. [whitespace/blank_line] [3]
45+
src/inspect/unnamed_namespace_check.hpp:59: At least two spaces is best between code and comments [whitespace/comments] [2]
46+
src/inspect/unnamed_namespace_check.hpp:60: At least two spaces is best between code and comments [whitespace/comments] [2]
47+
src/inspect/unnamed_namespace_check.hpp:51: Add #include <string> for string [build/include_what_you_use] [4]
748
src/tr1/c_policy.hpp:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_BOOST_SAMPLE_SRC_TR1_C_POLICY_HPP_ [build/header_guard] [5]
849
src/tr1/c_policy.hpp:9: Missing space before { [whitespace/braces] [5]
950
src/tr1/c_policy.hpp:13: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
src/inspect/*
2+
1
3+
3
4+
Done processing src/inspect/unnamed_namespace_check.hpp
5+
Total errors found: 40
6+
7+
src/inspect/unnamed_namespace_check.hpp:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_BOOST_SAMPLE_SRC_INSPECT_UNNAMED_NAMESPACE_CHECK_HPP_ [build/header_guard] [5]
8+
src/inspect/unnamed_namespace_check.hpp:14: Do not use unnamed namespaces in header files. See https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces for more information. [build/namespaces] [4]
9+
src/inspect/unnamed_namespace_check.hpp:18: At least two spaces is best between code and comments [whitespace/comments] [2]
10+
src/inspect/unnamed_namespace_check.hpp:19: Closing ) should be moved to the previous line [whitespace/parens] [2]
11+
src/inspect/unnamed_namespace_check.hpp:21: Anonymous namespace should be terminated with "// namespace" [readability/namespace] [5]
12+
src/inspect/unnamed_namespace_check.hpp:21: At least two spaces is best between code and comments [whitespace/comments] [2]
13+
src/inspect/unnamed_namespace_check.hpp:26: { should almost always be at the end of the previous line [whitespace/braces] [4]
14+
src/inspect/unnamed_namespace_check.hpp:27: Do not indent within a namespace [runtime/indentation_namespace] [4]
15+
src/inspect/unnamed_namespace_check.hpp:28: { should almost always be at the end of the previous line [whitespace/braces] [4]
16+
src/inspect/unnamed_namespace_check.hpp:29: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
17+
src/inspect/unnamed_namespace_check.hpp:30: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
18+
src/inspect/unnamed_namespace_check.hpp:30: { should almost always be at the end of the previous line [whitespace/braces] [4]
19+
src/inspect/unnamed_namespace_check.hpp:31: Extra space after ( in function call [whitespace/parens] [4]
20+
src/inspect/unnamed_namespace_check.hpp:31: Extra space before ) [whitespace/parens] [2]
21+
src/inspect/unnamed_namespace_check.hpp:32: At least two spaces is best between code and comments [whitespace/comments] [2]
22+
src/inspect/unnamed_namespace_check.hpp:32: Extra space after ( in function call [whitespace/parens] [4]
23+
src/inspect/unnamed_namespace_check.hpp:32: Extra space before ) [whitespace/parens] [2]
24+
src/inspect/unnamed_namespace_check.hpp:33: Extra space after ( in function call [whitespace/parens] [4]
25+
src/inspect/unnamed_namespace_check.hpp:33: Extra space before ) [whitespace/parens] [2]
26+
src/inspect/unnamed_namespace_check.hpp:34: At least two spaces is best between code and comments [whitespace/comments] [2]
27+
src/inspect/unnamed_namespace_check.hpp:34: Extra space after ( in function call [whitespace/parens] [4]
28+
src/inspect/unnamed_namespace_check.hpp:34: Extra space before ) [whitespace/parens] [2]
29+
src/inspect/unnamed_namespace_check.hpp:35: Extra space after ( in function call [whitespace/parens] [4]
30+
src/inspect/unnamed_namespace_check.hpp:35: Extra space before ) [whitespace/parens] [2]
31+
src/inspect/unnamed_namespace_check.hpp:36: Extra space after ( in function call [whitespace/parens] [4]
32+
src/inspect/unnamed_namespace_check.hpp:36: Extra space before ) [whitespace/parens] [2]
33+
src/inspect/unnamed_namespace_check.hpp:37: Extra space after ( in function call [whitespace/parens] [4]
34+
src/inspect/unnamed_namespace_check.hpp:37: Extra space before ) [whitespace/parens] [2]
35+
src/inspect/unnamed_namespace_check.hpp:38: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
36+
src/inspect/unnamed_namespace_check.hpp:40: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
37+
src/inspect/unnamed_namespace_check.hpp:44: { should almost always be at the end of the previous line [whitespace/braces] [4]
38+
src/inspect/unnamed_namespace_check.hpp:48: Lines should be <= 80 characters long [whitespace/line_length] [2]
39+
src/inspect/unnamed_namespace_check.hpp:49: Missing space before ( in for( [whitespace/parens] [5]
40+
src/inspect/unnamed_namespace_check.hpp:50: { should almost always be at the end of the previous line [whitespace/braces] [4]
41+
src/inspect/unnamed_namespace_check.hpp:54: Extra space after ( in function call [whitespace/parens] [4]
42+
src/inspect/unnamed_namespace_check.hpp:54: Extra space before ) [whitespace/parens] [2]
43+
src/inspect/unnamed_namespace_check.hpp:57: Redundant blank line at the end of a code block should be deleted. [whitespace/blank_line] [3]
44+
src/inspect/unnamed_namespace_check.hpp:59: At least two spaces is best between code and comments [whitespace/comments] [2]
45+
src/inspect/unnamed_namespace_check.hpp:60: At least two spaces is best between code and comments [whitespace/comments] [2]
46+
src/inspect/unnamed_namespace_check.hpp:51: Add #include <string> for string [build/include_what_you_use] [4]
47+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// unnamed_namespace_check -----------------------------------------//
2+
3+
// Copyright Gennaro Prota 2006.
4+
//
5+
// Distributed under the Boost Software License, Version 1.0.
6+
// (See accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include "boost/regex.hpp"
10+
#include "boost/lexical_cast.hpp"
11+
#include "unnamed_namespace_check.hpp"
12+
13+
14+
namespace {
15+
16+
17+
boost::regex unnamed_namespace_regex(
18+
"\\<namespace\\s*(\\?\\?<|\\{)" // trigraph ??< or {
19+
);
20+
21+
} // unnamed namespace (ironical? :-)
22+
23+
24+
25+
namespace boost
26+
{
27+
namespace inspect
28+
{
29+
unnamed_namespace_check::unnamed_namespace_check() : m_errors(0)
30+
{
31+
register_signature( ".h" );
32+
register_signature( ".hh" ); // just in case
33+
register_signature( ".hpp" );
34+
register_signature( ".hxx" ); // just in case
35+
register_signature( ".inc" );
36+
register_signature( ".ipp" );
37+
register_signature( ".inl" );
38+
}
39+
40+
void unnamed_namespace_check::inspect(
41+
const string & library_name,
42+
const path & full_path, // example: c:/foo/boost/filesystem/path.hpp
43+
const string & contents ) // contents of file to be inspected
44+
{
45+
if (contents.find( "boostinspect:" "nounnamed" ) != string::npos) return;
46+
47+
48+
boost::sregex_iterator cur(contents.begin(), contents.end(), unnamed_namespace_regex), end;
49+
for( ; cur != end; ++cur, ++m_errors )
50+
{
51+
const string::size_type
52+
ln = std::count( contents.begin(), (*cur)[0].first, '\n' ) + 1;
53+
54+
error( library_name, full_path, "Unnamed namespace", ln );
55+
}
56+
57+
58+
}
59+
} // namespace inspect
60+
} // namespace boost
61+
62+

0 commit comments

Comments
 (0)