[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [clazy/1.1] /: Introduce CLAZY_NO_WERROR env variable
From:       Sergio Martins <null () kde ! org>
Date:       2017-03-31 23:57:14
Message-ID: E1cu6Pq-0001e8-F4 () code ! kde ! org
[Download RAW message or body]

Git commit bebeb51b5eb53cc66b2d0085424c5df391989ae1 by Sergio Martins.
Committed on 31/03/2017 at 23:55.
Pushed by smartins into branch '1.1'.

Introduce CLAZY_NO_WERROR env variable

Set it to anything so that clazy doesn't treat warnings as errors
even if -Werror is present.

Useful if you want -Werror only for the regular gcc/clang warnings
and not for clazy warnings.

M  +2    -1    src/checkbase.cpp
M  +3    -0    src/checkmanager.cpp
M  +6    -0    src/checkmanager.h
M  +7    -0    tests/clazy/config.json
A  +13   -0    tests/clazy/werror2.cpp     [License: UNKNOWN]  *
A  +1    -0    tests/clazy/werror2.cpp.expected
M  +6    -3    tests/run_tests.py

The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.


https://commits.kde.org/clazy/bebeb51b5eb53cc66b2d0085424c5df391989ae1

diff --git a/src/checkbase.cpp b/src/checkbase.cpp
index 624fd05..689bde1 100644
--- a/src/checkbase.cpp
+++ b/src/checkbase.cpp
@@ -217,7 +217,8 @@ void CheckBase::reallyEmitWarning(clang::SourceLocation loc, \
const std::string &  {
     FullSourceLoc full(loc, sm());
     auto &engine = m_ci.getDiagnostics();
-    auto severity = engine.getWarningsAsErrors() ? DiagnosticIDs::Error : \
DiagnosticIDs::Warning; +    auto severity = (engine.getWarningsAsErrors() && \
!m_checkManager->userDisabledWError()) ? DiagnosticIDs::Error +                       \
                : DiagnosticIDs::Warning;
     unsigned id = engine.getDiagnosticIDs()->getCustomDiagID(severity, \
error.c_str());  DiagnosticBuilder B = engine.Report(full, id);
     for (const FixItHint& fixit : fixits) {
diff --git a/src/checkmanager.cpp b/src/checkmanager.cpp
index a61e149..7525e98 100644
--- a/src/checkmanager.cpp
+++ b/src/checkmanager.cpp
@@ -51,6 +51,9 @@ CheckManager::CheckManager()
             m_requestedFixitName = string(fixitsEnv);
         }
     }
+
+    // Allows user to make clazy ignore -Werror
+    m_noWerror = getenv("CLAZY_NO_WERROR") != nullptr;
 }
 
 bool CheckManager::checkExists(const string &name) const
diff --git a/src/checkmanager.h b/src/checkmanager.h
index 02854a0..79fa17a 100644
--- a/src/checkmanager.h
+++ b/src/checkmanager.h
@@ -118,6 +118,11 @@ public:
         return !ci.getPreprocessorOpts().ImplicitPCHInclude.empty();
     }
 
+    bool userDisabledWError() const
+    {
+        return m_noWerror;
+    }
+
 private:
     CheckManager();
 
@@ -131,6 +136,7 @@ private:
     std::unordered_map<std::string, RegisteredFixIt > m_fixitByName;
     std::string m_requestedFixitName;
     bool m_enableAllFixits;
+    bool m_noWerror = false;
     CheckLevel m_requestedLevel;
     const std::vector<std::string> m_extraOptions;
     SuppressionManager m_suppressionManager;
diff --git a/tests/clazy/config.json b/tests/clazy/config.json
index d4e1f4d..b108701 100644
--- a/tests/clazy/config.json
+++ b/tests/clazy/config.json
@@ -18,7 +18,14 @@
         {
             "filename" : "werror.cpp",
             "flags"    : "-Werror",
+            "must_fail": true,
             "checks"   : ["foreach"]
+        },
+        {
+            "filename" : "werror2.cpp",
+            "flags"    : "-Werror",
+            "checks"   : ["foreach"],
+            "env"      : { "CLAZY_NO_WERROR" : "1" }
         }
     ]
 }
diff --git a/tests/clazy/werror2.cpp b/tests/clazy/werror2.cpp
new file mode 100644
index 0000000..7e73ff0
--- /dev/null
+++ b/tests/clazy/werror2.cpp
@@ -0,0 +1,13 @@
+#include <QtCore/QString>
+#include <QtCore/QList>
+
+struct BigTrivial
+{
+    int a, b, c, d, e;
+};
+
+void test()
+{
+    QList<BigTrivial> list;
+    foreach (BigTrivial b, list) { }
+}
diff --git a/tests/clazy/werror2.cpp.expected b/tests/clazy/werror2.cpp.expected
new file mode 100644
index 0000000..ddd1921
--- /dev/null
+++ b/tests/clazy/werror2.cpp.expected
@@ -0,0 +1 @@
+clazy/werror2.cpp:12:14: warning: Missing reference in foreach with sizeof(T) = 20 \
                bytes (struct BigTrivial) [-Wclazy-foreach]
diff --git a/tests/run_tests.py b/tests/run_tests.py
index ceea7f5..96bacb8 100755
--- a/tests/run_tests.py
+++ b/tests/run_tests.py
@@ -30,6 +30,7 @@ class Test:
         self.env = os.environ
         self.checks = []
         self.flags = ""
+        self.must_fail = False
         self.blacklist_platforms = []
 
     def isScript(self):
@@ -137,6 +138,8 @@ def load_json(check_name):
                 test.checks = t['checks']
             if 'flags' in t:
                 test.flags = t['flags']
+            if 'must_fail' in t:
+                test.must_fail = t['must_fail']
             if 'expects_failure' in t:
                 test.expects_failure = t['expects_failure']
 
@@ -339,17 +342,17 @@ def run_unit_test(test):
     if _verbose:
         print "Running: " + clazy_cmd
 
-    using_werror = "-Werror" in test.flags
+    must_fail = test.must_fail
 
     cmd_success = run_command(clazy_cmd, output_file, test.env)
 
-    if (not cmd_success and not using_werror) or (cmd_success and using_werror):
+    if (not cmd_success and not must_fail) or (cmd_success and must_fail):
         print "[FAIL] " + checkname + " (Failed to build test. Check " + output_file \
+ " for details)"  print
         return False
 
     if not test.compare_everything and not test.isFixedFile:
-        word_to_grep = "warning:" if not using_werror else "error:"
+        word_to_grep = "warning:" if not must_fail else "error:"
         extract_word(word_to_grep, output_file, result_file)
 
     printableName = checkname


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic