summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-06-19 09:00:59 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-06-19 11:34:15 +0200
commit45c06838e95c94445359536d84c6328fa8b17a66 (patch)
treeda05ccf67ce15d5afc78c2ddb80d117c0a576c84 /compilerplugins
parentd3e0ab976a5bbf63d1673422035def67ba9f4838 (diff)
only unit-test one loplugin at a time
tell the plugin code when we are unit-testing it, so we can suppress all the warnings except for the plugin we are currently testing Change-Id: I240c8e37eba90c219e53c29531a3a43bc841a1c8
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/pluginhandler.cxx20
-rw-r--r--compilerplugins/clang/pluginhandler.hxx1
-rw-r--r--compilerplugins/clang/test/finalprotected.cxx12
-rw-r--r--compilerplugins/clang/test/passstuffbyref.cxx4
-rw-r--r--compilerplugins/clang/test/redundantinline.hxx2
-rw-r--r--compilerplugins/clang/test/stringconstant.cxx2
-rw-r--r--compilerplugins/clang/test/useuniqueptr.cxx2
-rw-r--r--compilerplugins/clang/test/vclwidgets.cxx8
8 files changed, 30 insertions, 21 deletions
diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx
index cc9ea891ceac..ad043e87e58d 100644
--- a/compilerplugins/clang/pluginhandler.cxx
+++ b/compilerplugins/clang/pluginhandler.cxx
@@ -62,16 +62,15 @@ PluginHandler::PluginHandler( CompilerInstance& compiler, const vector< string >
, rewriter( compiler.getSourceManager(), compiler.getLangOpts())
, scope( "mainfile" )
, warningsAsErrors( false )
+ , unitTestMode( false )
{
set< string > rewriters;
- for( vector< string >::const_iterator it = args.begin();
- it != args.end();
- ++it )
+ for( string const & arg : args )
{
- if( it->size() >= 2 && (*it)[ 0 ] == '-' && (*it)[ 1 ] == '-' )
- handleOption( it->substr( 2 ));
+ if( arg.size() >= 2 && arg[ 0 ] == '-' && arg[ 1 ] == '-' )
+ handleOption( arg.substr( 2 ));
else
- rewriters.insert( *it );
+ rewriters.insert( arg );
}
createPlugins( rewriters );
bPluginObjectsCreated = true;
@@ -110,6 +109,8 @@ void PluginHandler::handleOption( const string& option )
}
else if( option == "warnings-as-errors" )
warningsAsErrors = true;
+ else if( option == "unit-test-mode" )
+ unitTestMode = true;
else
report( DiagnosticsEngine::Fatal, "unknown option %0" ) << option;
}
@@ -190,7 +191,12 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
++i )
{
if( plugins[ i ].object != NULL )
- plugins[ i ].object->run();
+ {
+ // When in unit-test mode, ignore plugins whose names don't match the filename of the test,
+ // so that we only generate warnings for the plugin that we want to test.
+ if (!unitTestMode || mainFileName.find(plugins[ i ].optionName) != StringRef::npos)
+ plugins[ i ].object->run();
+ }
}
#if defined _WIN32
//TODO: make the call to 'rename' work on Windows (where the renamed-to
diff --git a/compilerplugins/clang/pluginhandler.hxx b/compilerplugins/clang/pluginhandler.hxx
index 3d5f6c82e3d9..a2cc136f5751 100644
--- a/compilerplugins/clang/pluginhandler.hxx
+++ b/compilerplugins/clang/pluginhandler.hxx
@@ -47,6 +47,7 @@ class PluginHandler
string scope;
string warningsOnly;
bool warningsAsErrors;
+ bool unitTestMode;
};
/**
diff --git a/compilerplugins/clang/test/finalprotected.cxx b/compilerplugins/clang/test/finalprotected.cxx
index 99fb19584a8d..c15564874447 100644
--- a/compilerplugins/clang/test/finalprotected.cxx
+++ b/compilerplugins/clang/test/finalprotected.cxx
@@ -10,25 +10,25 @@
class S final {
protected:
- void f(int f) { f1 = f; } // expected-error {{final class should not have protected members - convert them to private [loplugin:finalprotected]}} expected-error {{[loplugin:unreffun]}}
+ void f(int f) { f1 = f; } // expected-error {{final class should not have protected members - convert them to private [loplugin:finalprotected]}}
int f1; // expected-error {{final class should not have protected members - convert them to private [loplugin:finalprotected]}}
public:
- void g(); // expected-error {{[loplugin:externandnotdefined]}} expected-error {{[loplugin:unreffun]}}
+ void g();
int g1;
private:
- void h(); // expected-error {{[loplugin:externandnotdefined]}} expected-error {{[loplugin:unreffun]}}
+ void h();
int h1;
};
class S2 {
protected:
- void f(int f) { f1 = f; } // expected-error {{[loplugin:unreffun]}}
+ void f(int f) { f1 = f; }
int f1;
public:
- void g(); // expected-error {{[loplugin:externandnotdefined]}} expected-error {{[loplugin:unreffun]}}
+ void g();
int g1;
private:
- void h(); // expected-error {{[loplugin:externandnotdefined]}} expected-error {{[loplugin:unreffun]}}
+ void h();
int h1;
};
diff --git a/compilerplugins/clang/test/passstuffbyref.cxx b/compilerplugins/clang/test/passstuffbyref.cxx
index 7c31af77df77..89f51fb1c294 100644
--- a/compilerplugins/clang/test/passstuffbyref.cxx
+++ b/compilerplugins/clang/test/passstuffbyref.cxx
@@ -19,11 +19,13 @@ struct S {
};
-void f() // expected-error {{Unreferenced externally visible function definition [loplugin:unreffun]}}
+void f()
{
S* s;
OUString v1, v2;
s = new S(v1, v2);
}
+// expected-no-diagnostics
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/test/redundantinline.hxx b/compilerplugins/clang/test/redundantinline.hxx
index a0c91ceb67be..e4efc5663e42 100644
--- a/compilerplugins/clang/test/redundantinline.hxx
+++ b/compilerplugins/clang/test/redundantinline.hxx
@@ -19,7 +19,7 @@ S1::S1() = default;
struct S2 {
inline S2() = default; // expected-error {{[loplugin:redundantinline]}}
- inline ~S2() = default; // expected-error {{[loplugin:redundantinline]}} expected-error {{[loplugin:unnecessaryoverride]}}
+ inline ~S2() = default; // expected-error {{[loplugin:redundantinline]}}
};
struct S3 {
diff --git a/compilerplugins/clang/test/stringconstant.cxx b/compilerplugins/clang/test/stringconstant.cxx
index 392567fa3cab..1b1eca2794bb 100644
--- a/compilerplugins/clang/test/stringconstant.cxx
+++ b/compilerplugins/clang/test/stringconstant.cxx
@@ -14,7 +14,7 @@
#include "com/sun/star/uno/Reference.hxx"
#include "rtl/strbuf.hxx"
-extern void foo(OUString const &); // expected-error {{extern prototype in main file without definition}}
+extern void foo(OUString const &);
struct Foo {
Foo(OUString const &, int) {}
diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx
index c705bbf0f158..564e93ccbdc0 100644
--- a/compilerplugins/clang/test/useuniqueptr.cxx
+++ b/compilerplugins/clang/test/useuniqueptr.cxx
@@ -10,7 +10,7 @@
class Foo {
char* m_pbar; // expected-note {{member is here [loplugin:useuniqueptr]}}
- ~Foo() // expected-error {{Unreferenced externally visible function definition [loplugin:unreffun]}}
+ ~Foo()
{
delete m_pbar; // expected-error {{a destructor with only a single unconditional call to delete on a member, is a sure sign it should be using std::unique_ptr for that field [loplugin:useuniqueptr]}}
m_pbar = nullptr;
diff --git a/compilerplugins/clang/test/vclwidgets.cxx b/compilerplugins/clang/test/vclwidgets.cxx
index d7926c0c4e98..9ead1c905289 100644
--- a/compilerplugins/clang/test/vclwidgets.cxx
+++ b/compilerplugins/clang/test/vclwidgets.cxx
@@ -16,7 +16,7 @@ struct Widget : public VclReferenceBase
{
VclPtr<Widget> mpParent;
- void widget1() // expected-error {{Unreferenced externally visible function definition [loplugin:unreffun]}}
+ void widget1()
{
// test that we ignore assignments from a member field
Widget* p = mpParent;
@@ -48,7 +48,7 @@ Widget* g()
}
// test the variable init detection
-void bar() // expected-error {{Unreferenced externally visible function definition [loplugin:unreffun]}}
+void bar()
{
Widget* p = f(); // expected-error {{assigning a returned-by-value VclPtr<T> to a T* variable is dodgy, should be assigned to a VclPtr. If you know that the RHS does not return a newly created T, then add a '.get()' to the RHS [loplugin:vclwidgets]}}
(void)p;
@@ -59,7 +59,7 @@ void bar() // expected-error {{Unreferenced externally visible function definiti
}
// test the assignment detection
-void bar2() // expected-error {{Unreferenced externally visible function definition [loplugin:unreffun]}}
+void bar2()
{
Widget* p;
p = nullptr;
@@ -76,7 +76,7 @@ void bar2() // expected-error {{Unreferenced externally visible function definit
template<class T>
T * get() { return nullptr; }
-void bar3() // expected-error {{Unreferenced externally visible function definition [loplugin:unreffun]}}
+void bar3()
{
Widget* p;
p = get<Widget>();