1 # -*- Autotest -*- 2 3 AT_BANNER([Autotest.]) 4 5 # Copyright (C) 2004-2012 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 3 of the License, or 10 # (at your option) 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, see <http://www.gnu.org/licenses/>. 19 20 21 # AT_DATA_AUTOTEST(FILE-NAME, CONTENTS) 22 # ------------------------------------- 23 # Escape the invalid tokens with @&t@. 24 m4_define([AT_DATA_AUTOTEST], 25 [AT_DATA([$1], 26 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AT\)\(_\)\|\(d\)\(nl\)], 27 [\1\3\5@&t@\2\4\6])])]) 28 29 30 # AT_CHECK_AT_PREP(NAME, SUITE-CODE, [STATUS = 0], [STDOUT], [STDERR], 31 # [DIR = .]) 32 # -------------------------------------------------------------------- 33 # Create a new testsuite named NAME that runs a minimal Autotest test suite, 34 # SUITE-CODE. Do not use `testsuite' for NAME, or the log file it generates 35 # will overwrite the log that the Autoconf test produces when managing 36 # this test case. STATUS, STDOUT, and STDERR pass directly to the AT_CHECK 37 # that compiles the testsuite. DIR can specify a particular subdirectory 38 # where the testsuite should live. 39 m4_define([AT_CHECK_AT_PREP], 40 [AT_KEYWORDS([autotest])dnl 41 dnl overquote AT_dir, to make it easier to use 42 m4_pushdef([AT_dir], m4_ifval([$6], [[[$6]]], [.]))dnl 43 dnl 44 AT_CAPTURE_FILE(AT_dir[/$1.log])dnl 45 dnl 46 AT_DATA_AUTOTEST(AT_dir[/package.m4], 47 [[m4_define([AT_PACKAGE_NAME], [GNU Nonsense]) 48 m4_define([AT_PACKAGE_TARNAME], [nonsense]) 49 m4_define([AT_PACKAGE_VERSION], [1.0]) 50 m4_define([AT_PACKAGE_STRING], [GNU Nonsense 1.0]) 51 m4_define([AT_PACKAGE_BUGREPORT], [bug-autoconf (a] gnu.org]) 52 ]]) 53 dnl 54 AT_DATA_AUTOTEST(AT_dir[/$1.at], [$2]) 55 AT_CHECK([cat >m4_default([$6], [.])/atconfig <<EOF 56 at_testdir=m4_default([$6], [.]) 57 abs_builddir='`pwd`' 58 at_srcdir=. 59 abs_srcdir='`pwd`' 60 at_top_srcdir=. 61 abs_top_srcdir='`pwd`' 62 at_top_build_prefix= 63 abs_top_builddir='`pwd`' 64 EOF]) 65 m4_ifval([$6], [(cd AT_dir]) 66 AT_CHECK_AUTOM4TE([--language=autotest -o $1 $1.at], [$3], [$4], [$5]) 67 m4_ifval([$6], [)]) 68 m4_popdef([AT_dir])dnl 69 ]) # AT_CHECK_AT_PREP 70 71 # AT_CHECK_AT(TITLE, SUITE-CODE, [XFAIL-CONDITION], [STATUS = 0], 72 # [STDOUT = ignore], STDERR, [PRE-TEST-CODE], 73 # [POST-TEST-CODE], [SUITE-ARGS]) 74 # --------------------------------------------------------------- 75 # Create a new test named TITLE that runs a minimal Autotest test suite, 76 # SUITE-CODE with additional SUITE-ARGS, once without and once with 77 # '-v -x' added. Call AT_XFAIL_IF with XFAIL-CONDITION. Pass STDERR 78 # directly to the AT_CHECK that calls the minimal test suite, STDOUT to 79 # the AT_CHECK without '-v -x'; ignore stdout for the latter. 80 # Run PRE-TEST-CODE at the top level after the micro-suite is created, but 81 # before it is run, and POST-TEST-CODE after the micro-suite has been run. 82 m4_define([AT_CHECK_AT], 83 [AT_SETUP([$1]) 84 AT_XFAIL_IF([$3]) 85 AT_CHECK_AT_PREP([micro-suite], [$2]) 86 $7 87 AT_CHECK([$CONFIG_SHELL ./micro-suite $9], m4_default([$4], 0), 88 m4_default([$5], [ignore]), [$6]) 89 AT_CHECK([$CONFIG_SHELL ./micro-suite -v -x $9], m4_default([$4], 0), 90 [ignore], [$6]) 91 $8 92 AT_CLEANUP 93 ])# AT_CHECK_AT 94 95 # AT_CHECK_AT_TEST(TITLE, SUITE-SNIPPET, ...) 96 # ------------------------------------------- 97 # Wrapper for AT_CHECK_AT that surrounds SUITE-SNIPPET with a boilerplate 98 # AT_INIT, AT_SETUP, and AT_CLEANUP and passes other arguments verbatim. 99 m4_define([AT_CHECK_AT_TEST], 100 [AT_CHECK_AT([$1], 101 [[ 102 AT_INIT([artificial test suite]) 103 AT_SETUP([my only test]) 104 $2 105 AT_CLEANUP 106 ]], m4_shift2($@))]) # AT_CHECK_AT_TEST 107 108 # AT_CHECK_AT_SYNTAX(TITLE, SUITE, MESSAGE) 109 # ----------------------------------------- 110 # Create a test named TITLE that tries compiling SUITE with syntax 111 # errors with autotest. Expect a failed compilation, and grep for 112 # MESSAGE occurring within the error output. 113 m4_define([AT_CHECK_AT_SYNTAX], 114 [AT_SETUP([$1]) 115 AT_CHECK_AT_PREP([micro-suite], [$2], [1], [], [stderr]) 116 AT_CHECK([grep '$3' stderr], [0], [ignore]) 117 AT_CLEANUP 118 ])# AT_CHECK_AT_SYNTAX 119 120 121 # AT_NO_CMDSUBST 122 # -------------- 123 m4_define([AT_NO_CMDSUBST], 124 [if (eval 'foo=$(echo bar) && test "$foo" = bar') >/dev/null 2>&1; then ]dnl 125 [false; else :; fi]) 126 127 # AT_CHECK_EGREP(PATTERN, STATUS, COUNT) 128 # -------------------------------------- 129 # Run grep -E, counting how many times PATTERN occurs in the file 'stdout', 130 # and expecting exit STATUS and output COUNT. 131 m4_define([AT_CHECK_EGREP], 132 [AT_CHECK([$EGREP -c '$1' stdout], [$2], [$3 133 ], [ignore]) 134 ]) 135 136 137 ## -------------- ## 138 ## AT_COPYRIGHT. ## 139 ## -------------- ## 140 141 # Ensure the FSF notice as well as the user-provided one are present 142 # in the head of the testsuite as well as the --version output. 143 144 AT_CHECK_AT([AT@&t@_COPYRIGHT], 145 [[AT_INIT([Testing AT@&t@_COPYRIGHT]) 146 AT_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid 147 words that may be matched by scanners for legal things, 148 causing extra work for distributors. 149 Multi-line values should be supported. 150 ]]) 151 ]], [], [], [stdout], [], [], [ 152 AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore]) 153 AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore]) 154 AT_CHECK([sed 50q micro-suite | grep 'Copyright.*Free Software Foundation'], 155 [], [ignore]) 156 AT_CHECK([sed 50q micro-suite | grep 'This is just a test notice'], 157 [], [ignore])], 158 [--version]) 159 160 161 ## --------- ## 162 ## AT_DATA. ## 163 ## --------- ## 164 165 AT_CHECK_AT_TEST([AT@&t@_DATA], [ 166 AT_CHECK([test -f file1], [1]) 167 AT_DATA([file1]) 168 AT_CHECK([test -f file1 && test ! -s file1]) 169 AT_CHECK([echo hi > file1]) 170 AT_DATA([file1], [[]]) 171 AT_CHECK([test -f file1 && test ! -s file1]) 172 file=file2 173 AT_DATA([$file], [[$file 174 ]]) 175 AT_CHECK([echo '$file' > file3]) 176 AT_CHECK([cmp file2 file3]) 177 ]) 178 179 180 ## ------------------ ## 181 ## Empty test suite. ## 182 ## ------------------ ## 183 184 # This is not a sensible thing to do, but the user should not get an unhelpful 185 # error message. 186 AT_CHECK_AT([Empty test suite], 187 [[AT_INIT([empty test suite]) 188 ]]) 189 190 AT_CHECK_AT([Banner-only test suite], 191 [[AT_INIT([empty test suite]) 192 AT_BANNER([banner]) 193 ]]) 194 195 # Next level of emptiness. 196 AT_CHECK_AT_TEST([Empty test], []) 197 198 # And finally, an empty check should not cause a syntax error. 199 AT_CHECK_AT_TEST([Empty check], [AT_CHECK]) 200 201 # Check for sensible error messages for common bugs. 202 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP without AT@&t@_INIT], 203 [[AT_SETUP([only test]) 204 AT_CHECK([:]) 205 AT_CLEANUP 206 ]], [AT@&t@_SETUP: missing AT@&t@_INIT detected]) 207 208 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER without AT@&t@_INIT], 209 [[AT_BANNER([just a banner]) 210 ]], [AT@&t@_BANNER: missing AT@&t@_INIT detected]) 211 212 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_INIT], 213 [[AT_CLEANUP 214 ]], [AT@&t@_CLEANUP: missing AT@&t@_INIT detected]) 215 216 AT_CHECK_AT_SYNTAX([Missing AT@&t@_CLEANUP], 217 [[AT_INIT([incomplete test suite]) 218 AT_SETUP([only test]) 219 AT_CHECK([:]) 220 ]], [missing AT@&t@_CLEANUP detected]) 221 222 AT_CHECK_AT_SYNTAX([AT@&t@_FAIL_IF without AT@&t@_SETUP], 223 [[AT_INIT([incomplete test suite]) 224 AT_FAIL_IF([:]) 225 ]], [AT@&t@_FAIL_IF: missing AT@&t@_SETUP detected]) 226 227 AT_CHECK_AT_SYNTAX([AT@&t@_SKIP_IF without AT@&t@_SETUP], 228 [[AT_INIT([incomplete test suite]) 229 AT_SKIP_IF([:]) 230 ]], [AT@&t@_SKIP_IF: missing AT@&t@_SETUP detected]) 231 232 AT_CHECK_AT_SYNTAX([AT@&t@_CHECK without AT@&t@_SETUP], 233 [[AT_INIT([incomplete test suite]) 234 AT_CHECK([:]) 235 ]], [AT@&t@_CHECK: missing AT@&t@_SETUP detected]) 236 237 AT_CHECK_AT_SYNTAX([AT@&t@_DATA without AT@&t@_SETUP], 238 [[AT_INIT([incomplete test suite]) 239 AT_DATA([file]) 240 ]], [AT@&t@_DATA: missing AT@&t@_SETUP detected]) 241 242 AT_CHECK_AT_SYNTAX([AT@&t@_XFAIL_IF without AT@&t@_SETUP], 243 [[AT_INIT([incomplete test suite]) 244 AT_XFAIL_IF([:]) 245 ]], [AT@&t@_XFAIL_IF: missing AT@&t@_SETUP detected]) 246 247 AT_CHECK_AT_SYNTAX([AT@&t@_KEYWORDS without AT@&t@_SETUP], 248 [[AT_INIT([incomplete test suite]) 249 AT_KEYWORDS([keyword]) 250 ]], [AT@&t@_KEYWORDS: missing AT@&t@_SETUP detected]) 251 252 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_SETUP], 253 [[AT_INIT([incomplete test suite]) 254 AT_CLEANUP 255 ]], [AT@&t@_CLEANUP: missing AT@&t@_SETUP detected]) 256 257 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER inside AT@&t@_SETUP], 258 [[AT_INIT([incomplete test suite]) 259 AT_SETUP([only test]) 260 AT_BANNER([banner]) 261 AT_CHECK([:]) 262 AT_CLEANUP 263 ]], [AT@&t@_BANNER: nested AT@&t@_SETUP detected]) 264 265 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP inside AT@&t@_SETUP], 266 [[AT_INIT([incomplete test suite]) 267 AT_SETUP([only test]) 268 AT_SETUP([nested test]) 269 AT_CHECK([:]) 270 AT_CLEANUP 271 AT_CHECK([:]) 272 AT_CLEANUP 273 ]], [AT@&t@_SETUP: nested AT@&t@_SETUP detected]) 274 275 AT_CHECK_AT_SYNTAX([Multiple AT@&t@_INIT], 276 [[AT_INIT([[suite, take one]]) 277 AT_INIT([repeat]) 278 ]], [AT@&t@_INIT: invoked multiple times]) 279 280 # Check for tested programs. autoconf should only appear once. 281 AT_CHECK_AT([Tested programs], 282 [[AT_INIT([programs test suite]) 283 AT_TESTED([autoconf autom4te]) 284 AT_TESTED([autoconf]) 285 ]], [], [], [], [], [], 286 [AT_CHECK([[sed -n 's|.*/\([^ /]* --version\)|\1|p' micro-suite.log]], [], 287 [[autoconf --version 288 autom4te --version 289 ]])]) 290 291 AT_CHECK_AT([Startup error messages], 292 [[AT_INIT([[suite]]) 293 AT_SETUP([only test]) 294 AT_CHECK([:]) 295 AT_CLEANUP 296 ]], [], [], [], [], [], 297 [AT_CHECK([sed -n '/exec AS_MESSAGE_LOG_FD/q; />&AS_MESSAGE_LOG_FD/p' < micro-suite])]) 298 299 ## ----------------- ## 300 ## Status handling. ## 301 ## ----------------- ## 302 303 AT_CHECK_AT_TEST([Truth], 304 [AT_CHECK([:], 0, [], [])]) 305 306 AT_CHECK_AT_TEST([Fallacy], 307 [AT_CHECK([false], [], [], [])], 308 [], [1], [], [ignore], [], 309 [AT_CHECK([grep failed micro-suite.log], [], [ignore])]) 310 311 AT_CHECK_AT_TEST([Skip], 312 [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])], 313 [], [], [], [], [], 314 [AT_CHECK([grep skipped micro-suite.log], [], [ignore])]) 315 316 AT_CHECK_AT_TEST([Hard fail], 317 [AT_CHECK([exit 99]) 318 AT_CLEANUP 319 AT_SETUP([another test]) 320 AT_XFAIL_IF([:]) 321 AT_CHECK([exit 99])], 322 [], [1], [], [ignore], [], 323 [AT_CHECK([grep '2 failed unexpectedly' micro-suite.log], [], [ignore]) 324 AT_CHECK([grep '^[[12]].*ok' micro-suite.log], [1])]) 325 326 AT_CHECK_AT_TEST([AT@&t@_FAIL_IF], 327 [AT_FAIL_IF([:]) 328 AT_CLEANUP 329 AT_SETUP 330 AT_FAIL_IF([false]) 331 AT_CLEANUP 332 AT_SETUP 333 AT_FAIL_IF([test x = y]) 334 AT_CLEANUP 335 AT_SETUP 336 AT_FAIL_IF([bah]) 337 AT_CLEANUP 338 AT_SETUP 339 AT_FAIL_IF([test x = x]) 340 AT_CLEANUP 341 AT_SETUP 342 AT_FAIL_IF([test $foo = x])], 343 [], [1], [stdout], [ignore], [], 344 [AT_CHECK([grep '1 5 failed' stdout], [], [ignore], [ignore])]) 345 346 AT_CHECK_AT_TEST([AT@&t@_SKIP_IF], 347 [AT_SKIP_IF([:]) 348 AT_CLEANUP 349 AT_SETUP 350 AT_SKIP_IF([false]) 351 AT_CLEANUP 352 AT_SETUP 353 AT_SKIP_IF([test x = y]) 354 AT_CLEANUP 355 AT_SETUP 356 AT_SKIP_IF([bah]) 357 AT_CLEANUP 358 AT_SETUP 359 AT_SKIP_IF([test x = x]) 360 AT_CLEANUP 361 AT_SETUP 362 AT_SKIP_IF([test $foo = x])], 363 [], [], [], [], [], 364 [AT_CHECK([grep '2.*skipped' micro-suite.log], [], [ignore], [ignore])]) 365 366 AT_CHECK_AT_TEST([Syntax error], 367 [AT_CHECK([:]) 368 AT_CLEANUP 369 AT_SETUP([syntax]) 370 AT_CHECK([if]) 371 AT_CLEANUP 372 AT_SETUP([another test]) 373 AT_CHECK([:])], 374 [], [0], [], [], [], 375 [dnl Until we can find a way to avoid catastrophic failure (ash) or 376 dnl lack of failure (zsh), skip the rest of this test on such shells. 377 echo 'if' > syntax 378 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in 379 0|"") exit 77;; 380 esac'], [0], [ignore], [ignore]) 381 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [stderr]) 382 AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])], 383 [1 3]) 384 385 AT_CHECK_AT_TEST([errexit], 386 [AT_CHECK([false]) 387 AT_CLEANUP 388 AT_SETUP([test that should not be run]) 389 AT_CHECK([:]) 390 AT_CLEANUP 391 AT_SETUP([xpassing test]) 392 AT_XFAIL_IF([:]) 393 AT_CHECK([:]) 394 AT_CLEANUP 395 AT_SETUP([another test that should not be run]) 396 AT_CHECK([:]) 397 AT_CLEANUP 398 AT_SETUP([skipping test]) 399 AT_CHECK([exit 77]) 400 AT_CLEANUP 401 AT_SETUP([xfailing test]) 402 AT_XFAIL_IF([:]) 403 AT_CHECK([false]) 404 AT_CLEANUP 405 AT_SETUP([a test that should be run]) 406 AT_CLEANUP 407 AT_SETUP([hard failure]) 408 AT_XFAIL_IF([:]) 409 AT_CHECK([exit 99]) 410 AT_CLEANUP 411 AT_SETUP([yet another test that should not be run])], 412 [], [1], [stdout], [stderr], [], 413 [AT_CHECK([test -f micro-suite.log], [1]) 414 touch micro-suite.log # shut up AT_CAPTURE_FILE. 415 AT_CHECK([grep "should not be run" stdout], [1]) 416 AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore]) 417 AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 3-], [1], [stdout], [stderr]) 418 AT_CHECK([grep "should not be run" stdout], [1]) 419 AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore]) 420 AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 5-], [1], [stdout], [stderr]) 421 AT_CHECK([grep "should be run" stdout], [0], [ignore]) 422 AT_CHECK([grep "should not be run" stdout], [1]) 423 AT_CHECK([grep "inhibited subsequent" stderr], [], [ignore])], 424 [--errexit]) 425 426 427 AT_CHECK_AT_TEST([at_status], 428 [AT_CHECK([exit $mystatus], [$expected], [], [], 429 [AT_CHECK([echo run-if-fail: $at_status], [], [ignore])], 430 [AT_CHECK([echo run-if-pass: $at_status], [], [ignore])]) 431 AT_CLEANUP 432 AT_SETUP([test with nested checks]) 433 AT_CHECK([exit $mystatus], [$expected], [], [], 434 [AT_CHECK([exit $mystatus], [$expected], [], [], 435 [AT_CHECK([echo inner run-if-fail: $at_status], [], 436 [ignore])])])], 437 [], [], [stdout], [], 438 [], [ 439 AT_CHECK([grep 'inner run-if-fail: 42' stdout], [], [ignore]) 440 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=0], [], [stdout]) 441 AT_CHECK([grep 'run-if-pass: 0' stdout], [], [ignore]) 442 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=0], [], [stdout]) 443 AT_CHECK([grep 'run-if-fail: 42' stdout], [], [ignore]) 444 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=42], [], [stdout]) 445 AT_CHECK([grep 'run-if-fail: 0' stdout], [], [ignore]) 446 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=42], [], [stdout]) 447 AT_CHECK([grep 'run-if-pass: 42' stdout], [], [ignore]) 448 ], 449 [-v mystatus=42 expected=1 450 ]) 451 452 453 AT_CHECK_AT_TEST([AT@&t@_CHECK execution environment], 454 [dnl The first test should fail, so we enter RUN-IF-FAIL. 455 AT_CHECK([test "$state" != before], [], [], [], 456 [state=run-if-fail 457 AT_CHECK([:]) dnl need this so we do not bail out at this point. 458 ]) 459 dnl This should pass, so we enter RUN-IF-PASS. 460 AT_CHECK([test "$state" = run-if-fail], [], [], [], [], 461 [state=run-if-pass]) 462 AT_CHECK([test "$state" = run-if-pass]) 463 dnl However, COMMANDS are run inside a subshell, so do not change state. 464 AT_CHECK([state=broken; false], [], [], [], 465 [AT_CHECK([test "$state" = run-if-pass])]) 466 AT_CHECK([state=broken], [], [], [], [], 467 [AT_CHECK([test "$state" = run-if-pass])]) 468 ], 469 [], [], [], [], [], [], [state=before]) 470 471 472 AT_CHECK_AT_TEST([unquoted output], 473 [m4_define([backtick], [`]) 474 a=a 475 AT_CHECK_UNQUOTED([echo 'a"b backtick`'], [], 476 [${a}"`echo 'b '`\`\backtick]m4_newline)], 477 [], [], [], [], [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])]) 478 479 AT_CHECK_AT_TEST([Trace output], 480 [AT_CHECK([echo some longer longer longer command piped | ]dnl 481 [sed 's,into some other longer longer longer command,,'], 482 [], [some longer longer longer command piped 483 ])]) 484 485 AT_CHECK_AT([Logging], 486 [[AT_INIT([artificial test suite]) 487 dnl intentionally write failing tests, to see what gets logged 488 AT_SETUP([one]) 489 AT_CHECK([echo magicstring01], [1], [ignore]) 490 AT_CLEANUP 491 AT_SETUP([two]) 492 AT_CHECK([echo magicstring02 >&2], [1], [], [ignore]) 493 AT_CLEANUP 494 AT_SETUP([three]) 495 AT_CHECK([echo magicstring03], [1], [ignore-nolog]) 496 AT_CLEANUP 497 AT_SETUP([four]) 498 AT_CHECK([echo magicstring04 >&2], [1], [], [ignore-nolog]) 499 AT_CLEANUP 500 AT_SETUP([five]) 501 AT_CHECK([echo magicstring05], [1], [stdout]) 502 AT_CLEANUP 503 AT_SETUP([six]) 504 AT_CHECK([echo magicstring06 >&2], [1], [], [stderr]) 505 AT_CLEANUP 506 AT_SETUP([seven]) 507 AT_CHECK([echo magicstring07], [1], [stdout-nolog]) 508 AT_CLEANUP 509 AT_SETUP([eight]) 510 AT_CHECK([echo magicstring08 >&2], [1], [], [stderr-nolog]) 511 AT_CLEANUP 512 AT_SETUP([nine]) 513 echo magicstring09 > expout 514 AT_CHECK([echo magicstring09], [1], [expout]) 515 AT_CLEANUP 516 AT_SETUP([ten]) 517 echo magicstring10 > experr 518 AT_CHECK([echo magicstring10 >&2], [1], [], [experr]) 519 AT_CLEANUP 520 ]], [], [1], [], [ignore], [], 521 [AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore-nolog], [ignore-nolog]) 522 AT_CHECK([grep '^magicstring' micro-suite.log], [], 523 [[magicstring01 524 magicstring02 525 magicstring05 526 magicstring06 527 ]])]) 528 529 530 AT_CHECK_AT([Binary output], 531 [[AT_INIT([artificial test suite]) 532 AT_SETUP([pass: no trailing newline]) 533 AT_CHECK([printf short], [0], [stdout-nolog]) 534 AT_CHECK([cat stdout], [0], [[short]]) 535 AT_CLEANUP 536 AT_SETUP([pass: non-printing characters]) 537 AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog]) 538 printf '\1\n' > expout 539 AT_CHECK([cat stderr], [0], [expout]) 540 AT_CLEANUP 541 AT_SETUP([pass: long lines]) 542 # 5000 bytes in str 543 str=.......... 544 str=$str$str$str$str$str$str$str$str$str$str 545 str=$str$str$str$str$str$str$str$str$str$str 546 str=$str$str$str$str$str 547 AT_CHECK_UNQUOTED([echo $str], [0], [[$str]m4_newline]) 548 AT_CLEANUP 549 AT_SETUP([fail: no trailing newline]) 550 AT_CHECK([printf short], [0], [stdout-nolog]) 551 AT_CHECK([cat stdout], [0], [[long]]) 552 AT_CLEANUP 553 AT_SETUP([fail: non-printing characters]) 554 AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog]) 555 printf '\2\n' > expout 556 AT_CHECK([cat stderr], [0], [expout]) 557 AT_CLEANUP 558 AT_SETUP([fail: long lines]) 559 # 5000 bytes in str 560 str=.......... 561 str=$str$str$str$str$str$str$str$str$str$str 562 str=$str$str$str$str$str$str$str$str$str$str 563 str=$str$str$str$str$str 564 AT_CHECK_UNQUOTED([echo x$str], [0], [[${str}x]m4_newline]) 565 AT_CLEANUP 566 ]], [], [0], [], [], [], 567 [AT_CHECK([$CONFIG_SHELL ./micro-suite 4], [1], [ignore], [ignore]) 568 AT_CHECK([$CONFIG_SHELL ./micro-suite 5], [1], [ignore], [ignore]) 569 AT_CHECK([$CONFIG_SHELL ./micro-suite 6], [1], [ignore], [ignore])], [1-3]) 570 571 572 AT_CHECK_AT_TEST([Cleanup], 573 [AT_CHECK([test ! -f cleanup.success && test ! -f cleanup.failure]) 574 AT_XFAIL_IF([$xfail]) 575 AT_CHECK_UNQUOTED([exit $value], [ignore], [$output], 576 [], [touch cleanup.failure], [touch cleanup.success])], 577 [], [], [], [], 578 [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED]) 579 output=; export output], 580 [AT_CHECK([test -d micro-suite.dir/1]) 581 AT_CHECK([test -f micro-suite.dir/1/cleanup.success]) 582 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure]) 583 584 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1], [], [ignore]) 585 AT_CHECK([test -f micro-suite.dir/1/cleanup.success]) 586 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure]) 587 588 AT_CHECK([$CONFIG_SHELL ./micro-suite xfail=: value=0], 589 [1], [ignore], [ignore]) 590 AT_CHECK([test -f micro-suite.dir/1/cleanup.success]) 591 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure]) 592 593 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1 output=mismatch], 594 [1], [ignore], [ignore]) 595 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success]) 596 AT_CHECK([test -f micro-suite.dir/1/cleanup.failure]) 597 598 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=77], [], [ignore]) 599 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success]) 600 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure]) 601 602 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=99], 603 [1], [ignore], [ignore]) 604 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success]) 605 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure]) 606 ], [-d xfail=false value=0]) 607 608 ## ----------------------------------------------------- ## 609 ## Newlines and command substitutions in test commands. ## 610 ## ----------------------------------------------------- ## 611 612 AT_CHECK_AT_TEST([Literal multiline command], 613 [AT_CHECK([echo Auto' 614 'conf], 0, [Auto 615 conf 616 ], [])]) 617 618 AT_CHECK_AT_TEST([Multiline parameter expansion], 619 [FOO='one 620 two' 621 AT_CHECK([echo "$FOO"], 0, [one 622 two 623 ], [])]) 624 625 AT_CHECK_AT_TEST([Backquote command substitution], 626 [AT_CHECK([echo `echo hi`], 0, [hi 627 ], [])]) 628 629 630 AT_CHECK_AT_TEST([Multiline backquote command substitution], 631 [AT_DATA([myfile],[foo 632 bar 633 ]) 634 AT_CHECK([echo "`cat myfile`"], 0, [foo 635 bar 636 ], [])]) 637 638 AT_CHECK_AT_TEST([Parenthetical command substitution], 639 [AT_CHECK([echo $(echo hi)], 0, [hi 640 ], [])], 641 [AT_NO_CMDSUBST]) 642 643 AT_CHECK_AT_TEST([Multiline parenthetical command substitution], 644 [AT_DATA([myfile],[foo 645 bar 646 ]) 647 AT_CHECK([echo "$(cat myfile)"], 0, [foo 648 bar 649 ], [])], 650 [AT_NO_CMDSUBST]) 651 652 653 AT_CHECK_AT_TEST([Shell comment in command], 654 [my_echo=echo 655 AT_CHECK([$my_echo one [#] two], [], [one 656 ])]) 657 658 659 ## ------------------------- ## 660 ## ${...} in test commands. ## 661 ## ------------------------- ## 662 663 # If this invalid parameter expansion capsizes the test suite, the entire 664 # AT_SETUP ... AT_CLEANUP subshell will exit, and the commands it runs will 665 # appear to have succeeded. Therefore, we verify a failing test case. 666 667 AT_CHECK_AT_TEST([Invalid brace-enclosed parameter expansion], 668 [AT_CHECK([echo '${=invalid}'], 0, [wrong])], [false], 1, ignore, ignore) 669 670 671 ## ---------------------------- ## 672 ## M4 macros in test commands. ## 673 ## ---------------------------- ## 674 675 AT_CHECK_AT_TEST([Multiline command from M4 expansion], 676 [m4_define([GNU], ['foo 677 bar']) 678 AT_CHECK([echo GNU], 0, [foo 679 bar 680 ], [])]) 681 682 AT_CHECK_AT_TEST([Double-M4-quoted command], 683 [m4_define([GNU], ['foo 684 bar']) 685 AT_CHECK([[echo GNU]], 0, [[GNU 686 ]], [])]) 687 688 689 AT_CHECK_AT_TEST([Metacharacters in command from M4 expansion], 690 [m4_define([GNU], [\"`]) 691 AT_CHECK([echo '\"`' [GNU] 'GNU'], 0, [GNU [G][NU] [\"` 692 ]], [])]) 693 694 695 ## -------------------------------------- ## 696 ## Backslash-<newline> in test commands. ## 697 ## -------------------------------------- ## 698 699 AT_CHECK_AT_TEST([BS-newline in command], 700 [AT_CHECK([echo Auto"\ 701 "conf], 0, [Autoconf 702 ], [])]) 703 704 AT_CHECK_AT_TEST([^BS-newline in command], 705 [AT_CHECK([\ 706 echo GNU], 0, [GNU 707 ], [])]) 708 709 AT_CHECK_AT_TEST([BSx641-newline in command], 710 [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 711 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf 712 ], [])]) 713 714 AT_CHECK_AT_TEST([BS-BS-newline in command], 715 [AT_CHECK([printf '%s\n' Auto"\\ 716 "conf], 0, [Auto\ 717 conf 718 ], [])]) 719 720 # A `^BS-BS-newline in command' test will run a command named `\'. No, thanks. 721 722 AT_CHECK_AT_TEST([BSx640-newline in command], 723 [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 724 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 725 conf 726 ], [])]) 727 728 # This command has both escaped and unescaped newlines. 729 AT_CHECK_AT_TEST([Newline-CODE-BS-newline in command], 730 [AT_CHECK([printf '%s\n' Auto' 731 'co\ 732 nf], 0, [Auto 733 conf 734 ], [])]) 735 736 AT_CHECK_AT_TEST([Single-quote-BS-newline in command], 737 [AT_CHECK([printf '%s\n' Auto'\ 738 'conf], 0, [Auto\ 739 conf 740 ], [])]) 741 742 AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command], 743 [AT_CHECK([printf '%s\n' Auto' 744 \ 745 'conf], 0, [Auto 746 \ 747 conf 748 ], [])]) 749 750 751 ## ----------------- ## 752 ## Input from stdin. ## 753 ## ----------------- ## 754 755 AT_SETUP([Input from stdin]) 756 757 AT_CHECK_AT_PREP([micro-suite], 758 [[AT_INIT 759 AT_SETUP([please enter hello<RETURN><EOF>]) 760 AT_CHECK([cat], [], [hello 761 ]) 762 AT_CLEANUP 763 ]]) 764 765 AT_CHECK([echo hello | $CONFIG_SHELL ./micro-suite], [], [ignore]) 766 AT_CHECK([$CONFIG_SHELL ./micro-suite </dev/null], [1], [ignore], [ignore]) 767 768 AT_CLEANUP 769 770 771 ## ------------------------------- ## 772 ## Funny characters in test names. ## 773 ## ------------------------------- ## 774 775 # AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST, 776 # [XFAIL-CONDITION], [COLUMN = 53]) 777 # --------------------------------------------------------------- 778 # Create a new test named TITLE that runs an Autotest test suite 779 # comprised of a trivial test named TITLE-TO-TEST, which expands 780 # to EXPANDED-TITLE-TO-TEST. XFAIL-CONDITION passes verbatim to 781 # AT_CHECK_AT. Verify that `ok' prints at COLUMN. 782 m4_define([AT_CHECK_AT_TITLE], 783 [AT_CHECK_AT([$1], 784 [[ 785 m4_define([macro_name], [[macro_expanded]]) 786 m4_define([macro_expanded], [[macro_overexpanded]]) 787 m4_define([macro_backquote], [`]) 788 m4_define([macro_single_quote], [']) 789 m4_define([macro_double_quote], ["]) 790 ]]dnl restore font-lock: " 791 [[m4_define([macro_backslash], [\]) 792 m4_define([macro_echo], [$][1]) 793 AT_INIT([artificial test suite]) 794 AT_SETUP([$2]) 795 AT_CHECK([:]) 796 AT_CLEANUP 797 ]], [$4], [], [], [], [], 798 dnl This sed script checks for two things - that the output is properly 799 dnl expanded, and that the 'ok' starts on the right column. 800 [AT_KEYWORDS([m4@&t@_expand]) 801 AT_CHECK([[$CONFIG_SHELL ./micro-suite | 802 sed -n '/^ 1:/{ 803 h 804 s/[^:]*: \(.*[^ ]\)[ ]*ok.*/\1/p 805 x 806 s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p 807 }']],, 808 [[$3 809 ok 810 ]]) 811 dnl This sed script checks for two things - that -v output doesn't have 812 dnl an empty $at_srcdir expansion, and that the 'testing ...' line 813 dnl contains the test group title. 814 AT_CHECK([[$CONFIG_SHELL ./micro-suite -v | 815 sed -n 's/.*testing \(.*\) \.\.\./\1/p; /^\/micro-suite\.at:/p']],, 816 [[$3 817 ]]) 818 AT_CHECK([[$CONFIG_SHELL ./micro-suite -l | 819 sed -n 's/.*[0-9]: [^ ][^ ]*[ ][ ]*\(.*[^ ]\)[ ]*/\1/p']],, 820 [[$3 821 ]]) 822 AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],, 823 [[$3 824 ]]) 825 ])]) 826 827 m4_define([AT_CHECK_AT_TITLE_CHAR], 828 [AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name], 829 [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4, $5)]) 830 831 AT_CHECK_AT_TITLE_CHAR([Backquote], [`]) 832 AT_CHECK_AT_TITLE_CHAR([Single-quote], [']) 833 AT_CHECK_AT_TITLE_CHAR([Double-quote], ["]) 834 dnl restore font-lock: " 835 AT_CHECK_AT_TITLE_CHAR([Backslash], [\]) 836 AT_CHECK_AT_TITLE_CHAR([Brackets], [[[]]], [[]]) 837 AT_CHECK_AT_TITLE_CHAR([Left bracket], [@<:@], [@<:@]) 838 AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:>@], [@:>@]) 839 AT_CHECK_AT_TITLE_CHAR([Quoted pound], [[#]], [#]) 840 AT_CHECK_AT_TITLE_CHAR([Pound], [#]) 841 AT_CHECK_AT_TITLE_CHAR([Quoted comma], [[,]], [,]) 842 AT_CHECK_AT_TITLE_CHAR([Comma], [,]) 843 dnl this test also hits quadrigraphs for () 844 AT_CHECK_AT_TITLE_CHAR([Parentheses], [(@{:@)@:}@], [(())]) 845 AT_CHECK_AT_TITLE_CHAR([Left paren], [[(]], [(]) 846 AT_CHECK_AT_TITLE_CHAR([Right paren], [[)]], [)]) 847 848 AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], [macro_name]) 849 AT_CHECK_AT_TITLE_CHAR([Macro], [macro_name], [macro_expanded]) 850 AT_CHECK_AT_TITLE_CHAR([Macro with backquote], [macro_backquote], [`]) 851 AT_CHECK_AT_TITLE_CHAR([Macro with single-quote], [macro_single_quote], [']) 852 AT_CHECK_AT_TITLE_CHAR([Macro with double-quote], [macro_double_quote], ["]) 853 dnl restore font-lock: " 854 AT_CHECK_AT_TITLE_CHAR([Macro with backslash], [macro_backslash], [\]) 855 AT_CHECK_AT_TITLE_CHAR([Macro echoing macro], [macro_echo([macro_name])], 856 [macro_expanded]) 857 AT_CHECK_AT_TITLE_CHAR([Macro echoing single-quote], [macro_echo(['])], [']) 858 AT_CHECK_AT_TITLE_CHAR([Long test title], [0123456789012345678901234567890123]) 859 AT_CHECK_AT_TITLE_CHAR([Longer test title], 860 [01234567890123456789012345678901234], [], [], [54]) 861 862 863 ## ----------------------- ## 864 ## Long test source lines. ## 865 ## ----------------------- ## 866 867 # Create a test file that has more than 99 words in a line, for Solaris awk. 868 # While at that, try out the limit of 2000 bytes in a text file line. 869 870 AT_CHECK_AT_TEST([Long test source lines], 871 [m4_for([nnn], [1], [999], [], [: ]) 872 AT_CHECK([:]) 873 ], [], [], [], [ignore], [], 874 [AT_CHECK([$CONFIG_SHELL ./micro-suite -k skipalltests], [], [ignore], [ignore]) 875 ]) 876 877 878 ## ---------------- ## 879 ## Huge testsuite. ## 880 ## ---------------- ## 881 882 # Ensure we don't hit line length limits with large test suites. 883 884 AT_CHECK_AT_TEST([Huge testsuite], 885 [m4_for([nnn], [1], [1999], [], 886 [AT_CLEANUP 887 AT_SETUP([test ]nnn) 888 ]) 889 ], [], [], [], [ignore], [], [], [1999]) 890 891 892 ## ----------------- ## 893 ## Debugging a test. ## 894 ## ----------------- ## 895 896 AT_CHECK_AT_TEST([Debugging a successful test], 897 [AT_CHECK([:])], [], [], [], [ignore], [], 898 [# Without options, when all tests pass, no test directory should exist. 899 AT_CHECK([test -d micro-suite.dir/1 && exit 42 900 $CONFIG_SHELL ./micro-suite -d 1], [], [ignore], [ignore]) 901 # Running with -d should leave a reproducible test group. 902 # Also, running the test script from the test group locks the 903 # directory from removal on some platforms; the script should still be 904 # able to run even if rmdir fails. 905 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore]) 906 # Running a debugging script implies -d. 907 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore]) 908 ]) 909 910 AT_CHECK_AT_TEST([Debugging script and environment], 911 [AT_CHECK([test "$MY_VAR" = pass || exit 42])], 912 [], [1], [], [ignore], [], [ 913 # Changing environment outside of debugging script is not preserved. 914 AT_CHECK([(cd micro-suite.dir/1 && MY_VAR=pass ./run)], 915 [0], [ignore], [ignore]) 916 AT_CHECK([(cd micro-suite.dir/1 && ./run)], 917 [1], [ignore], [ignore]) 918 # Changing environment as argument to debugging script is preserved. 919 AT_CHECK([(cd micro-suite.dir/1; ./run MY_VAR=pass)], 920 [0], [ignore], [ignore]) 921 AT_CHECK([(cd micro-suite.dir/1; ./run)], 922 [0], [ignore], [ignore]) 923 ]) 924 925 # The run script must still be valid when shell metacharacters are passed 926 # in via an environment option. 927 AT_CHECK_AT_TEST([Debugging a failed test], 928 [AT_CHECK([test "$MY_VAR" = "one space" || exit 42])], 929 [], [1], [], [ignore], [], [ 930 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='two spaces')], 931 [1], [ignore], [ignore]) 932 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='one space')], 933 [0], [ignore], [ignore]) 934 ]) 935 936 937 # Setting default variable values via atlocal. 938 AT_CHECK_AT_TEST([Using atlocal], 939 [AT_CHECK([test "x$MY_VAR" = "xodd; 'string" || exit 42])], 940 [], [1], [ignore], [ignore], [], [ 941 dnl check that command line can set variable 942 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR="odd; 'string"], [0], [ignore]) 943 dnl check that command line overrides environment 944 AT_CHECK([MY_VAR="odd; 'string" $CONFIG_SHELL ./micro-suite MY_VAR=unset], 945 [1], [ignore], [ignore]) 946 dnl check that atlocal can give it a default 947 AT_CHECK([cat <<EOF >atlocal 948 MY_VAR="odd; 'string" 949 export MY_VAR 950 dnl Also populate enough of atlocal to do what atconfig normally does. 951 at_testdir=. 952 abs_builddir='`pwd`' 953 at_srcdir=. 954 abs_srcdir='`pwd`' 955 at_top_srcdir=. 956 abs_top_srcdir='`pwd`' 957 at_top_build_prefix= 958 abs_top_builddir='`pwd`' 959 EOF 960 ]) 961 AT_CHECK([$CONFIG_SHELL ./micro-suite], [0], [ignore]) 962 dnl check that atlocal overrides environment 963 AT_CHECK([MY_VAR=unset $CONFIG_SHELL ./micro-suite], [0], [ignore]) 964 dnl check that command line overrides atlocal 965 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR=], [1], [ignore], [ignore]) 966 dnl check that syntax error is detected 967 AT_CHECK([$CONFIG_SHELL ./micro-suite =], [1], [], [ignore], [ignore]) 968 AT_CHECK([$CONFIG_SHELL ./micro-suite 1=2], [1], [], [ignore], [ignore]) 969 ]) 970 971 972 # Controlling where the testsuite is run. 973 AT_CHECK_AT_TEST([Choosing where testsuite is run], 974 [AT_CHECK([:])], [], [], [], [], [], [ 975 dnl AT_CHECK_AT_TEST tests the default of running in `.'. 976 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean]) 977 AT_CHECK([test -f micro-suite.log], [1]) 978 AT_CHECK([test -d micro-suite.dir], [1]) 979 AT_CHECK([mkdir sub1 sub2]) 980 dnl check specifying a different relative path to run in. 981 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [0], [ignore], []) 982 AT_CHECK([test -f micro-suite.log], [1]) 983 AT_CHECK([test -f sub1/micro-suite.log], [0]) 984 AT_CHECK([test -d micro-suite.dir], [1]) 985 AT_CHECK([test -d sub1/micro-suite.dir], [0]) 986 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --clean]) 987 AT_CHECK([test -f sub1/micro-suite.log], [1]) 988 AT_CHECK([test -d sub1/micro-suite.dir], [1]) 989 dnl check specifying an absolute path to run in. 990 AT_CHECK([$CONFIG_SHELL ./micro-suite --directory="`pwd`/sub2"], 991 [0], [ignore], []) 992 AT_CHECK([test -f micro-suite.log], [1]) 993 AT_CHECK([test -f sub2/micro-suite.log], [0]) 994 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean --directory="`pwd`/sub2"]) 995 AT_CHECK([test -f sub2/micro-suite.log], [1]) 996 AT_CHECK([test -f sub2/micro-suite.dir], [1]) 997 dnl check for failure detection with bad, missing, or empty directory. 998 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch || exit 1], [1], [ignore], [ignore]) 999 AT_CHECK([$CONFIG_SHELL ./micro-suite -C ''], [1], [ignore], [ignore]) 1000 AT_CHECK([$CONFIG_SHELL ./micro-suite -C - || exit 1], [1], [ignore], [ignore]) 1001 AT_CHECK([$CONFIG_SHELL ./micro-suite -C], [1], [ignore], [ignore]) 1002 dnl check that --help overrides bad directory selection. 1003 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch --help], [0], [ignore], []) 1004 ]) 1005 1006 1007 # --recheck. 1008 AT_CHECK_AT_TEST([recheck], 1009 [AT_CHECK([:]) 1010 AT_CLEANUP 1011 AT_SETUP([failing test]) 1012 AT_CHECK([exit 1]) 1013 AT_CLEANUP 1014 AT_SETUP([xpassing test]) 1015 AT_XFAIL_IF([:]) 1016 AT_CHECK([:]) 1017 AT_CLEANUP 1018 AT_SETUP([xfailing test]) 1019 AT_XFAIL_IF([:]) 1020 AT_CHECK([exit 1]) 1021 ], [], [], [], [], [], [ 1022 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [0], [stdout]) 1023 AT_CHECK([grep "0 tests were successful" stdout], [0], [ignore]) 1024 1025 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [ignore]) 1026 AT_CHECK([grep 'only test' micro-suite.log], [0], [ignore]) 1027 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [1], [ignore], [ignore]) 1028 AT_CHECK([grep 'only test' micro-suite.log], [1]) 1029 AT_CHECK([grep 'xfailing' micro-suite.log], [1]) 1030 AT_CHECK([grep 'failing test' micro-suite.log], [0], [ignore]) 1031 AT_CHECK([grep 'xpassing test' micro-suite.log], [0], [ignore]) 1032 1033 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean], [0]) 1034 AT_CHECK([test -f micro-suite.log], [1]) 1035 1036 dnl check specifying a different relative path to run in. 1037 AT_CHECK([mkdir sub1]) 1038 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [1], [ignore], [ignore]) 1039 AT_CHECK([test -f micro-suite.log], [1]) 1040 AT_CHECK([test -f sub1/micro-suite.log], [0]) 1041 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck --list], [0], [stdout]) 1042 AT_CHECK([grep 'only test' stdout], [1]) 1043 AT_CHECK([grep 'xfailing test' stdout], [1]) 1044 AT_CHECK([grep 'failing test' stdout], [0], [ignore]) 1045 AT_CHECK([grep 'xpassing test' stdout], [0], [ignore]) 1046 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck], [1], [ignore], 1047 [ignore]) 1048 AT_CHECK([grep 'failing test' sub1/micro-suite.log], [0], [ignore]) 1049 AT_CHECK([grep 'xpassing test' sub1/micro-suite.log], [0], [ignore]) 1050 ], [1 4]) 1051 1052 1053 ## -------- ## 1054 ## Banners. ## 1055 ## -------- ## 1056 AT_SETUP([Banners]) 1057 1058 AT_CHECK_AT_PREP([b], 1059 [[AT_INIT 1060 AT_SETUP(zero)# 1 1061 AT_CHECK(:) 1062 AT_CLEANUP 1063 1064 AT_BANNER([first]) 1065 AT_SETUP(one a)# 2 1066 AT_CHECK(:) 1067 AT_CLEANUP 1068 AT_SETUP(one b)# 3 1069 AT_CHECK(:) 1070 AT_CLEANUP 1071 1072 AT_BANNER() 1073 AT_SETUP(two a)# 4 1074 AT_CHECK(:) 1075 AT_CLEANUP 1076 AT_SETUP(two b)# 5 1077 AT_CHECK(:) 1078 AT_CLEANUP 1079 1080 AT_BANNER([second]) 1081 AT_SETUP(three a)# 6 1082 AT_CHECK(:) 1083 AT_CLEANUP 1084 AT_SETUP(three b)# 7 1085 AT_CHECK(:) 1086 AT_CLEANUP 1087 ]]) 1088 1089 # AT_CHECK_BANNERS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2) 1090 m4_define([AT_CHECK_BANNERS], 1091 [AT_CHECK([$CONFIG_SHELL ./b $1], [], [stdout]) 1092 AT_CHECK_EGREP([$2], m4_if([$3], [0], [1], [0]), [$3]) 1093 AT_CHECK_EGREP([$4], m4_if([$5], [0], [1], [0]), [$5]) 1094 ]) 1095 1096 AT_CHECK_BANNERS([], [first], [1], [second], [1]) 1097 AT_CHECK_BANNERS([-k zero], [first], [0], [second], [0]) 1098 AT_CHECK_BANNERS([1], [first], [0], [second], [0]) 1099 AT_CHECK_BANNERS([-2], [first], [1], [second], [0]) 1100 AT_CHECK_BANNERS([-3], [first], [1], [second], [0]) 1101 AT_CHECK_BANNERS([-k one], [first], [1], [second], [0]) 1102 AT_CHECK_BANNERS([3-4], [first], [1], [second], [0]) 1103 dnl There should be an empty line separating the first category from the 1104 dnl unnamed one. 1105 AT_CHECK([sed -n '/one b/,/two a/p' stdout | grep '^$'], [0], [ignore]) 1106 AT_CHECK_BANNERS([3-6], [first], [1], [second], [1]) 1107 AT_CHECK_BANNERS([4-6], [first], [0], [second], [1]) 1108 AT_CHECK_BANNERS([3-], [first], [1], [second], [1]) 1109 AT_CHECK_BANNERS([-k a], [first], [1], [second], [1]) 1110 AT_CHECK_BANNERS([4], [first], [0], [second], [0]) 1111 AT_CHECK_BANNERS([4-], [first], [0], [second], [1]) 1112 AT_CHECK_BANNERS([-k two], [first], [0], [second], [0]) 1113 AT_CHECK_BANNERS([1 4], [first], [0], [second], [0]) 1114 AT_CHECK_BANNERS([-k three], [first], [0], [second], [1]) 1115 AT_CHECK_BANNERS([5], [first], [0], [second], [0]) 1116 AT_CHECK_BANNERS([5-], [first], [0], [second], [1]) 1117 AT_CLEANUP 1118 1119 1120 ## --------- ## 1121 ## Keywords. ## 1122 ## --------- ## 1123 AT_SETUP([Keywords and ranges]) 1124 1125 AT_CHECK_AT_PREP([k], 1126 [[AT_INIT 1127 AT_SETUP(none) # 01 1128 AT_CHECK(:) 1129 AT_CLEANUP 1130 AT_SETUP(first) # 02 1131 AT_KEYWORDS(key1) 1132 AT_CHECK(:) 1133 AT_CLEANUP 1134 AT_SETUP(second) # 03 1135 AT_KEYWORDS(key2) 1136 AT_CHECK(:) 1137 AT_CLEANUP 1138 AT_SETUP(both) # 04 1139 AT_KEYWORDS([key1 key2]) 1140 AT_KEYWORDS([m4_echo([Key1])]) 1141 AT_CHECK(:) 1142 AT_CLEANUP 1143 AT_SETUP(test5) # 05 1144 AT_CHECK(:) 1145 AT_CLEANUP 1146 AT_SETUP(test6) # 06 1147 AT_CHECK(:) 1148 AT_CLEANUP 1149 AT_SETUP(test7) # 07 1150 AT_CHECK(:) 1151 AT_CLEANUP 1152 AT_SETUP(test8) # 08 1153 AT_CHECK(:) 1154 AT_CLEANUP 1155 AT_SETUP(test9) # 09 1156 AT_CHECK(:) 1157 AT_CLEANUP 1158 AT_SETUP(test10) # 10 1159 AT_CHECK(:) 1160 AT_CLEANUP 1161 ]]) 1162 dnl check that AT_KEYWORDS does not duplicate words 1163 AT_CHECK([grep -i 'key1.*key1' k], [1]) 1164 dnl check that -k requires an argument 1165 AT_CHECK([$CONFIG_SHELL ./k -k], [1], [], [ignore]) 1166 1167 # AT_CHECK_KEYS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2) 1168 m4_define([AT_CHECK_KEYS], 1169 [AT_CHECK([$CONFIG_SHELL ./k $1], 0, [stdout]) 1170 AT_CHECK_EGREP([$2], 0, [$3]) 1171 AT_CHECK_EGREP([$4], 1, [$5]) 1172 ]) 1173 1174 AT_CHECK_KEYS([-k key1], [first|both], [2], [none|second], [0]) 1175 AT_CHECK_KEYS([-k key2], [second|both], [2], [none|first], [0]) 1176 AT_CHECK_KEYS([-k key1,key2], [both], [1], [none|first|second], [0]) 1177 AT_CHECK_KEYS([-k key1 -k key2], [first|second|both], [3], [none], [0]) 1178 AT_CHECK_KEYS([-k '!key1'], [none|second], [2], [first|both], [0]) 1179 AT_CHECK_KEYS([-k '!key2'], [none|first], [2], [second|both], [0]) 1180 AT_CHECK_KEYS([-k '!key1,key2'], [second], [1], [none|first|both], [0]) 1181 AT_CHECK_KEYS([-k 'key1,!key2'], [first], [1], [none|second|both], [0]) 1182 AT_CHECK_KEYS([-k '!key1,!key2'], [none], [1], [first|second|both], [0]) 1183 AT_CHECK_KEYS([-k '!key1' -k KEY2], [none|second|both], [3], [first], [0]) 1184 AT_CHECK_KEYS([-k key1 -k '!key2'], [none|first|both], [3], [second], [0]) 1185 AT_CHECK_KEYS([-k '!KEY1' -k '!key2'], [none|first|second], [3], [both], [0]) 1186 1187 AT_CHECK_KEYS([-k none], [none], [1], [first|second|both], [0]) 1188 AT_CHECK_KEYS([-k key1,both], [both], [1], [none|first|second], [0]) 1189 AT_CHECK_KEYS([-k key1 -k both], [first|both], [2], [none|second], [0]) 1190 AT_CHECK_KEYS([-k none,first], [successful], [1], [none|first|second|both], [0]) 1191 AT_CHECK_KEYS([-k none,first,second,both], [successful], [1], [none|first|second|both], [0]) 1192 AT_CHECK_KEYS([-k !none,first], [first], [1], [none|second|both], [0]) 1193 1194 AT_CHECK_KEYS([-k '.*eco.*'], [second], [1], [none|first|both], [0]) 1195 AT_CHECK_KEYS([-k 'ECO'], [successful], [1], [none|first|second|both], [0]) 1196 AT_CHECK_KEYS([-k '.*eco'], [successful], [1], [none|first|second|both], [0]) 1197 AT_CHECK_KEYS([-k 'eco.*'], [successful], [1], [none|first|second|both], [0]) 1198 AT_CHECK_KEYS([-k 'fir.*'], [first], [1], [none|second|both], [0]) 1199 1200 AT_CHECK_KEYS([1-2], [none|first], [2], [second|both], [0]) 1201 AT_CHECK_KEYS([01-002 08], [none|first], [2], [second|both], [0]) 1202 AT_CHECK_KEYS([1-3 2-1], [none|first|second], [3], [both], [0]) 1203 AT_CHECK_KEYS([-3], [none|first|second], [3], [both], [0]) 1204 AT_CHECK_KEYS([4-], [both], [1], [none|first|second], [0]) 1205 AT_CHECK_KEYS([010], [test10], [1], [none|first|second|both], [0]) 1206 AT_CHECK_KEYS([-k second 4-], [second|both], [2], [none|first], [0]) 1207 1208 AT_CHECK([$CONFIG_SHELL ./k 0], [1], [ignore], [ignore]) 1209 AT_CHECK([$CONFIG_SHELL ./k 0-], [1], [ignore], [ignore]) 1210 AT_CHECK([$CONFIG_SHELL ./k -0], [1], [ignore], [ignore]) 1211 AT_CHECK([$CONFIG_SHELL ./k 11], [1], [ignore], [ignore]) 1212 AT_CHECK([$CONFIG_SHELL ./k 11-], [1], [ignore], [ignore]) 1213 AT_CHECK([$CONFIG_SHELL ./k 1-011], [1], [ignore], [ignore]) 1214 AT_CHECK([$CONFIG_SHELL ./k -k nonexistent], [0], [ignore]) 1215 1216 AT_CHECK_KEYS([--list -k nonexistent], [KEYWORDS], [1], [first|second|both], [0]) 1217 AT_CHECK_KEYS([--list 1], [none], [1], [first|second|both], [0]) 1218 AT_CHECK_KEYS([--list 01], [none], [1], [first|second|both], [0]) 1219 AT_CHECK_KEYS([--list -k none -k first], [none|first], [2], [second|both], [0]) 1220 AT_CLEANUP 1221 1222 1223 ## ----------------- ## 1224 ## Keyword wrapping. ## 1225 ## ----------------- ## 1226 AT_SETUP([Keyword wrapping]) 1227 1228 AT_CHECK_AT_PREP([k], 1229 [[AT_INIT 1230 AT_SETUP([test]) 1231 AT_KEYWORDS([a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1 t1]) 1232 AT_KEYWORDS([u1 v1 w1 x1 y1 z1]) 1233 AT_KEYWORDS([a b c d e f g h i j k l m n o p q r s t u v w x y z]) 1234 AT_CLEANUP 1235 AT_SETUP([test with long keywords]) 1236 AT_KEYWORDS( 1237 [this-is-a-long-keyword-that-cannot-be-wrapped-so-we-exceed-the-length-limit-here]) 1238 # surrounded by short ones 1239 AT_KEYWORDS([s]) 1240 AT_KEYWORDS( 1241 [another-very-long-keyword-that-hits-the-line-length-limit-bla-bla-bla-bla]) 1242 AT_KEYWORDS([t]) 1243 AT_CLEANUP 1244 ]]) 1245 1246 AT_CHECK_KEYS([-l], [.{80}], [1], [.{87}], [0]) 1247 1248 AT_CLEANUP 1249 1250 1251 ## ------------- ## 1252 ## AT_ARG_OPTION ## 1253 ## ------------- ## 1254 1255 AT_CHECK_AT([AT@&t@_ARG_OPTION], 1256 [[ 1257 AT_INIT([artificial test suite]) 1258 AT_ARG_OPTION([frob fro fr f], 1259 [AS_HELP_STRING([-f, --frob], [frobnicate the test run])], 1260 [frob=$at_optarg], [frob=default]) 1261 AT_ARG_OPTION([opt-with-hyphen], 1262 [AS_HELP_STRING([--opt-with-hyphen], [option name with hypen])]) 1263 AT_ARG_OPTION([ping], 1264 [AS_HELP_STRING([--ping], [ping on every encounter])], 1265 [echo ping]) 1266 AT_SETUP([test argument handling]) 1267 AT_CHECK([test "$frob" = "$FROB"]) 1268 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"]) 1269 AT_CLEANUP 1270 AT_SETUP([test hyphen normalization]) 1271 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"]) 1272 AT_CLEANUP 1273 ]], 1274 [], [], [stdout], [], [], 1275 [# We already invoked --help. 1276 AT_CHECK([grep ' -f, --frob.*frobnicate' stdout], [], [ignore]) 1277 for args in \ 1278 '1 FROB=default FROB_ARG=false' \ 1279 '1 -f FROB=: FROB_ARG=:' \ 1280 '1 --fr FROB=: FROB_ARG=:' \ 1281 '1 --fro FROB=: FROB_ARG=:' \ 1282 '1 --frob FROB=: FROB_ARG=:' \ 1283 '1 --no-f FROB=false FROB_ARG=false' \ 1284 '1 --no-fr FROB=false FROB_ARG=false' \ 1285 '1 --no-fro FROB=false FROB_ARG=false' \ 1286 '1 --no-frob FROB=false FROB_ARG=false' \ 1287 '2 expected=false' \ 1288 '2 --opt-with-hyphen expected=:' \ 1289 '2 --no-opt-with-hyphen expected=false' 1290 do 1291 AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore]) 1292 done 1293 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping --no-ping --ping expected=false], 1294 [], [stdout]) 1295 AT_CHECK([grep -c ping stdout], [], [[3 1296 ]]) 1297 ], [--help]) 1298 1299 1300 ## ----------------- ## 1301 ## AT_ARG_OPTION_ARG ## 1302 ## ----------------- ## 1303 1304 AT_CHECK_AT([AT@&t@_ARG_OPTION_ARG], 1305 [[ 1306 AT_INIT([artificial test suite]) 1307 AT_ARG_OPTION_ARG([frob fro fr f], 1308 [AS_HELP_STRING([-f, --frob=FOO], [frobnicate FOO])], 1309 [frob=$at_optarg], [frob=default]) 1310 AT_ARG_OPTION_ARG([opt-with-hyphen], 1311 [AS_HELP_STRING([--opt-with-hyphen=ARG], 1312 [option name with hypen])]) 1313 AT_ARG_OPTION_ARG([ping], 1314 [AS_HELP_STRING([--ping], [ping on every encounter])], 1315 [echo ping]) 1316 AT_SETUP([test argument handling]) 1317 AT_CHECK([test "$frob" = "$FROB"]) 1318 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"]) 1319 AT_CLEANUP 1320 AT_SETUP([test hyphen normalization]) 1321 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"]) 1322 AT_CLEANUP 1323 ]], 1324 [], [], [stdout], [], [], 1325 [# We already invoked --help. 1326 AT_CHECK([grep ' -f, --frob.*frobnicate' stdout], [], [ignore]) 1327 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --frob], [1], [ignore], [stderr]) 1328 AT_CHECK([grep 'requires an argument' stderr], [], [ignore]) 1329 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --no-frob], [1], [ignore], [stderr]) 1330 AT_CHECK([grep 'invalid option' stderr], [], [ignore]) 1331 for args in \ 1332 '1 FROB=default FROB_ARG=' \ 1333 '1 -f bar FROB=bar FROB_ARG=bar' \ 1334 '1 --fr bar FROB=bar FROB_ARG=bar' \ 1335 '1 --fro bar FROB=bar FROB_ARG=bar' \ 1336 '1 --frob bar FROB=bar FROB_ARG=bar' \ 1337 '1 -f=bar FROB=bar FROB_ARG=bar' \ 1338 '1 --fr=bar FROB=bar FROB_ARG=bar' \ 1339 '1 --fro=bar FROB=bar FROB_ARG=bar' \ 1340 '1 --frob=bar FROB=bar FROB_ARG=bar' \ 1341 '2 expected=' \ 1342 '2 --opt-with-hyphen=baz expected=baz' 1343 do 1344 AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore]) 1345 done 1346 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping=1 --ping=2 expected=], 1347 [], [stdout]) 1348 AT_CHECK([grep -c ping stdout], [], [[2 1349 ]]) 1350 ], [--help]) 1351 1352 1353 m4_define([AT_SKIP_PARALLEL_TESTS], 1354 [# Per BUGS, we have not yet figured out how to run parallel tests cleanly 1355 # under dash and some ksh variants. For now, only run this test under 1356 # limited conditions; help is appreciated in widening this test base. 1357 AT_SKIP_IF([${CONFIG_SHELL-$SHELL} -c 'test -z "${BASH_VERSION+set}]]dnl 1358 [[${ZSH_VERSION+set}${TEST_PARALLEL_AUTOTEST+set}"']) 1359 # The parallel scheduler requires mkfifo and job control to work. 1360 AT_CHECK([mkfifo fifo || exit 77]) 1361 AT_CHECK([${CONFIG_SHELL-$SHELL} -c '(set -m && set +m) || exit 77'], 1362 [], [], [ignore]) 1363 ]) 1364 1365 1366 ## ----------------------- ## 1367 ## parallel test execution ## 1368 ## ----------------------- ## 1369 1370 AT_SETUP([parallel test execution]) 1371 1372 # This test tries to ensure that -j runs tests in parallel. 1373 # Such a test is inherently racy, because there are no real-time 1374 # guarantees about scheduling delays. So we try to minimize 1375 # the chance to lose the race. 1376 1377 # The time needed for a micro-suite consisting of NTESTS tests each 1378 # sleeping for a second is estimated by 1379 # startup + ntests * (serial_overhead + 1 / njobs) 1380 # 1381 # in absence of major scheduling delays. This leads to side conditions: 1382 # - NTESTS should be high, so the STARTUP time is small compared to the 1383 # test run time, and scheduling delays can even out; it should not be 1384 # too high, to not slow down the testsuite unnecessarily, 1385 # - the number of concurrent jobs NJOBS should not be too low, so the 1386 # race is not lost so easily; it should not be too high, to avoid fork 1387 # failures on tightly limited systems. 4 seems a good compromise 1388 # here, considering that Autotest spawns several other processes. 1389 # - STARTUP is assumed to be the same for parallel and serial runs, so 1390 # the latter can estimate the former. 1391 # - To avoid unportable output from time measurement commands, spawn 1392 # both a parallel and a serial testsuite run; check that the former 1393 # completes before the latter has completed a fraction SERIAL_NTESTS 1394 # of the tests (the serial run is executed in a subdirectory), plus 1395 # some additional time to allow for compensation of SERIAL_OVERHEAD. 1396 # - when adding this time to the serial test execution, an initial delay 1397 # SERIAL_DELAY of the serial test helps to avoid unreliable scheduling 1398 # due to the startup burst of the suites. 1399 1400 dnl total number of tests. 1401 m4_define([AT_PARALLEL_NTESTS], [16]) 1402 dnl number of jobs to run in parallel. 1403 m4_define([AT_PARALLEL_NJOBS], [4]) 1404 dnl number of tests to run serially, as comparison. 1405 m4_define([AT_PARALLEL_SERIAL_NTESTS], 1406 m4_eval(AT_PARALLEL_NTESTS / AT_PARALLEL_NJOBS)) 1407 dnl initial delay of serial run, to compensate for SERIAL_OVERHEAD. 1408 dnl This corresponds to 0.67 s of overhead per test. 1409 m4_define([AT_PARALLEL_SERIAL_DELAY], 1410 m4_eval((AT_PARALLEL_NTESTS - AT_PARALLEL_SERIAL_NTESTS + 1) * 2 / 3)) 1411 1412 1413 AT_CHECK_AT_PREP([micro-suite], 1414 [[AT_INIT([suite to test parallel execution]) 1415 m4_for([count], [1], ]]AT_PARALLEL_NTESTS[[, [], 1416 [AT_SETUP([test number count]) 1417 AT_CHECK([sleep 1]) 1418 AT_CLEANUP 1419 ]) 1420 ]]) 1421 1422 # Even if parallel jobs are not supported, the command line must work. 1423 AT_CHECK([$CONFIG_SHELL ./micro-suite --help | grep " --jobs"], [0], [ignore]) 1424 AT_CHECK([$CONFIG_SHELL ./micro-suite -j2foo], [1], [], [stderr]) 1425 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore]) 1426 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=foo], [1], [], [stderr]) 1427 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore]) 1428 1429 AT_SKIP_PARALLEL_TESTS 1430 1431 # Ensure that all tests run, and lines are not split. 1432 AT_CHECK([$CONFIG_SHELL ./micro-suite -j[]AT_PARALLEL_NJOBS], [], [stdout]) 1433 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS 1434 ]) 1435 # Running one test with -j should produce correctly formatted output: 1436 AT_CHECK([$CONFIG_SHELL ./micro-suite -j 3], [], [stdout]) 1437 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1 1438 ]) 1439 # Specifying more jobs than tests should not hang: 1440 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 3], [], [stdout]) 1441 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1 1442 ]) 1443 # Not even with zero tests: 1444 AT_CHECK([$CONFIG_SHELL ./micro-suite -j -k nomatch], [], [ignore]) 1445 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 -k nomatch], [], [ignore]) 1446 1447 mkdir serial 1448 1449 # Unfortunately, the return value of wait is unreliable, 1450 # so we check that kill fails. 1451 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=[]AT_PARALLEL_NJOBS & ]dnl 1452 [sleep AT_PARALLEL_SERIAL_DELAY && ]dnl 1453 [cd serial && $CONFIG_SHELL ../micro-suite -AT_PARALLEL_SERIAL_NTESTS >/dev/null && ]dnl 1454 [{ kill $! && exit 1; :; }], [], [stdout], [ignore]) 1455 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS 1456 ]) 1457 AT_CHECK([grep 'AT_PARALLEL_NTESTS tests' stdout], [], [ignore]) 1458 1459 AT_CLEANUP 1460 1461 AT_CHECK_AT_TEST([parallel truth], 1462 [AT_CHECK([:], 0, [], [])], 1463 [], [], [], [], [AT_SKIP_PARALLEL_TESTS], 1464 [], [-j]) 1465 1466 AT_CHECK_AT_TEST([parallel fallacy], 1467 [AT_CHECK([false], [], [], [])], 1468 [], [1], [], [ignore], [AT_SKIP_PARALLEL_TESTS], 1469 [AT_CHECK([grep failed micro-suite.log], [], [ignore])], [-j]) 1470 1471 AT_CHECK_AT_TEST([parallel skip], 1472 [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])], 1473 [], [], [], [], [AT_SKIP_PARALLEL_TESTS], 1474 [AT_CHECK([grep skipped micro-suite.log], [], [ignore])], [-j]) 1475 1476 AT_CHECK_AT_TEST([parallel syntax error], 1477 [AT_CHECK([:]) 1478 AT_CLEANUP 1479 AT_SETUP([syntax]) 1480 AT_CHECK([if]) 1481 AT_CLEANUP 1482 AT_SETUP([another test]) 1483 AT_CHECK([:])], 1484 [], [0], [], [], [AT_SKIP_PARALLEL_TESTS], 1485 [dnl Until we can find a way to avoid catastrophic failure (ash) or 1486 dnl lack of failure (zsh), skip the rest of this test on such shells. 1487 echo 'if' > syntax 1488 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in 1489 0|"") exit 77;; 1490 esac'], [0], [ignore], [ignore]) 1491 AT_CHECK([$CONFIG_SHELL ./micro-suite -j], [1], [ignore], [stderr]) 1492 AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])], 1493 [-j2 1 3]) 1494 1495 AT_CHECK_AT_TEST([parallel errexit], 1496 [AT_CHECK([false]) 1497 AT_CLEANUP 1498 AT_SETUP([barrier test]) 1499 AT_CHECK([sleep 4]) 1500 AT_CLEANUP 1501 AT_SETUP([test that should not be run]) 1502 AT_CHECK([:])], 1503 [], [1], [stdout], [stderr], [AT_SKIP_PARALLEL_TESTS], 1504 [AT_CHECK([test -f micro-suite.log], [1]) 1505 touch micro-suite.log # shut up AT_CAPTURE_FILE. 1506 AT_CHECK([grep "should not be run" stdout], [1]) 1507 AT_CHECK([grep "[[12]] .* inhibited subsequent" stderr], [], [ignore])], 1508 [-j2 --errexit]) 1509 1510 1511 AT_SETUP([parallel autotest and signal handling]) 1512 1513 AT_SKIP_PARALLEL_TESTS 1514 1515 # Goals: 1516 # (1) interrupt `./testsuite -jN' 1517 # (2) interrupt `make check TESTSUITEFLAGS=-jN' 1518 # (3) no trailing verbose/trace output 1519 # (4) exit status should be 128+signal 1520 1521 AT_DATA([atlocal], 1522 [[suite_pid=$$ 1523 export suite_pid 1524 ]]) 1525 1526 AT_CHECK_AT_PREP([micro-suite], 1527 [[AT_INIT([suite to test parallel execution]) 1528 AT_SETUP([test number 1]) 1529 AT_CHECK([sleep 2]) 1530 AT_CLEANUP 1531 AT_SETUP([test number 2]) 1532 AT_CHECK([sleep 1]) 1533 AT_CLEANUP 1534 AT_SETUP([test number 3]) 1535 AT_CHECK([sleep 1]) 1536 AT_CLEANUP 1537 AT_SETUP([killer test]) 1538 AT_CHECK([kill -$signal $suite_pid]) 1539 AT_CLEANUP 1540 m4_for([count], [5], [7], [], 1541 [AT_SETUP([test number count]) 1542 AT_CHECK([sleep 1]) 1543 AT_CLEANUP 1544 ]) 1545 ]]) 1546 1547 AT_DATA([Makefile.in], 1548 [[@SET_MAKE@ 1549 SHELL = @SHELL@ 1550 TESTSUITE = ./micro-suite 1551 check: 1552 $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) 1553 .PHONY: check 1554 ]]) 1555 1556 AT_CHECK([$CONFIG_SHELL $abs_top_builddir/config.status --file=Makefile:Makefile.in], 1557 [], [ignore]) 1558 1559 # Test INT and TERM. 1560 for signal in 2 15; do 1561 export signal 1562 AS_VAR_ARITH([expected_status], [128 + $signal]) 1563 1564 # Sequential case. 1565 AT_CHECK([$CONFIG_SHELL ./micro-suite], [$expected_status], 1566 [ignore], [stderr]) 1567 # Both stderr and the log should contain the notification about the signal. 1568 AT_CHECK([grep 'bailing out' stderr], [], [ignore]) 1569 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore]) 1570 # There should be no junk job status output. 1571 AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1]) 1572 1573 # Parallel case. 1574 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=3], [$expected_status], 1575 [ignore], [stderr]) 1576 AT_CHECK([grep 'bailing out' stderr], [], [ignore]) 1577 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore]) 1578 # We'd like to check this here, too, but some shells do not allow to 1579 # turn off job control. 1580 # AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1]) 1581 1582 # Ditto with `make' in the loop. 1583 : "${MAKE=make}" 1584 unset MAKEFLAGS 1585 # Need to eliminate outer TESTSUITEFLAGS here. 1586 # Need to normalize exit status here: some make implementations 1587 # exit 1 (BSD make), some exit 2 (GNU make). 1588 AT_CHECK([$MAKE check TESTSUITEFLAGS=; ]dnl 1589 [case $? in 1|2) exit 1;; *) exit $?;; esac], 1590 [1], [ignore], [stderr]) 1591 AT_CHECK([grep 'bailing out' stderr], [], [ignore]) 1592 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore]) 1593 # Ditto, parallel case. 1594 AT_CHECK([$MAKE check TESTSUITEFLAGS=--jobs=3; ]dnl 1595 [case $? in 1|2) exit 1;; *) exit $?;; esac], 1596 [1], [ignore], [stderr]) 1597 AT_CHECK([grep 'bailing out' stderr], [], [ignore]) 1598 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore]) 1599 done 1600 1601 1602 # Test PIPE. 1603 # The most important part here is that things should not hang, nor 1604 # get out of hand. OTOH, if the shell sets the default handler to 1605 # ignore PIPE (pdksh, dash), there is little we can do about having the 1606 # test run; it's only the output that won't be there. So all we check 1607 # for is that, if test 7 didn't run serially, then it shouldn't be 1608 # run in the parallel case either; the intermediate tests serve as 1609 # parallel barrier. 1610 # Note that stderr may contain "Broken pipe" errors. 1611 AT_CHECK([($CONFIG_SHELL ./micro-suite -d -3 5-; echo $? >status) | sed 5q], 1612 [], [stdout], [stderr]) 1613 AT_CHECK([grep '5.*ok' stdout], [1]) 1614 # Apparently some shells don't get around to creating 'status' any more. 1615 # And ksh93 on FreeBSD uses 256 + 13 instead of 128 + 13 1616 AT_CHECK([test ! -s status || grep 141 status || grep 269 status], 1617 [], [ignore]) 1618 AT_CHECK([if test -f micro-suite.dir/7/micro-suite.log; then ]dnl 1619 [ echo "shell ignores SIGPIPE" > sigpipe-stamp ]dnl 1620 [else :; fi]) 1621 1622 AT_CHECK([$CONFIG_SHELL ./micro-suite -d -3 5- --jobs=2 | sed 5q], [], [stdout], [ignore]) 1623 AT_CHECK([grep '5.*ok' stdout], [1]) 1624 AT_CHECK([test -s sigpipe-stamp || test ! -f micro-suite.dir/7/micro-suite.log], [0]) 1625 1626 AT_CLEANUP 1627 1628 1629 # Avoid running into a regression when mkfifo does not work. 1630 AT_CHECK_AT_TEST([parallel args but non-working mkfifo], 1631 [AT_CHECK([:]) 1632 AT_CLEANUP 1633 AT_SETUP([second test]) 1634 AT_CHECK([:]) 1635 ], 1636 [], [], [stdout], [stderr], 1637 [AT_SKIP_PARALLEL_TESTS 1638 mkdir bin 1639 cat >bin/mkfifo <<\EOF 1640 #! /bin/sh 1641 exit 1 1642 EOF 1643 chmod +x bin/mkfifo 1644 PATH=`pwd`/bin:$PATH 1645 export PATH 1646 ], 1647 [AT_CHECK([grep 'second test' stdout], [], [ignore]) 1648 ], [--jobs]) 1649 1650 1651 # --color 1652 AT_CHECK_AT_TEST([colored test results], 1653 [AT_CHECK([:]) 1654 AT_CLEANUP 1655 AT_SETUP([fail]) 1656 AT_CHECK([exit 1]) 1657 AT_CLEANUP 1658 AT_SETUP([xpass]) 1659 AT_XFAIL_IF([:]) 1660 AT_CHECK([:]) 1661 AT_CLEANUP 1662 AT_SETUP([xfail]) 1663 AT_XFAIL_IF([:]) 1664 AT_CHECK([exit 1]) 1665 AT_CLEANUP 1666 AT_SETUP([skip]) 1667 AT_CHECK([exit 77]) 1668 AT_CLEANUP 1669 AT_SETUP([hardfail]) 1670 AT_XFAIL_IF([:]) 1671 AT_CHECK([exit 99]) 1672 ], [], [], [], [], [], [ 1673 1674 TERM=ansi 1675 export TERM 1676 1677 red=`printf '\033@<:@0;31m'` 1678 grn=`printf '\033@<:@0;32m'` 1679 lgn=`printf '\033@<:@1;32m'` 1680 blu=`printf '\033@<:@1;34m'` 1681 std=`printf '\033@<:@m'` 1682 1683 # Check that grep can parse nonprinting characters. 1684 # BSD 'grep' works from a pipe, but not a seekable file. 1685 # GNU or BSD 'grep -a' works on files, but is not portable. 1686 AT_CHECK([case `echo "$std" | grep .` in #'' restore font-lock 1687 $std) :;; 1688 *) exit 77;; 1689 esac], [], [ignore], [], 1690 [echo "grep can't parse nonprinting characters" >&2]) 1691 1692 if echo 'ab*c' | grep -F 'ab*c' >/dev/null 2>&1; then 1693 FGREP="grep -F" 1694 else 1695 FGREP=fgrep 1696 fi 1697 1698 # No color. 1699 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [stdout], [stderr]) 1700 for color in "$red" "$grn" "$lgn" "$blu"; do 1701 AT_CHECK([cat stdout stderr | $FGREP "$color"], [1]) 1702 done 1703 1704 # Color of test group results. 1705 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always], [1], [stdout], [stderr]) 1706 AT_CHECK([cat stdout | grep " only " | $FGREP "$grn"], [], [ignore]) 1707 AT_CHECK([cat stdout | grep " fail " | $FGREP "$red"], [], [ignore]) 1708 AT_CHECK([cat stdout | grep " xfail " | $FGREP "$lgn"], [], [ignore]) 1709 AT_CHECK([cat stdout | grep " xpass " | $FGREP "$red"], [], [ignore]) 1710 AT_CHECK([cat stdout | grep " skip " | $FGREP "$blu"], [], [ignore]) 1711 AT_CHECK([cat stdout | grep " hardfail " | $FGREP "$red"], [], [ignore]) 1712 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore]) 1713 1714 # The summary is green if all tests were successful, light green if all 1715 # behaved as expected, and red otherwise. 1716 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k skip], 1717 [0], [stdout]) 1718 AT_CHECK([cat stdout | grep 'test.*successful' | $FGREP "$grn"], 1719 [], [ignore]) 1720 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k xfail -k skip], 1721 [0], [stdout]) 1722 AT_CHECK([cat stdout | grep 'as expected' | $FGREP "$lgn"], [], [ignore]) 1723 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k fail], 1724 [1], [ignore], [stderr]) 1725 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore]) 1726 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k xpass], 1727 [1], [ignore], [stderr]) 1728 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore]) 1729 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k hardfail], 1730 [1], [ignore], [stderr]) 1731 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore]) 1732 # Reset color on verbose output. 1733 printf %s\\n "$std" 1734 ], [1]) 1735 1736 1737 ## ------------------- ## 1738 ## srcdir propagation. ## 1739 ## ------------------- ## 1740 1741 AT_SETUP([srcdir propagation]) 1742 1743 mkdir pkg vpath-outside vpath-abs 1744 mkdir pkg/t pkg/vpath-inside 1745 AT_DATA([pkg/a]) 1746 AT_DATA([pkg/t/b]) 1747 1748 AT_DATA([pkg/configure.ac], [[AC_INIT 1749 AC_CONFIG_TESTDIR([t]) 1750 AC_OUTPUT 1751 ]]) 1752 cp "$abs_top_srcdir/build-aux/install-sh" pkg 1753 1754 cd pkg 1755 AT_CHECK_AUTOCONF 1756 cd .. 1757 1758 AT_CHECK_AT_PREP([suite], 1759 [[AT_INIT([suite to check srcdir]) 1760 AT_SETUP([my only test]) 1761 AT_CHECK([test -f "$top_srcdir"/a && test -f "$srcdir"/b]) 1762 AT_CLEANUP 1763 ]], [], [], [], [pkg/t]) 1764 1765 rm -f pkg/t/atconfig 1766 1767 # Build directory totally outside source directory. 1768 cd vpath-outside 1769 AT_CHECK([../pkg/configure $configure_options], [0], [ignore]) 1770 cd t 1771 AT_CHECK([../../pkg/t/suite], [0], [ignore]) 1772 AT_CHECK([../../pkg/t/suite -v], [0], [stdout]) 1773 AT_CHECK([grep '^\.\./\.\./pkg/t/suite.at' stdout], [0], [ignore]) 1774 cd ../.. 1775 1776 # Build directory totally outside source directory (absolute). 1777 my_srcdir=`pwd`/pkg 1778 cd vpath-abs 1779 AT_CHECK(["$my_srcdir"/configure $configure_options], [0], [ignore]) 1780 cd t 1781 AT_CHECK(["$my_srcdir"/t/suite], [0], [ignore]) 1782 AT_CHECK(["$my_srcdir"/t/suite -v], [0], [stdout]) 1783 AT_CHECK([grep '..*/t/suite.at' stdout], [0], [ignore]) 1784 cd ../.. 1785 1786 # Build directory as subdirectory of source directory. 1787 cd pkg/vpath-inside 1788 AT_CHECK([../configure $configure_options], [0], [ignore]) 1789 cd t 1790 AT_CHECK([../../t/suite], [0], [ignore]) 1791 AT_CHECK([../../t/suite -v], [0], [stdout]) 1792 AT_CHECK([grep '^\.\./\.\./t/suite.at' stdout], [0], [ignore]) 1793 cd ../../.. 1794 1795 # Build directory as parent of source directory. 1796 AT_CHECK([pkg/configure $configure_options], [0], [ignore]) 1797 cd t 1798 AT_CHECK([../pkg/t/suite], [0], [ignore]) 1799 AT_CHECK([../pkg/t/suite -v], [0], [stdout]) 1800 AT_CHECK([grep '^\.\./pkg/t/suite.at' stdout], [0], [ignore]) 1801 cd .. 1802 1803 # Build directory as source directory. 1804 cd pkg 1805 AT_CHECK_CONFIGURE 1806 cd t 1807 AT_CHECK([./suite], [0], [ignore]) 1808 AT_CHECK([./suite -v], [0], [stdout]) 1809 AT_CHECK([grep '^\./suite.at' stdout], [0], [ignore]) 1810 cd ../.. 1811 1812 AT_CLEANUP 1813 1814 1815 ## ------------------------------ ## 1816 ## whitespace in absolute testdir ## 1817 ## ------------------------------ ## 1818 1819 AT_SETUP([whitespace in absolute testdir]) 1820 1821 dir='dir with whitespace' 1822 mkdir "$dir" 1823 cd "$dir" 1824 wd=`pwd` 1825 1826 AT_DATA([a]) 1827 AT_CHECK_AT_PREP([suite], 1828 [[AT_INIT([suite to check srcdir]) 1829 AT_SETUP([my only test]) 1830 AT_CHECK([test -f "$top_srcdir"/a]) 1831 AT_CLEANUP 1832 ]]) 1833 AT_CHECK([top_srcdir=$wd ./suite], [0], [ignore]) 1834 AT_CHECK([top_srcdir=$wd ./suite -d], [0], [ignore]) 1835 AT_CHECK([cd suite.dir/1 && ./run top_srcdir="$wd"], [0], [ignore], [ignore]) 1836 AT_CLEANUP 1837 1838 1839 ## ------------------ ## 1840 ## unusual file names ## 1841 ## ------------------ ## 1842 1843 AT_SETUP([unusual file names]) 1844 1845 AT_DATA_AUTOTEST([d@&t (a] nl.at], 1846 [[AT_SETUP([test one]) 1847 m4_pattern_allow([^dnl$]) 1848 AT_CHECK([test "]m4_dquote(AT_LINE)[" = dn[]l.at:3]) 1849 AT_CLEANUP 1850 ]]) 1851 1852 mkdir sub 1853 AT_DATA_AUTOTEST([sub/"two spaces".at], 1854 [[AT_SETUP([test two]) 1855 AT_CHECK([test "]m4_dquote(AT_LINE)[" = "two spaces.at:2"]) 1856 AT_CLEANUP 1857 ]]) 1858 1859 AT_CHECK_AT_PREP([suite], 1860 [[AT_INIT([suite to check included file names]) 1861 m4_include([d][nl.at]) 1862 m4_include([sub/two spaces.at]) 1863 ]]) 1864 AT_CHECK([$CONFIG_SHELL ./suite], [0], [stdout]) 1865 AT_CHECK([grep 'two spaces' suite.log], [1]) 1866 AT_CLEANUP 1867 1868 1869 ## ------------------------- ## 1870 ## Erlang EUnit unit tests. ## 1871 ## ------------------------- ## 1872 1873 AT_SETUP([Erlang Eunit unit tests]) 1874 AT_KEYWORDS([Erlang]) 1875 1876 mkdir s t 1877 AT_DATA([configure.ac], [[AC_INIT 1878 AC_ERLANG_PATH_ERL([no]) 1879 AC_ERLANG_PATH_ERLC([no]) 1880 if test "$ERL" = "no" || test "$ERLC" = "no"; then 1881 HAVE_ERLANG=no 1882 HAVE_EUNIT=no 1883 else 1884 HAVE_ERLANG=yes 1885 AC_ERLANG_CHECK_LIB([eunit], [HAVE_EUNIT=yes], [HAVE_EUNIT=no]) 1886 fi 1887 AC_SUBST([HAVE_ERLANG]) 1888 AC_SUBST([HAVE_EUNIT]) 1889 1890 AC_CONFIG_TESTDIR([t]) 1891 AC_CONFIG_FILES([s/compile], [chmod +x s/compile]) 1892 AC_CONFIG_FILES([erlang.conf]) 1893 AC_OUTPUT 1894 ]]) 1895 1896 # File to pass info back to us 1897 AT_DATA([erlang.conf.in], 1898 [[HAVE_ERLANG=@HAVE_ERLANG@ 1899 HAVE_EUNIT=@HAVE_EUNIT@ 1900 ]]) 1901 1902 # Erlang module to test: 1903 AT_DATA([s/testme.erl], 1904 [[-module(testme). 1905 -export([foo/1]). 1906 foo(1) -> one; 1907 foo(2) -> two; 1908 foo(_) -> other. 1909 ]]) 1910 1911 # Corresponding Eunit unit test module: 1912 AT_DATA([s/testme_tests.erl], 1913 [[-module(testme_tests). 1914 -include_lib("eunit/include/eunit.hrl"). 1915 foo_one_test() -> ?assertEqual(one, testme:foo(1)). 1916 foo_two_test() -> ?assertEqual(two, testme:foo(2)). 1917 foo_other_test() -> ?assertEqual(other, testme:foo(42)). 1918 ]]) 1919 1920 # Compilation script: 1921 AT_DATA([s/compile.in], 1922 [["@ERLC@" -b beam testme.erl testme_tests.erl 1923 ]]) 1924 1925 AT_CHECK_AT_PREP([suite], 1926 [[AT_INIT([suite to check EUnit integration]) 1927 AT_SETUP([my only test]) 1928 AT_CHECK_EUNIT([my_testsuite], [{module, testme}], 1929 [-pa "${abs_top_builddir}/s"]) 1930 AT_CLEANUP 1931 ]], [], [], [], [t]) 1932 1933 AT_CHECK_AUTOCONF 1934 AT_CHECK_CONFIGURE 1935 . ./erlang.conf 1936 1937 AT_CHECK([grep '^ERL='\''.*'\' t/atconfig], [], [ignore]) 1938 AT_CHECK([grep '^ERLC='\''.*'\' t/atconfig], [], [ignore]) 1939 AT_CHECK([grep '^ERLCFLAGS='\''.*'\' t/atconfig], [], [ignore]) 1940 1941 if test "$HAVE_ERLANG" = yes && test "$HAVE_EUNIT" = yes; then 1942 AT_CHECK([cd s && $CONFIG_SHELL ./compile]) 1943 fi 1944 1945 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore]) 1946 1947 if test "$HAVE_EUNIT" = yes; then 1948 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore]) 1949 AT_CHECK([grep skipped t/suite.log], [1], [ignore]) 1950 else 1951 AT_CHECK([grep 1.*skipped t/suite.log], [], [ignore]) 1952 AT_CHECK([grep 0.*successful t/suite.log], [], [ignore]) 1953 fi 1954 1955 AT_CLEANUP 1956