1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
# SYNOPSIS
#
# AX_AT_CHECK_PATTERN(COMMANDS, [STATUS], [STDOUT-RE], [STDERR-RE], [RUN-IF-FAIL], [RUN-IF-PASS])
# AX_AT_DIFF_PATTERN(PATTERN-FILE, TEST-FILE, [STATUS=0], [DIFFERENCES])
# AX_AT_DATA_CHECK_PATTERN_AWK(FILENAME)
#
# DESCRIPTION
#
# AX_AT_CHECK_PATTERN() executes a test similar to AT_CHECK(), except
# that stdout and stderr are awk regular expressions (REs).
#
# NOTE: as autoconf uses [] for quoting, the use of [brackets] in the RE
# arguments STDOUT-RE and STDERR-RE can be awkward and require careful
# extra quoting, or quadrigraphs '@<:@' (for '[') and '@:>@' (for ']').
#
# awk is invoked via $AWK, which defaults to "awk" if unset or empty.
#
# Implemented using AT_CHECK() with a custom value for $at_diff that
# invokes diff with an awk post-processor.
#
#
# AX_AT_DIFF_PATTERN() checks that the PATTERN-FILE applies to TEST-FILE.
# If there are differences, STATUS will be 1 and they should be DIFFERENCES.
#
#
# AX_AT_DATA_CHECK_PATTERN_AWK() creates FILENAME with the contents of
# the awk script used.
#
#
# The latest version of this macro and a supporting test suite are at:
# https://github.com/lukem/pyrediff
#
#
# LICENSE
#
# Copyright (c) 2013-2017 Luke Mewburn <luke@mewburn.net>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
#serial 13
m4_define([_AX_AT_CHECK_PATTERN_AWK],
[[BEGIN { exitval=0 }
function set_mode(m)
{
mode=m
lc=0
rc=0
}
function mismatch()
{
print mode
for (i = 0; i < lc; i++) {
print ll@<:@i@:>@
}
print "---"
for (i = 0; i < rc; i++) {
print rl@<:@i@:>@
}
set_mode("")
exitval=1
}
function change_mode(m)
{
if (lc > rc) {
mismatch()
}
set_mode(m)
}
@S|@1 ~ /^@<:@0-9@:>@+(,@<:@0-9@:>@+)?@<:@ad@:>@@<:@0-9@:>@+(,@<:@0-9@:>@+)?@S|@/ {
change_mode("")
print
exitval=1
next
}
@S|@1 ~ /^@<:@0-9@:>@+(,@<:@0-9@:>@+)?@<:@c@:>@@<:@0-9@:>@+(,@<:@0-9@:>@+)?@S|@/ {
change_mode(@S|@1)
next
}
mode == "" {
print @S|@0
next
}
@S|@1 == "<" {
ll@<:@lc@:>@ = @S|@0
lc = lc + 1
next
}
@S|@1 == "---" {
next
}
@S|@1 == ">" {
rl@<:@rc@:>@ = @S|@0
rc = rc + 1
if (rc > lc) {
mismatch()
next
}
pat = "^" substr(ll@<:@rc-1@:>@, 3) "@S|@"
str = substr(@S|@0, 3)
if (str !~ pat) {
mismatch()
}
next
}
{
print "UNEXPECTED LINE: " @S|@0
exit 10
}
END {
change_mode("")
exit exitval
}
]])
m4_defun([_AX_AT_CHECK_PATTERN_PREPARE], [dnl
dnl Can't use AC_PROG_AWK() in autotest.
AS_VAR_IF([AWK], [], [AWK=awk])
AS_REQUIRE_SHELL_FN([ax_at_diff_pattern],
[AS_FUNCTION_DESCRIBE([ax_at_diff_pattern], [PATTERN OUTPUT],
[Diff PATTERN OUTPUT and elide change lines where the RE pattern matches])],
[diff "$[]1" "$[]2" | $AWK '_AX_AT_CHECK_PATTERN_AWK'])
])dnl _AX_AT_CHECK_PATTERN_PREPARE
m4_defun([AX_AT_CHECK_PATTERN], [dnl
AS_REQUIRE([_AX_AT_CHECK_PATTERN_PREPARE])
_ax_at_check_pattern_prepare_original_at_diff="$at_diff"
at_diff='ax_at_diff_pattern'
AT_CHECK(m4_expand([$1]), [$2], m4_expand([$3]), m4_expand([$4]),
[at_diff="$_ax_at_check_pattern_prepare_original_at_diff";$5],
[at_diff="$_ax_at_check_pattern_prepare_original_at_diff";$6])
])dnl AX_AT_CHECK_PATTERN
m4_defun([AX_AT_DIFF_PATTERN], [dnl
AS_REQUIRE([_AX_AT_CHECK_PATTERN_PREPARE])
AT_CHECK([ax_at_diff_pattern $1 $2], [$3], [$4])
])dnl AX_AT_DIFF_PATTERN
m4_defun([AX_AT_DATA_CHECK_PATTERN_AWK], [dnl
m4_if([$1], [], [m4_fatal([$0: argument 1: empty filename])])dnl
AT_DATA([$1], [dnl
# check_pattern.awk
# Generated by AX_AT_DATA_CHECK_PATTERN_AWK()
# from https://github.com/lukem/pyrediff
#
# awk script to process the output of "diff PATTERN OUTPUT" removing lines
# where the difference is a PATTERN line that exactly matches an OUTPUT line.
#
#
# Copyright (c) 2013-2017 Luke Mewburn <luke@mewburn.net>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
#
]
_AX_AT_CHECK_PATTERN_AWK)
])dnl AX_AT_DATA_CHECK_PATTERN_AWK
|