Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.1KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_at_check_pattern.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_AT_CHECK_PATTERN(COMMANDS, [STATUS], [STDOUT-RE], [STDERR-RE], [RUN-IF-FAIL], [RUN-IF-PASS])
  8. # AX_AT_DIFF_PATTERN(PATTERN-FILE, TEST-FILE, [STATUS=0], [DIFFERENCES])
  9. #
  10. # DESCRIPTION
  11. #
  12. # AX_AT_CHECK_PATTERN() executes a test similar to AT_CHECK(), except that
  13. # stdout and stderr are awk regular expressions (REs).
  14. #
  15. # NOTE: as autoconf uses [] for quoting, the use of [brackets] in the RE
  16. # arguments STDOUT-RE and STDERR-RE can be awkward and require careful
  17. # extra quoting, or quadrigraphs '@<:@' (for '[') and '@:>@' (for ']').
  18. #
  19. # awk is invoked via $AWK, which defaults to "awk" if unset or empty.
  20. #
  21. # Implemented using AT_CHECK() with a custom value for $at_diff that
  22. # invokes diff with an awk post-processor.
  23. #
  24. # AX_AT_DIFF_PATTERN() checks that the PATTERN-FILE applies to TEST-FILE.
  25. # If there are differences, STATUS will be 1 and they should be
  26. # DIFFERENCES.
  27. #
  28. # LICENSE
  29. #
  30. # Copyright (c) 2013-2014 Luke Mewburn <luke@mewburn.net>
  31. #
  32. # Copying and distribution of this file, with or without modification, are
  33. # permitted in any medium without royalty provided the copyright notice
  34. # and this notice are preserved. This file is offered as-is, without any
  35. # warranty.
  36. #serial 2
  37. m4_defun([_AX_AT_CHECK_PATTERN_PREPARE], [dnl
  38. dnl Can't use AC_PROG_AWK() in autotest.
  39. AS_VAR_IF([AWK], [], [AWK=awk])
  40. AS_REQUIRE_SHELL_FN([ax_at_diff_pattern],
  41. [AS_FUNCTION_DESCRIBE([ax_at_diff_pattern], [PATTERN OUTPUT],
  42. [Diff PATTERN OUTPUT and elide change lines where the RE pattern matches])],
  43. [diff "$[]1" "$[]2" | $AWK '
  44. BEGIN { exitval=0 }
  45. function mismatch()
  46. {
  47. print mode
  48. for (i = 0; i < lc; i++) {
  49. print ll[[i]]
  50. }
  51. print "---"
  52. for (i = 0; i < rc; i++) {
  53. print rl[[i]]
  54. }
  55. mode=""
  56. exitval=1
  57. }
  58. $[]1 ~ /^[[0-9]]+(,[[0-9]]+)?[[ad]][[0-9]]+(,[[0-9]]+)?$/ {
  59. print
  60. mode=""
  61. exitval=1
  62. next
  63. }
  64. $[]1 ~ /^[[0-9]]+(,[[0-9]]+)?[[c]][[0-9]]+(,[[0-9]]+)?$/ {
  65. mode=$[]1
  66. lc=0
  67. rc=0
  68. next
  69. }
  70. mode == "" {
  71. print $[]0
  72. next
  73. }
  74. $[]1 == "<" {
  75. ll[[lc]] = $[]0
  76. lc = lc + 1
  77. next
  78. }
  79. $[]1 == "---" {
  80. next
  81. }
  82. $[]1 == ">" {
  83. rl[[rc]] = $[]0
  84. rc = rc + 1
  85. if (rc > lc) {
  86. mismatch()
  87. next
  88. }
  89. pat = "^" substr(ll[[rc-1]], 2) "$"
  90. str = substr($[]0, 2)
  91. if (str !~ pat) {
  92. mismatch()
  93. }
  94. next
  95. }
  96. {
  97. print "UNEXPECTED LINE: " $[]0
  98. exit 10
  99. }
  100. END { exit exitval }
  101. '])dnl ax_at_diff_pattern
  102. ])dnl _AX_AT_CHECK_PATTERN_PREPARE
  103. m4_defun([AX_AT_CHECK_PATTERN], [dnl
  104. AS_REQUIRE([_AX_AT_CHECK_PATTERN_PREPARE])
  105. _ax_at_check_pattern_prepare_original_at_diff="$at_diff"
  106. at_diff='ax_at_diff_pattern'
  107. AT_CHECK($1, $2, $3, $4,
  108. [at_diff="$_ax_at_check_pattern_prepare_original_at_diff";]$5,
  109. [at_diff="$_ax_at_check_pattern_prepare_original_at_diff";]$6)
  110. ])dnl AX_AT_CHECK_PATTERN
  111. m4_defun([AX_AT_DIFF_PATTERN], [dnl
  112. AS_REQUIRE([_AX_AT_CHECK_PATTERN_PREPARE])
  113. AT_CHECK([ax_at_diff_pattern $1 $2], [$3], [$4])
  114. ])dnl AX_AT_CHECK_PATTERN