Skip to content

Commit

Permalink
Preview of clang-format changes and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Sep 8, 2020
1 parent bfd1701 commit 805e3b0
Show file tree
Hide file tree
Showing 98 changed files with 6,195 additions and 11,213 deletions.
139 changes: 139 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: AfterColon
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '<turtle/'
Priority: 10
SortPriority: 0
- Regex: '<boost/'
Priority: 20
SortPriority: 0
- Regex: '^<'
Priority: 30
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Impl|_Win32|_Other)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 10000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: c++14
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
...

17 changes: 17 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Static analysis

on:
push:
pull_request:

jobs:
Formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: git submodule update --init
- name: Formatting
uses: DoozyX/[email protected]
with:
source: 'include test doc'
clangFormatVersion: 10
4 changes: 2 additions & 2 deletions doc/example/calculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class view;
class calculator
{
public:
calculator( view& v );
calculator(view& v);

void add( int a, int b ); // the result will be sent to the view 'v'
void add(int a, int b); // the result will be sent to the view 'v'
};
//]

Expand Down
128 changes: 56 additions & 72 deletions doc/example/customization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,126 +14,110 @@
#include "mock_view.hpp"

//[ mock_stream_user_type
namespace user_namespace
{
struct user_type
{};
namespace user_namespace {
struct user_type
{};

inline mock::stream& operator<<( mock::stream& s, const user_type& )
{
return s << "user_type";
}
inline mock::stream& operator<<(mock::stream& s, const user_type&)
{
return s << "user_type";
}
} // namespace user_namespace
//]

namespace custom_constraint_free_function_test
{
namespace custom_constraint_free_function_test {
//[ custom_constraint_free_function
bool custom_constraint( int actual )
bool custom_constraint(int actual)
{
return actual == 42;
}
//]

//[ custom_constraint_free_function_test
BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two )
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two)
{
mock_view v;
calculator c( v );
MOCK_EXPECT( v.display ).with( &custom_constraint );
c.add( 41, 1 );
}
//]
calculator c(v);
MOCK_EXPECT(v.display).with(&custom_constraint);
c.add(41, 1);
}
//]
} // namespace custom_constraint_free_function_test

namespace custom_constraint_functor_test
{
namespace custom_constraint_functor_test {
//[ custom_constraint_functor
struct custom_constraint
{
friend bool operator==( int actual, const custom_constraint& )
{
return actual == 42;
}
friend bool operator==(int actual, const custom_constraint&) { return actual == 42; }

friend std::ostream& operator<<( std::ostream& s, const custom_constraint& )
{
return s << "_ == 42";
}
friend std::ostream& operator<<(std::ostream& s, const custom_constraint&) { return s << "_ == 42"; }
};
//]

//[ custom_constraint_functor_test
BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two )
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two)
{
mock_view v;
calculator c( v );
MOCK_EXPECT( v.display ).with( custom_constraint() );
c.add( 41, 1 );
calculator c(v);
MOCK_EXPECT(v.display).with(custom_constraint());
c.add(41, 1);
}
//]
}
} // namespace custom_constraint_functor_test

//[ near_constraint
template< typename Expected >
template<typename Expected>
struct near_constraint
{
near_constraint( Expected expected, Expected threshold )
: expected_( expected )
, threshold_( threshold )
{}
near_constraint(Expected expected, Expected threshold) : expected_(expected), threshold_(threshold) {}

template< typename Actual >
bool operator()( Actual actual ) const
template<typename Actual>
bool operator()(Actual actual) const
{
return std::abs( actual - boost::unwrap_ref( expected_ ) )
< boost::unwrap_ref( threshold_ );
return std::abs(actual - boost::unwrap_ref(expected_)) < boost::unwrap_ref(threshold_);
}

friend std::ostream& operator<<( std::ostream& s, const near_constraint& c )
friend std::ostream& operator<<(std::ostream& s, const near_constraint& c)
{
return s << "near( " << mock::format( c.expected_ )
<< ", " << mock::format( c.threshold_ ) << " )";
return s << "near( " << mock::format(c.expected_) << ", " << mock::format(c.threshold_) << " )";
}

Expected expected_, threshold_;
};

template< typename Expected >
mock::constraint< near_constraint< Expected > > near( Expected expected, Expected threshold )
template<typename Expected>
mock::constraint<near_constraint<Expected>> near(Expected expected, Expected threshold)
{
return near_constraint< Expected >( expected, threshold );
return near_constraint<Expected>(expected, threshold);
}
//]

namespace near_constraint_test
{
namespace near_constraint_test {
//[ near_constraint_test
BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one )
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two_plus_or_minus_one)
{
mock_view v;
calculator c( v );
MOCK_EXPECT( v.display ).with( near( 42, 1 ) );
c.add( 41, 1 );
mock_view v;
calculator c(v);
MOCK_EXPECT(v.display).with(near(42, 1));
c.add(41, 1);
}
//]
}
} // namespace near_constraint_test

namespace near_constraint_cref_test
{
namespace near_constraint_cref_test {
//[ near_constraint_cref_test
BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one )
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two_plus_or_minus_one)
{
mock_view v;
calculator c( v );
int expected, threshold;
MOCK_EXPECT( v.display ).with( near( boost::cref( expected ), boost::cref( threshold ) ) );
expected = 42;
threshold = 1;
c.add( 41, 1 );
mock_view v;
calculator c(v);
int expected, threshold;
MOCK_EXPECT(v.display).with(near(boost::cref(expected), boost::cref(threshold)));
expected = 42;
threshold = 1;
c.add(41, 1);
}
//]
}
} // namespace near_constraint_cref_test

#undef MOCK_MAX_ARGS
//[ max_args
Expand All @@ -142,25 +126,25 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one )
//]

//[ custom_policy
template< typename Result >
template<typename Result>
struct custom_policy
{
static Result abort()
{
// Notify the test framework that an error occurs which makes it impossible to continue the test.
// This should most likely throw an exception of some kind.
}
template< typename Context >
static void fail( const char* message, const Context& context, const char* file = "unknown location", int line = 0 )
template<typename Context>
static void fail(const char* message, const Context& context, const char* file = "unknown location", int line = 0)
{
// Notify the test framework that an unexpected call has occurred.
}
template< typename Context >
static void call( const Context& context, const char* file, int line )
template<typename Context>
static void call(const Context& context, const char* file, int line)
{
// Notify the test framework that an expectation has been fulfilled.
}
static void pass( const char* file, int line )
static void pass(const char* file, int line)
{
// Notify the test framework that the test execution merely passed the given code location.
}
Expand Down
Loading

0 comments on commit 805e3b0

Please sign in to comment.