1# -*- Autotest -*- 2 3AT_BANNER([Autotest.]) 4 5# Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2, or (at your option) 10# any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20# 02110-1301, USA. 21 22# AT_CHECK_AT(TITLE, SUITE-CODE, [XFAIL-CONDITION], [STATUS = 0], 23# [STDOUT := ignore], STDERR, [POST-TEST-CODE]) 24# --------------------------------------------------------------- 25# Create a new test named TITLE that runs a minimal Autotest test suite, 26# SUITE-CODE. Call AT_XFAIL_IF with XFAIL-CONDITION. STATUS and STDERR pass 27# directly to the AT_CHECK that call the minimal test suite. STDOUT is not 28# used, but it is reserved for future use. Run POST-TEST-CODE 29# at the top level after the micro-suite has been run. 30m4_define([AT_CHECK_AT], 31[ 32AT_SETUP([$1]) 33AT_KEYWORDS([autotest]) 34AT_CAPTURE_FILE([micro-suite.log]) 35AT_XFAIL_IF([$3]) 36 37AT_DATA([package.m4],[[ 38m4_define([AT_PACKAGE_NAME], [GNU Nonsense]) 39m4_define([AT_PACKAGE_TARNAME], [nonsense]) 40m4_define([AT_PACKAGE_VERSION], [1.0]) 41m4_define([AT_PACKAGE_STRING], [GNU Nonsense 1.0]) 42m4_define([AT_PACKAGE_BUGREPORT], [bug-autoconf@gnu.org]) 43]]) 44 45AT_DATA([mysuite.at], [$2]) 46 47# Do not use `testsuite' as the name of the small test suite, or the 48# log file it generates will overwrite the log that the Autoconf test 49# suite produces for this test case. 50AT_CHECK_AUTOM4TE([--language=autotest -o micro-suite mysuite.at]) 51AT_CHECK([$CONFIG_SHELL ./micro-suite], m4_default([$4], 0), [ignore], [$6]) 52AT_CHECK([$CONFIG_SHELL ./micro-suite -v -x], m4_default([$4], 0), [ignore], [$6]) 53$7 54AT_CLEANUP 55])# AT_CHECK_AT 56 57# AT_CHECK_AT_TEST(TITLE, SUITE-SNIPPET, ...) 58# ----------------------------------------------------------------------- 59# Wrapper for AT_CHECK_AT that surrounds SUITE-SNIPPET with a boilerplate 60# AT_INIT, AT_SETUP, and AT_CLEANUP and passes other arguments verbatim. 61m4_define([AT_CHECK_AT_TEST], 62[AT_CHECK_AT([$1], 63[[ 64AT_INIT([artificial test suite]) 65AT_SETUP([my only test]) 66$2 67AT_CLEANUP 68]], m4_shiftn(2, $@))]) 69 70# Here documents for these tests contain forbidden macros. 71m4_pattern_allow([^AT_]) 72 73# AT_NO_CMDSUBST 74# -------------- 75m4_define([AT_NO_CMDSUBST], 76[if (eval 'foo=$(echo bar) && test "$foo" = bar') >/dev/null 2>&1; then false; else :; fi]) 77 78 79## ------------------ ## 80## Empty test suite. ## 81## ------------------ ## 82 83# This is not a sensible thing to do, but the user should not get an unhelpful 84# error message. 85AT_CHECK_AT([Empty test suite], 86[[AT_INIT([empty test suite]) 87]]) 88 89# Next level of emptiness. 90AT_CHECK_AT_TEST([Empty test], []) 91 92# And finally, an empty check should not cause a syntax error. 93AT_CHECK_AT_TEST([Empty check], [AT_CHECK]) 94 95## ----------------------------------------------------- ## 96## Newlines and command substitutions in test commands. ## 97## ----------------------------------------------------- ## 98 99AT_CHECK_AT_TEST([Truth], 100 [AT_CHECK([:], 0, [], [])]) 101 102AT_CHECK_AT_TEST([Fallacy], 103 [AT_CHECK([false], ignore, [], [])]) 104 105AT_CHECK_AT_TEST([Literal multiline command], 106 [AT_CHECK([echo Auto' 107'conf], 0, [Auto 108conf 109], [])]) 110 111AT_CHECK_AT_TEST([Multiline parameter expansion], 112 [FOO='one 113two' 114 AT_CHECK([echo "$FOO"], 0, [one 115two 116], [])]) 117 118AT_CHECK_AT_TEST([Backquote command substition], 119 [AT_CHECK([echo `echo hi`], 0, [hi 120], [])]) 121 122 123AT_CHECK_AT_TEST([Multiline backquote command substition], 124 [AT_DATA([myfile],[foo 125bar 126]) 127 AT_CHECK([echo "`cat myfile`"], 0, [foo 128bar 129], [])]) 130 131AT_CHECK_AT_TEST([Parenthetical command substition], 132 [AT_CHECK([echo $(echo hi)], 0, [hi 133], [])], 134 [AT_NO_CMDSUBST]) 135 136AT_CHECK_AT_TEST([Multiline parenthetical command substition], 137 [AT_DATA([myfile],[foo 138bar 139]) 140 AT_CHECK([echo "$(cat myfile)"], 0, [foo 141bar 142], [])], 143 [AT_NO_CMDSUBST]) 144 145 146## ------------------------- ## 147## ${...} in test commands. ## 148## ------------------------- ## 149 150# If this invalid parameter expansion capsizes the test suite, the entire 151# AT_SETUP ... AT_CLEANUP subshell will exit, and the commands it runs will 152# appear to have succeeded. Therefore, we verify a failing test case. 153 154AT_CHECK_AT_TEST([Invalid brace-enclosed parameter expansion], 155 [AT_CHECK([echo '${=invalid}'], 0, [wrong])], [false], 1, ignore, ignore) 156 157 158## ---------------------------- ## 159## M4 macros in test commands. ## 160## ---------------------------- ## 161 162# The last paragaph in the comment above _AT_DECIDE_TRACEABLE illustrates why 163# this test fails (except with Korn shell-style quoting $'foo\nbar'). 164AT_CHECK_AT_TEST([Multiline command from M4 expansion], 165 [m4_define([GNU], ['foo 166bar']) 167 AT_CHECK([echo GNU], 0, [foo 168bar 169], [])], [case `( set -x; echo 'foo 170bar') 2>&1` in *\$\'foo\\nbar\'*) false;; *) :;; esac]) 171 172AT_CHECK_AT_TEST([Double-M4-quoted command], 173 [m4_define([GNU], ['foo 174bar']) 175 AT_CHECK([[echo GNU]], 0, [[GNU 176]], [])]) 177 178 179## -------------------------------------- ## 180## Backslash-<newline> in test commands. ## 181## -------------------------------------- ## 182 183AT_CHECK_AT_TEST([BS-newline in command], 184 [AT_CHECK([echo Auto"\ 185"conf], 0, [Autoconf 186], [])]) 187 188AT_CHECK_AT_TEST([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\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf 196], [])]) 197 198AT_CHECK_AT_TEST([BS-BS-newline in command], 199 [AT_CHECK([echo Auto"\\ 200"conf], 0, [Auto\ 201conf 202], [])]) 203 204# A `^BS-BS-newline in command' test will run a command named `\'. No, thanks. 205 206AT_CHECK_AT_TEST([BSx640-newline in command], 207 [AT_CHECK([echo Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 208"conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 209conf 210], [])]) 211 212# This command has both escaped and unescaped newlines. 213AT_CHECK_AT_TEST([Newline-CODE-BS-newline in command], 214 [AT_CHECK([echo Auto' 215'co\ 216nf], 0, [Auto 217conf 218], [])]) 219 220AT_CHECK_AT_TEST([Single-quote-BS-newline in command], 221 [AT_CHECK([echo Auto'\ 222'conf], 0, [Auto\ 223conf 224], [])]) 225 226AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command], 227 [AT_CHECK([echo Auto' 228\ 229'conf], 0, [Auto 230\ 231conf 232], [])]) 233 234 235## ------------------------------- ## 236## Funny characters in test names. ## 237## ------------------------------- ## 238 239# AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST 240# [XFAIL-CONDITION]) 241# --------------------------------------------------------------- 242# Create a new test named TITLE that runs an Autotest test suite 243# comprised of a trivial test named TITLE-TO-TEST, which expands 244# to EXPANDED-TITLE-TO-TEST. XFAIL-CONDITION passes verbatim to 245# AT_CHECK_AT. 246m4_define([AT_CHECK_AT_TITLE], 247[AT_CHECK_AT([$1], 248[[ 249m4@&t@_define([macro_name], [[macro_expanded]]) 250m4@&t@_define([macro_expanded], [[macro_overexpanded]]) 251m4@&t@_define([macro_backquote], [`]) 252m4@&t@_define([macro_single_quote], [']) 253m4@&t@_define([macro_double_quote], ["]) 254m4@&t@_define([macro_backslash], [\\]) 255AT_INIT([artificial test suite]) 256AT_SETUP([$2]) 257AT_CHECK([:]) 258AT_CLEANUP 259]], [$4], [], [], [], 260[AT_CHECK([[$CONFIG_SHELL ./micro-suite | 261 sed -n 's/[^:]*: \(.*[^ ]\)[ ]*ok.*/\1/p']],, 262[[$3 263]]) 264AT_CHECK([[$CONFIG_SHELL ./micro-suite -l | 265 sed -n 's/.*[0-9]: [^ ][^ ]*[ ][ ]*\(.*[^ ]\)[ ]*/\1/p']],, 266[[$3 267]]) 268AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],, 269[[$3 270]]) 271])]) 272 273m4_define([AT_CHECK_AT_TITLE_CHAR], 274[AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name], 275 [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4)]) 276 277AT_CHECK_AT_TITLE_CHAR([Backquote], [`]) 278AT_CHECK_AT_TITLE_CHAR([Single-quote], [']) 279AT_CHECK_AT_TITLE_CHAR([Double-quote], ["]) 280AT_CHECK_AT_TITLE_CHAR([Backslash], [\\]) 281AT_CHECK_AT_TITLE_CHAR([Brackets], [[[]]], [[]]) 282AT_CHECK_AT_TITLE_CHAR([Pound], [[#]], [#]) 283AT_CHECK_AT_TITLE_CHAR([Comma], [,]) 284 285AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], 286 [macro_name]) 287AT_CHECK_AT_TITLE_CHAR([Macro], [macro_name], 288 [macro_expanded]) 289AT_CHECK_AT_TITLE_CHAR([Macro with backquote], [macro_backquote], 290 [`], [:]) 291AT_CHECK_AT_TITLE_CHAR([Macro with single-quote], [macro_single_quote], [']) 292AT_CHECK_AT_TITLE_CHAR([Macro with double-quote], [macro_double_quote], 293 ["], [:]) 294# This test neither fails nor passes reliably. 295# AT_CHECK_AT_TITLE_CHAR([Macro with backslash], [macro_backslash], 296# [\\], [:]) 297 298 299## ----------------- ## 300## Debugging a test. ## 301## ----------------- ## 302 303AT_CHECK_AT_TEST([Debugging a successful test], 304 [AT_CHECK([:])], [], [], [], [ignore], 305[# Without options, when all tests pass, no test directory should exist. 306AT_CHECK([test -d micro-suite.dir/1 && exit 42 307 ./micro-suite -d 1], [], [ignore], [ignore]) 308# Running with -d should leave a reproducible test group. 309# Also, running the test script from the test group locks the 310# directory from removal on some platforms; the script should still be 311# able to run even if rmdir fails. 312AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore]) 313# Running a debugging script implies -d. 314AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore]) 315]) 316 317AT_CHECK_AT_TEST([Debugging script and environment], 318 [AT_CHECK([test "$MY_VAR" = pass || exit 42])], 319 [], [1], [], [ignore], [ 320# Changing environment outside of debugging script is not preserved. 321AT_CHECK([(cd micro-suite.dir/1 && MY_VAR=pass ./run)], 322 [0], [ignore], [ignore]) 323AT_CHECK([(cd micro-suite.dir/1 && ./run)], 324 [1], [ignore], [ignore]) 325# Changing environment as argument to debugging script is preserved. 326AT_CHECK([(cd micro-suite.dir/1; ./run MY_VAR=pass)], 327 [0], [ignore], [ignore]) 328AT_CHECK([(cd micro-suite.dir/1; ./run)], 329 [0], [ignore], [ignore]) 330]) 331 332# The run script must still be valid when shell metacharacters are passed 333# in via an environment option. 334AT_CHECK_AT_TEST([Debugging a failed test], 335 [AT_CHECK([test "$MY_VAR" = "one space" || exit 42])], 336 [], [1], [], [ignore], [ 337AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='two spaces')], 338 [1], [ignore], [ignore]) 339AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='one space')], 340 [0], [ignore], [ignore]) 341]) 342 343 344## --------- ## 345## Keywords. ## 346## --------- ## 347AT_SETUP([Keywords and ranges]) 348AT_KEYWORDS([autotest]) 349 350AT_DATA([k.at], 351[[m4_define([AT_PACKAGE_STRING],[k]) 352m4_define([AT_PACKAGE_BUGREPORT],[devnull]) 353AT_INIT 354AT_SETUP(none) 355AT_CHECK(:) 356AT_CLEANUP 357AT_SETUP(first) 358AT_KEYWORDS(key1) 359AT_CHECK(:) 360AT_CLEANUP 361AT_SETUP(second) 362AT_KEYWORDS(key2) 363AT_CHECK(:) 364AT_CLEANUP 365AT_SETUP(both) 366AT_KEYWORDS(key1) 367AT_KEYWORDS(key2) 368AT_CHECK(:) 369AT_CLEANUP 370]]) 371AT_CHECK_AUTOM4TE([--language=autotest -o k k.at]) 372 373# AT_CHECK_EGREP(PATTERN, STATUS, COUNT) 374m4_define([AT_CHECK_EGREP], 375[AT_CHECK([$EGREP -c '$1' stdout], $2, [$3 376], ignore) 377]) 378 379# AT_CHECK_KEYS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2) 380m4_define([AT_CHECK_KEYS], 381[AT_CHECK([./k $1], 0, [stdout]) 382AT_CHECK_EGREP([$2], 0, [$3]) 383AT_CHECK_EGREP([$4], 1, [$5]) 384]) 385 386AT_CHECK_KEYS([-k key1], [first|both], [2], [none|second], [0]) 387AT_CHECK_KEYS([-k key2], [second|both], [2], [none|first], [0]) 388AT_CHECK_KEYS([-k key1,key2], [both], [1], [none|first|second], [0]) 389AT_CHECK_KEYS([-k key1 -k key2], [first|second|both], [3], [none], [0]) 390AT_CHECK_KEYS([-k '!key1'], [none|second], [2], [first|both], [0]) 391AT_CHECK_KEYS([-k '!key2'], [none|first], [2], [second|both], [0]) 392AT_CHECK_KEYS([-k '!key1,key2'], [second], [1], [none|first|both], [0]) 393AT_CHECK_KEYS([-k 'key1,!key2'], [first], [1], [none|second|both], [0]) 394AT_CHECK_KEYS([-k '!key1,!key2'], [none], [1], [first|second|both], [0]) 395AT_CHECK_KEYS([-k '!key1' -k KEY2], [none|second|both], [3], [first], [0]) 396AT_CHECK_KEYS([-k key1 -k '!key2'], [none|first|both], [3], [second], [0]) 397AT_CHECK_KEYS([-k '!KEY1' -k '!key2'], [none|first|second], [3], [both], [0]) 398 399AT_CHECK_KEYS([-k none], [none], [1], [first|second|both], [0]) 400AT_CHECK_KEYS([-k key1,both], [both], [1], [none|first|second], [0]) 401AT_CHECK_KEYS([-k key1 -k both], [first|both], [2], [none|second], [0]) 402AT_CHECK_KEYS([-k none,first], [successful], [1], [none|first|second|both], [0]) 403AT_CHECK_KEYS([-k none,first,second,both], [successful], [1], [none|first|second|both], [0]) 404AT_CHECK_KEYS([-k !none,first], [first], [1], [none|second|both], [0]) 405 406AT_CHECK_KEYS([-k '.*eco.*'], [second], [1], [none|first|both], [0]) 407AT_CHECK_KEYS([-k 'ECO'], [successful], [1], [none|first|second|both], [0]) 408AT_CHECK_KEYS([-k '.*eco'], [successful], [1], [none|first|second|both], [0]) 409AT_CHECK_KEYS([-k 'eco.*'], [successful], [1], [none|first|second|both], [0]) 410AT_CHECK_KEYS([-k 'fir.*'], [first], [1], [none|second|both], [0]) 411 412AT_CHECK_KEYS([1-2], [none|first], [2], [second|both], [0]) 413AT_CHECK_KEYS([1-3 2-1], [none|first|second], [3], [both], [0]) 414AT_CHECK_KEYS([-3], [none|first|second], [3], [both], [0]) 415AT_CHECK_KEYS([4-], [both], [1], [none|first|second], [0]) 416AT_CHECK_KEYS([-k second 4-], [second|both], [2], [none|first], [0]) 417AT_CLEANUP 418