]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Only warn about unused rules if we had a chance to match them
authorPetr Machata <pmachata@redhat.com>
Wed, 15 Sep 2010 21:31:18 +0000 (23:31 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 15 Sep 2010 21:31:18 +0000 (23:31 +0200)
dwarflint/main.cc
dwarflint/tests/run-nodebug.sh

index d82c8c8d8055bbe0105c3b4780ca6fca0dfb33e2..53a61a44496dee1c8624230b1f39e106f5f86305 100644 (file)
@@ -198,6 +198,7 @@ main (int argc, char *argv[])
 
   /* Now process all the files given at the command line.  */
   bool only_one = remaining + 1 == argc;
+  bool one_passed = false;
   do
     {
       try
@@ -208,6 +209,7 @@ main (int argc, char *argv[])
          if (!only_one)
            std::cout << std::endl << fname << ":" << std::endl;
          dwarflint lint (fname, check_option.rules);
+         one_passed = true;
 
          if (prev_error_count == error_count && !be_quiet)
            puts (gettext ("No errors"));
@@ -220,11 +222,12 @@ main (int argc, char *argv[])
     }
   while (++remaining < argc);
 
-  for (checkrules::const_iterator it = check_option.rules.begin ();
-       it != check_option.rules.end (); ++it)
-    if (!it->used ())
-      std::cerr << "warning: the rule `" << it->name ()
-               << "' never matched." << std::endl;
+  if (one_passed)
+    for (checkrules::const_iterator it = check_option.rules.begin ();
+        it != check_option.rules.end (); ++it)
+      if (!it->used ())
+       std::cerr << "warning: the rule `" << it->name ()
+                 << "' never matched." << std::endl;
 
   return error_count != 0;
 }
index 346d9d8cbfde183e3ce24d5ccb3b39aff09ac2f1..5bfc2c552cc46510339bd18a4a2f3125d3a536f6 100755 (executable)
@@ -46,3 +46,26 @@ EOF
 testrun_compare ./dwarflint --check=oentuh -q nodebug <<EOF
 warning: the rule \`oentuh' never matched.
 EOF
+
+# ... and since we are testing this here, also check that we don't get
+# this message in situations where it makes no sense.
+LANG=C testrun_compare ./dwarflint --check=oentuh -q noeuht <<EOF
+error: Cannot open input file: No such file or directory.
+EOF
+
+LANG=C testrun_compare ./dwarflint --check=oentuh -q noeuht nodebug <<EOF
+
+noeuht:
+error: Cannot open input file: No such file or directory.
+
+nodebug:
+warning: the rule \`oentuh' never matched.
+EOF
+
+LANG=C testrun_compare ./dwarflint --check=oentuh -q nodebug nodebug <<EOF
+
+nodebug:
+
+nodebug:
+warning: the rule \`oentuh' never matched.
+EOF