From 155994a4bd79d3b9fb43ea028c9f0ed526d4530a Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 2 Oct 2015 11:06:36 +0100 Subject: [PATCH] Unit tests for variadic argument constructors Explicit variadic constructors can be marked explicit as they can have one or more arguments --- cpplint/cpplint_unittest.py | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index aaa3b24..42a7cb6 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -1338,6 +1338,47 @@ class CpplintTest(CpplintTestBase): Foo(std::initializer_list &arg) {} };""", '') + # Special case for variadic arguments + error_collector = ErrorCollector(self.assert_) + cpplint.ProcessFileData('foo.cc', 'cc', + ['class Foo {', + ' template', + ' 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', + ' 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', + ' 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', + ' 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',