summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-11-14 23:35:19 +0100
committerStephan Bergmann <sbergman@redhat.com>2016-11-15 11:09:29 +0100
commit645583dfd374c8b02f3c0eeba6233a0bb5884d68 (patch)
tree522ce0e474fb6263a69b3402f786245c73a1357e /compilerplugins
parent10efab2b9a3cf7fc49655c90ba29db4512680c38 (diff)
New compilerplugins/clang unit tests
...to check that loplugin produces warnings/errors as expected: * Clang has a -verify switch that makes it easy to write test input .cxx files that list in comments all the warnings/errors that are expected, and let Clang check those expectations instead of generating object code. See include/clang/Frontend/VerifyDiagnosticConsumer.h in the Clang source tree for documentation. * Introduce a CompilerTest gbuild class that uses the existing LinkTarget class as much as possible. Checking the input files is implicitly phony, as the compilation step doesn't generate any object files, and the link step does nothing because there is no gb_LinkTarget_set_targettype for CompilerTest. The setup at least works for Clang on Linux (will need adaptions for Clang on Windows; compilers other than Clang are not relevant for now given this is used to check compilerplugins). * Definition of gb_CFLAGS_WERROR in solenv/gbuild/platform/com_GCC_defs.mk needs to be lazy ('=' vs. ':=') so that CompilerTest can override it: The Clang -verify mode wants the input files to specify whether the loplugin diagnostics are warnings or errros, so they consistently need to be errors independent of --enable-werror configuration. * A first (example) test is in compilerplugins/clang/test/salbool.cxx. The corresponding gbuild CompilerTest instance is in solenv/CompilerTest_compilerplugins_clang.mk for now. The reason for that odd split across compilerplugins/ and solenv/ is that there is no compilerplugins/Modules_compilerplugins.mk file, so this setup is the easiest hack for now (to be cleaned up). (Another area that could be improved is that all test files need to be listed explicitly in the CompilerTest_*.mk file, instead of, say, using all .c/.cxx/.m/.mm files in a specified directory.) * The test is run somewhat late during a top-level 'make', after loplugin has already been used in compilation. But it can be run manually (e.g., 'make solenv') when making changes to loplugin during development. Change-Id: I01e12fb84887d264ac03ef2484807458c2075af4
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/test/salbool.cxx18
1 files changed, 18 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/salbool.cxx b/compilerplugins/clang/test/salbool.cxx
new file mode 100644
index 000000000000..da861afe73be
--- /dev/null
+++ b/compilerplugins/clang/test/salbool.cxx
@@ -0,0 +1,18 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <sal/types.h>
+
+struct S {
+ sal_Bool b; // expected-error {{FieldDecl, use "bool" instead of "sal_Bool" [loplugin:salbool]}}
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */