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
This commit is contained in:
Noel Grandin
2017-06-19 09:00:59 +02:00
parent d3e0ab976a
commit 45c06838e9
10 changed files with 33 additions and 22 deletions

View File

@@ -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

View File

@@ -47,6 +47,7 @@ class PluginHandler
string scope;
string warningsOnly;
bool warningsAsErrors;
bool unitTestMode;
};
/**

View File

@@ -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;
};

View File

@@ -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: */

View File

@@ -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 {

View File

@@ -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) {}

View File

@@ -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;

View File

@@ -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>();

View File

@@ -287,7 +287,7 @@ else
$(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%)
$(call gb_Output_announce,$*.cxx,$(true),$(if $(COMPILER_TEST),CPT,CXX),3)
$(eval $(gb_CxxObject__set_pchflags))
$(call gb_CObject__command_pattern,$@,$(T_CXXFLAGS) $(T_CXXFLAGS_APPEND),$<,$(call gb_CxxObject_get_dep_target,$*),$(COMPILER_PLUGINS))
$(call gb_CObject__command_pattern,$@,$(T_CXXFLAGS) $(T_CXXFLAGS_APPEND) $(if $(COMPILER_TEST),$(gb_COMPILER_TEST_FLAGS)),$<,$(call gb_CxxObject_get_dep_target,$*),$(COMPILER_PLUGINS))
endif
ifeq ($(gb_FULLDEPS),$(true))

View File

@@ -191,6 +191,7 @@ gb_LinkTarget_INCLUDE :=\
-I$(BUILDDIR)/config_$(gb_Side) \
ifeq ($(COM_IS_CLANG),TRUE)
gb_COMPILER_TEST_FLAGS := -Xclang -plugin-arg-loplugin -Xclang --unit-test-mode
ifeq ($(COMPILER_PLUGIN_TOOL),)
gb_COMPILER_PLUGINS := -Xclang -load -Xclang $(BUILDDIR)/compilerplugins/obj/plugin.so -Xclang -add-plugin -Xclang loplugin
ifneq ($(COMPILER_PLUGIN_WARNINGS_ONLY),)
@@ -209,6 +210,7 @@ gb_COMPILER_PLUGINS_SETUP := ICECC_EXTRAFILES=$(SRCDIR)/include/sal/log-areas.do
gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS := \
-Xclang -plugin-arg-loplugin -Xclang --warnings-as-errors
else
gb_COMPILER_TEST_FLAGS :=
gb_COMPILER_SETUP :=
gb_COMPILER_PLUGINS :=
gb_COMPILER_PLUGINS_SETUP :=