[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Honor multi-line m4_pattern_forbid comment
From: |
Hans Ulrich Niedermann |
Subject: |
[PATCH] Honor multi-line m4_pattern_forbid comment |
Date: |
Mon, 16 Jun 2008 22:46:15 +0200 |
User-agent: |
Thunderbird 2.0.0.14 (X11/20080501) |
Let m4 create $tmp/patterns with comments spread over
multiple lines as before, but have autom4te reassemble
multi-line comments.
Additionally, add tests to check functionality.
An alternative solution would be to let autom4te have
m4 convert multi-line comments to an escaped one-line
form and let autom4te later unescape them.
---
bin/autom4te.in | 52 +++++++++++++++++++++++++++++++++++++++++-
tests/tools.at | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 117 insertions(+), 2 deletions(-)
diff --git a/bin/autom4te.in b/bin/autom4te.in
index 685df41..eb7136a 100644
--- a/bin/autom4te.in
+++ b/bin/autom4te.in
@@ -524,6 +524,55 @@ EOF
}
+# forbid_message_filter (@PATTERNS)
+# ---------------------------------
+# Like
+# map { /^forbid:([^:]+):.+$/ => /^forbid:[^:]+:(.+)$/ } @PATTERNS;
+# but joining multi-line messages.
+sub forbid_message_filter (@)
+{
+ my @patterns = @_;
+ my %forbidden;
+ my $pattern;
+ my $lastpat;
+ my $accu;
+ foreach $pattern (@patterns) {
+ verb "parsing pattern: $pattern";
+ if ($pattern =~ /^forbid:([^:]+):(.+)$/) {
+ my ($pat, $msg) = ($1, $2);
+ verb "parsing forbid pattern: $pat, $msg";
+ if (defined $lastpat) { # flush output buffer
+ verb "flushing: $lastpat => $accu";
+ $forbidden{$lastpat} = $accu;
+ undef $lastpat;
+ }
+ $lastpat = $pat;
+ $accu = $msg;
+ } elsif ($pattern =~ /^allow:([^:]+)/) {
+ my $pat = $1;
+ verb "parsing allow pattern: $pat";
+ if (defined $lastpat) { # flush output buffer
+ verb "flushing: $lastpat => $accu";
+ $forbidden{$lastpat} = $accu;
+ undef $lastpat;
+ }
+ } else {
+ verb "parsing \"other\" pattern: $pattern";
+ if (defined $lastpat) {
+ $accu = $accu . "\n" . $pattern;
+ verb "appending, now accu: $accu";
+ }
+ }
+ }
+ if (defined $lastpat) { # flush output buffer
+ verb "flushing: $lastpat => $accu";
+ $forbidden{$lastpat} = $accu;
+ undef $lastpat;
+ }
+ return %forbidden;
+}
+
+
# handle_output ($REQ, $OUTPUT)
# -----------------------------
# Run m4 on the input files, perform quadrigraphs substitution, check for
@@ -540,8 +589,7 @@ sub handle_output ($$)
'm4_pattern_allow' => 'allow:$1'));
my @patterns = new Autom4te::XFile ("< " . open_quote
("$tmp/patterns"))->getlines;
chomp @patterns;
- my %forbidden =
- map { /^forbid:([^:]+):.+$/ => /^forbid:[^:]+:(.+)$/ } @patterns;
+ my %forbidden = forbid_message_filter(@patterns);
my $forbidden = join ('|', map { /^forbid:([^:]+)/ } @patterns) || "^\$";
my $allowed = join ('|', map { /^allow:([^:]+)/ } @patterns) || "^\$";
diff --git a/tests/tools.at b/tests/tools.at
index 9e13689..e727a25 100644
--- a/tests/tools.at
+++ b/tests/tools.at
@@ -362,6 +362,73 @@ AT_CHECK([autoconf])
AT_CLEANUP
+# autoconf: forbidden tokens, no comment
+# -------------------------------------------------
+AT_SETUP([autoconf: forbidden tokens,[] no comment])
+
+AT_DATA_M4SH([configure.ac],
+[[AS_INIT
+m4_pattern_forbid([FOOBAR])
+FOOBAR
+]])
+
+AT_CHECK_AUTOCONF([], 1, [],
+[[configure.ac:2: error: possibly undefined macro: FOOBAR
+ If this token and others are legitimate, please use m4@&address@hidden
+ See the Autoconf documentation.
+]])
+# Second run should succeed and yield no output.
+AT_CHECK([autoconf])
+
+AT_CLEANUP
+
+
+# autoconf: forbidden tokens, with one-line comment
+# -------------------------------------------------
+AT_SETUP([autoconf: forbidden tokens,[] one-line comment])
+
+AT_DATA_M4SH([configure.ac],
+[[AS_INIT
+m4_pattern_forbid([FOOBAR], [foobar macro not found])
+FOOBAR
+]])
+
+AT_CHECK_AUTOCONF([], 1, [],
+[[configure.ac:2: error: foobar macro not found
+ If this token and others are legitimate, please use m4@&address@hidden
+ See the Autoconf documentation.
+]])
+# Second run should succeed and yield no output.
+AT_CHECK([autoconf])
+
+AT_CLEANUP
+
+
+# autoconf: forbidden tokens, with multi-line comment
+# -------------------------------------------------
+AT_SETUP([autoconf: forbidden tokens,[] multi-line comment])
+
+AT_DATA_M4SH([configure.ac],
+[[AS_INIT
+m4_pattern_forbid([FOOBAR], [line 1 of comment
+line 2 of comment
+line 3 of comment])
+FOOBAR
+]])
+
+AT_CHECK_AUTOCONF([], 1, [],
+[[configure.ac:2: error: line 1 of comment
+line 2 of comment
+line 3 of comment
+ If this token and others are legitimate, please use m4@&address@hidden
+ See the Autoconf documentation.
+]])
+# Second run should succeed and yield no output.
+AT_CHECK([autoconf])
+
+AT_CLEANUP
+
+
# autoconf: forbidden tokens, exceptions
# --------------------------------------
AT_SETUP([autoconf: forbidden tokens,[] exceptions])
--
1.5.5.1