diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-08 00:48:45 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-08 00:48:45 +0000 |
commit | 5aa4f8a5bf24c636bad09d8f653bc53b4a58e1ec (patch) | |
tree | c49ed9f197db4c6987204186328fca8dc60655b2 /tools/clang/plugins | |
parent | 707961e53ed77b225647b9681a6dbc6c581c3725 (diff) | |
download | chromium_src-5aa4f8a5bf24c636bad09d8f653bc53b4a58e1ec.zip chromium_src-5aa4f8a5bf24c636bad09d8f653bc53b4a58e1ec.tar.gz chromium_src-5aa4f8a5bf24c636bad09d8f653bc53b4a58e1ec.tar.bz2 |
Add shell script based unit test system for the clang plugin.
The scripts compile a c++ test case and compares the compiler output against a golden file.
BUG=carnitas
TEST=(For developers only; QA ignore): ./test.sh <path to Release+Asserts>
Review URL: http://codereview.chromium.org/6623065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77217 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/clang/plugins')
-rw-r--r-- | tools/clang/plugins/tests/inline_ctor.cpp | 25 | ||||
-rw-r--r-- | tools/clang/plugins/tests/inline_ctor.h | 21 | ||||
-rw-r--r-- | tools/clang/plugins/tests/inline_ctor.txt | 8 | ||||
-rw-r--r-- | tools/clang/plugins/tests/missing_ctor.cpp | 23 | ||||
-rw-r--r-- | tools/clang/plugins/tests/missing_ctor.h | 19 | ||||
-rw-r--r-- | tools/clang/plugins/tests/missing_ctor.txt | 6 | ||||
-rwxr-xr-x | tools/clang/plugins/tests/test.sh | 50 | ||||
-rw-r--r-- | tools/clang/plugins/tests/virtual_methods.cpp | 36 | ||||
-rw-r--r-- | tools/clang/plugins/tests/virtual_methods.h | 26 | ||||
-rw-r--r-- | tools/clang/plugins/tests/virtual_methods.txt | 8 |
10 files changed, 222 insertions, 0 deletions
diff --git a/tools/clang/plugins/tests/inline_ctor.cpp b/tools/clang/plugins/tests/inline_ctor.cpp new file mode 100644 index 0000000..6a751fb --- /dev/null +++ b/tools/clang/plugins/tests/inline_ctor.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "inline_ctor.h" + +#include <string> +#include <vector> + +// We don't warn on classes that are in CPP files. +class InlineInCPPOK { + public: + InlineInCPPOK() {} + ~InlineInCPPOK() {} + + private: + std::vector<int> one_; + std::vector<std::string> two_; +}; + +int main() { + InlineInCPPOK one; + InlineCtorsArentOKInHeader two; + return 0; +} diff --git a/tools/clang/plugins/tests/inline_ctor.h b/tools/clang/plugins/tests/inline_ctor.h new file mode 100644 index 0000000..ce2685e --- /dev/null +++ b/tools/clang/plugins/tests/inline_ctor.h @@ -0,0 +1,21 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef INCLINE_CTOR_H_ +#define INCLINE_CTOR_H_ + +#include <string> +#include <vector> + +class InlineCtorsArentOKInHeader { + public: + InlineCtorsArentOKInHeader() {} + ~InlineCtorsArentOKInHeader() {} + + private: + std::vector<int> one_; + std::vector<std::string> two_; +}; + +#endif // INCLINE_CTOR_H_ diff --git a/tools/clang/plugins/tests/inline_ctor.txt b/tools/clang/plugins/tests/inline_ctor.txt new file mode 100644 index 0000000..caa0cb4 --- /dev/null +++ b/tools/clang/plugins/tests/inline_ctor.txt @@ -0,0 +1,8 @@ +In file included from inline_ctor.cpp:5: +./inline_ctor.h:13:3: warning: [chromium-style] Complex constructor has an inlined body. + InlineCtorsArentOKInHeader() {} + ^ +./inline_ctor.h:14:3: warning: [chromium-style] Complex destructor has an inline body. + ~InlineCtorsArentOKInHeader() {} + ^ +2 warnings generated. diff --git a/tools/clang/plugins/tests/missing_ctor.cpp b/tools/clang/plugins/tests/missing_ctor.cpp new file mode 100644 index 0000000..8ee2fb2 --- /dev/null +++ b/tools/clang/plugins/tests/missing_ctor.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "missing_ctor.h" + +#include <string> +#include <vector> + +// We don't warn on classes that use default ctors in cpp files. +class MissingInCPPOK { + public: + + private: + std::vector<int> one_; + std::vector<std::string> two_; +}; + +int main() { + MissingInCPPOK one; + MissingCtorsArentOKInHeader two; + return 0; +} diff --git a/tools/clang/plugins/tests/missing_ctor.h b/tools/clang/plugins/tests/missing_ctor.h new file mode 100644 index 0000000..1050457 --- /dev/null +++ b/tools/clang/plugins/tests/missing_ctor.h @@ -0,0 +1,19 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MISSING_CTOR_H_ +#define MISSING_CTOR_H_ + +#include <string> +#include <vector> + +class MissingCtorsArentOKInHeader { + public: + + private: + std::vector<int> one_; + std::vector<std::string> two_; +}; + +#endif // MISSING_CTOR_H_ diff --git a/tools/clang/plugins/tests/missing_ctor.txt b/tools/clang/plugins/tests/missing_ctor.txt new file mode 100644 index 0000000..d22f03f --- /dev/null +++ b/tools/clang/plugins/tests/missing_ctor.txt @@ -0,0 +1,6 @@ +In file included from missing_ctor.cpp:5: +./missing_ctor.h:11:1: warning: [chromium-style] Complex class/struct needs a declared constructor. +class MissingCtorsArentOKInHeader { +^ +./missing_ctor.h:11:1: warning: [chromium-style] Complex class/struct needs a declared destructor. +2 warnings generated. diff --git a/tools/clang/plugins/tests/test.sh b/tools/clang/plugins/tests/test.sh new file mode 100755 index 0000000..03c583d --- /dev/null +++ b/tools/clang/plugins/tests/test.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Hacky, primitive testing: This runs the style plugin for a set of input files +# and compares the output with golden result files. + +E_BADARGS=65 + +# Prints usage information. +function usage() { + echo "Usage: `basename $0` <Path to the llvm build dir, usually Release+Asserts>" + echo "" + echo " Runs all the libFindBadConstructs unit tests" + echo "" +} + +# Runs a single test case. +function do_testcase { + local output=`${CLANG_DIR}/bin/clang -cc1 \ + -load ${CLANG_DIR}/lib/libFindBadConstructs.so \ + -plugin find-bad-constructs ${1} 2>&1` + local diffout=`echo "${output}" | diff - ${2}` + if [[ ${diffout} == "" ]]; then + echo "PASS: ${1}" + else + echo "FAIL: ${1}" + echo "Output of compiler:" + echo "${output}" + fi +} + +# Validate input to the script. +if [[ -z "${1}" ]]; then + usage + exit ${E_BADARGS} +elif [[ ! -d "${1}" ]]; then + echo "${1} is not a directory." + usage + exit ${E_BADARGS} +else + echo "Using clang directory ${1}..." + export CLANG_DIR="${1}" +fi + +for input in *.cpp; do + do_testcase $input ${input%cpp}txt +done diff --git a/tools/clang/plugins/tests/virtual_methods.cpp b/tools/clang/plugins/tests/virtual_methods.cpp new file mode 100644 index 0000000..05515b7 --- /dev/null +++ b/tools/clang/plugins/tests/virtual_methods.cpp @@ -0,0 +1,36 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "virtual_methods.h" + +// Shouldn't warn about method usage in the implementation file. +class VirtualMethodsInImplementation { + public: + virtual void MethodIsAbstract() = 0; + virtual void MethodHasNoArguments(); + virtual void MethodHasEmptyDefaultImpl() {} + virtual bool ComplainAboutThis() { return true; } +}; + +// Stubs to fill in the abstract method +class ConcreteVirtualMethodsInHeaders : public VirtualMethodsInHeaders { + public: + virtual void MethodIsAbstract() {} +}; + +class ConcreteVirtualMethodsInImplementation + : public VirtualMethodsInImplementation { + public: + virtual void MethodIsAbstract() {} +}; + +// Fill in the implementations +void VirtualMethodsInHeaders::MethodHasNoArguments() {} +void WarnOnMissingVirtual::MethodHasNoArguments() {} +void VirtualMethodsInImplementation::MethodHasNoArguments() {} + +int main() { + ConcreteVirtualMethodsInHeaders one; + ConcreteVirtualMethodsInImplementation two; +} diff --git a/tools/clang/plugins/tests/virtual_methods.h b/tools/clang/plugins/tests/virtual_methods.h new file mode 100644 index 0000000..cb1846e --- /dev/null +++ b/tools/clang/plugins/tests/virtual_methods.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef VIRTUAL_METHODS_H_ +#define VIRTUAL_METHODS_H_ + +// Should warn about virtual method usage. +class VirtualMethodsInHeaders { + public: + // Don't complain about these. + virtual void MethodIsAbstract() = 0; + virtual void MethodHasNoArguments(); + virtual void MethodHasEmptyDefaultImpl() {} + + // But complain about this: + virtual bool ComplainAboutThis() { return true; } +}; + +// Complain on missing 'virtual' keyword in overrides. +class WarnOnMissingVirtual : public VirtualMethodsInHeaders { + public: + void MethodHasNoArguments(); +}; + +#endif // VIRTUAL_METHODS_H_ diff --git a/tools/clang/plugins/tests/virtual_methods.txt b/tools/clang/plugins/tests/virtual_methods.txt new file mode 100644 index 0000000..baa791f --- /dev/null +++ b/tools/clang/plugins/tests/virtual_methods.txt @@ -0,0 +1,8 @@ +In file included from virtual_methods.cpp:5: +./virtual_methods.h:17:36: warning: [chromium-style] virtual methods with non-empty bodies shouldn't be declared inline. + virtual bool ComplainAboutThis() { return true; } + ^ +./virtual_methods.h:23:3: warning: [chromium-style] Overridden method must have "virtual" keyword. + void MethodHasNoArguments(); + ^ +2 warnings generated. |