bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/4] diagnostics: check the styling


From: Akim Demaille
Subject: [PATCH 1/4] diagnostics: check the styling
Date: Sun, 21 Apr 2019 09:41:46 +0200

Enable checking of styles even when libtextstyle is not installed.

* src/getargs.h, src/getargs.c (style_debug): New.
(getargs_colors): Set it when --style=debug.
* src/complain.c (begin_use_class, end_use_class): Use it.
* tests/diagnostics.at: New.
---
 src/complain.c       | 18 ++++++++---
 src/getargs.c        |  9 +++++-
 src/getargs.h        |  2 +-
 tests/diagnostics.at | 71 ++++++++++++++++++++++++++++++++++++++++++++
 tests/local.mk       |  1 +
 tests/testsuite.at   |  3 ++
 6 files changed, 98 insertions(+), 6 deletions(-)
 create mode 100644 tests/diagnostics.at

diff --git a/src/complain.c b/src/complain.c
index 97af2f95..a42b6a06 100644
--- a/src/complain.c
+++ b/src/complain.c
@@ -72,8 +72,13 @@ begin_use_class (const char *s, FILE *out)
 {
   if (out == stderr)
     {
-      styled_ostream_begin_use_class (errstream, s);
-      styled_ostream_flush_to_current_style (errstream);
+      if (style_debug)
+        fprintf (out, "<%s>", s);
+      else
+        {
+          styled_ostream_begin_use_class (errstream, s);
+          styled_ostream_flush_to_current_style (errstream);
+        }
     }
 }
 
@@ -82,8 +87,13 @@ end_use_class (const char *s, FILE *out)
 {
   if (out == stderr)
     {
-      styled_ostream_end_use_class (errstream, s);
-      styled_ostream_flush_to_current_style (errstream);
+      if (style_debug)
+        fprintf (out, "</%s>", s);
+      else
+        {
+          styled_ostream_end_use_class (errstream, s);
+          styled_ostream_flush_to_current_style (errstream);
+        }
     }
 }
 
diff --git a/src/getargs.c b/src/getargs.c
index 8673d41c..9a0f0d54 100644
--- a/src/getargs.c
+++ b/src/getargs.c
@@ -45,6 +45,7 @@ bool no_lines_flag = false;
 bool token_table_flag = false;
 location yacc_loc = EMPTY_LOCATION_INIT;
 bool update_flag = false; /* for -u */
+bool style_debug = false; /* --style=debug. */
 
 bool nondeterministic_parser = false;
 bool glr_parser = false;
@@ -595,7 +596,13 @@ getargs_colors (int argc, char *argv[])
       if (STRPREFIX_LIT ("--color=", arg))
         handle_color_option (arg + strlen ("--color="));
       else if (STRPREFIX_LIT ("--style=", arg))
-        handle_style_option (arg + strlen ("--style="));
+        {
+          const char *style = arg + strlen ("--style=");
+          if (STREQ (style, "debug"))
+            style_debug = true;
+          else
+            handle_style_option (style);
+        }
     }
   complain_init_color ();
 }
diff --git a/src/getargs.h b/src/getargs.h
index 2037c00a..58f082f8 100644
--- a/src/getargs.h
+++ b/src/getargs.h
@@ -41,7 +41,7 @@ extern bool no_lines_flag;              /* for -l */
 extern bool token_table_flag;           /* for -k */
 extern location yacc_loc;               /* for -y */
 extern bool update_flag;                /* for -u */
-
+extern bool style_debug;                /* --style=debug. */
 /* GLR_PARSER is true if the input file says to use the GLR
    (Generalized LR) parser, and to output some additional information
    used by the GLR algorithm.  */
diff --git a/tests/diagnostics.at b/tests/diagnostics.at
new file mode 100644
index 00000000..41bbe8a7
--- /dev/null
+++ b/tests/diagnostics.at
@@ -0,0 +1,71 @@
+# Checking diagnotics.                               -*- Autotest -*-
+
+# Copyright (C) 2019 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_BANNER([[Diagnostics.]])
+
+# AT_TEST([TITLE], [GRAMMAR], [OUTPUT-WITH-STYLE])
+m4_pushdef([AT_TEST],
+[
+AT_SETUP([$1])
+AT_KEYWORDS([diagnostics])
+
+AT_BISON_OPTION_PUSHDEFS
+
+AT_DATA_GRAMMAR([[input.y]], [$2])
+
+AT_DATA([experr], [$3])
+AT_BISON_CHECK([-fcaret --style=debug -Wother input.y], [], [], [experr])
+
+# When no style, same messages, except the style.
+AT_CHECK([perl -pi -e 's{</?\w+>}{}g' experr])
+AT_BISON_CHECK([-fcaret -Wother input.y], [], [], [experr])
+
+AT_BISON_OPTION_POPDEFS
+
+AT_CLEANUP
+])
+
+
+## ---------- ##
+## Warnings.  ##
+## ---------- ##
+
+AT_TEST([[Warnings]],
+[[%token FOO FOO FOO
+%token FOO  FOO  FOO
+%%
+exp:;
+]],
+[[input.y:9.12-14: <warning>warning:</warning> symbol FOO redeclared 
[<warning>-Wother</warning>]
+ %token FOO <warning>FOO</warning> FOO
+            <warning>^~~</warning>
+input.y:9.16-18: <warning>warning:</warning> symbol FOO redeclared 
[<warning>-Wother</warning>]
+ %token FOO FOO <warning>FOO</warning>
+                <warning>^~~</warning>
+input.y:10.8-10: <warning>warning:</warning> symbol FOO redeclared 
[<warning>-Wother</warning>]
+ %token <warning>FOO</warning>  FOO  FOO
+        <warning>^~~</warning>
+input.y:10.13-15: <warning>warning:</warning> symbol FOO redeclared 
[<warning>-Wother</warning>]
+ %token FOO  <warning>FOO</warning>  FOO
+             <warning>^~~</warning>
+input.y:10.18-20: <warning>warning:</warning> symbol FOO redeclared 
[<warning>-Wother</warning>]
+ %token FOO  FOO  <warning>FOO</warning>
+                  <warning>^~~</warning>
+]])
+
+
+m4_popdef([AT_TEST])
\ No newline at end of file
diff --git a/tests/local.mk b/tests/local.mk
index 03a29e5e..c8ee3f02 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -48,6 +48,7 @@ TESTSUITE_AT =                                \
   %D%/calc.at                                 \
   %D%/conflicts.at                            \
   %D%/cxx-type.at                             \
+  %D%/diagnostics.at                          \
   %D%/existing.at                             \
   %D%/glr-regression.at                       \
   %D%/headers.at                              \
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 71df4881..54f494fa 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -26,6 +26,9 @@ m4_include([named-refs.at])
 # Output file names.
 m4_include([output.at])
 
+# Diagnostics.
+m4_include([diagnostics.at])
+
 # Skeleton support.
 m4_include([skeletons.at])
 
-- 
2.21.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]