Unit tests for variadic argument constructors

Explicit variadic constructors can be marked explicit as they can have
one or more arguments
This commit is contained in:
Matt Clarkson 2015-10-02 11:06:36 +01:00
parent 3591b2e540
commit 155994a4bd

View File

@ -1338,6 +1338,47 @@ class CpplintTest(CpplintTestBase):
Foo(std::initializer_list<T> &arg) {}
};""",
'')
# Special case for variadic arguments
error_collector = ErrorCollector(self.assert_)
cpplint.ProcessFileData('foo.cc', 'cc',
['class Foo {',
' template<typename... Args>',
' explicit Foo(const int arg, Args&&... args) {}',
'};'],
error_collector)
self.assertEquals(0, error_collector.ResultList().count(
'Constructors that require multiple arguments should not be marked '
'explicit. [runtime/explicit] [0]'))
error_collector = ErrorCollector(self.assert_)
cpplint.ProcessFileData('foo.cc', 'cc',
['class Foo {',
' template<typename... Args>',
' explicit Foo(Args&&... args) {}',
'};'],
error_collector)
self.assertEquals(0, error_collector.ResultList().count(
'Constructors that require multiple arguments should not be marked '
'explicit. [runtime/explicit] [0]'))
error_collector = ErrorCollector(self.assert_)
cpplint.ProcessFileData('foo.cc', 'cc',
['class Foo {',
' template<typename... Args>',
' Foo(const int arg, Args&&... args) {}',
'};'],
error_collector)
self.assertEquals(1, error_collector.ResultList().count(
'Constructors callable with one argument should be marked explicit.'
' [runtime/explicit] [5]'))
error_collector = ErrorCollector(self.assert_)
cpplint.ProcessFileData('foo.cc', 'cc',
['class Foo {',
' template<typename... Args>',
' Foo(Args&&... args) {}',
'};'],
error_collector)
self.assertEquals(1, error_collector.ResultList().count(
'Constructors callable with one argument should be marked explicit.'
' [runtime/explicit] [5]'))
# Anything goes inside an assembly block
error_collector = ErrorCollector(self.assert_)
cpplint.ProcessFileData('foo.cc', 'cc',