summaryrefslogtreecommitdiff
path: root/lib/am/check.am
blob: 36adef87ebb70cb38a1281016ae48376a09efd61 (plain)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
## automake - create Makefile.in from Makefile.am
## Copyright (C) 2001, 2003, 2006, 2007, 2008, 2009, 2010, 2011 Free
## Software Foundation, Inc.

## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.

am__tty_colors_dummy = \
  mgn= red= grn= lgn= blu= brg= std=; \
  am__color_tests=no
if %?COLOR%
# If stdout is a non-dumb tty, use colors.  If test -t is not supported,
# then this fails; a conservative approach.  Of course do not redirect
# stdout here, just stderr.
am__tty_colors = \
$(am__tty_colors_dummy); \
test "X$(AM_COLOR_TESTS)" != Xno \
&& test "X$$TERM" != Xdumb \
&& { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \
&& { \
  am__color_tests=yes; \
  red=''; \
  grn=''; \
  lgn=''; \
  blu=''; \
  mgn=''; \
  brg=''; \
  std=''; \
}
else !%?COLOR%
am__tty_colors = $(am__tty_colors_dummy)
endif !%?COLOR%

.PHONY: check-TESTS

if %?PARALLEL_TESTS%

include inst-vars.am

## New parallel test driver.
##
## This code is adapted from check.mk which was originally
## written at EPITA/LRDE, further developed at Gostai, then made
## its way from GNU coreutils to end up, largely rewritten, in
## Automake.
##
## It provides special support for "unit tests", that is to say,
## tests that (once run) no longer need to be re-compiled and
## re-run at each "make check", unless their sources changed.  To
## enable unit-test supports, set RECHECK_LOGS to empty.  In such a
## setting, that heavily relies on correct dependencies, its users may
## prefer to define EXTRA_PROGRAMS instead of check_PROGRAMS, because
## it allows intertwined compilation and execution of the tests.
## Sometimes this helps catching errors earlier (you don't have to
## wait for all the tests to be compiled).
##
## Define TEST_SUITE_LOG to be the name of the global log to create.
## Define TEST_LOGS to the set of logs to include in it.  It defaults
## to $(TESTS), with `.test' and `@EXEEXT@' removed, and `'.log'
## appended.
##
## In addition to the magic "exit 77 means SKIP" feature (which was
## imported from automake), there is a magic "exit 99 means ERROR" feature
## which is useful if you need to issue a hard error no matter whether the
## test is XFAIL or not.  You can disable this feature by setting the
## variable DISABLE_HARD_ERRORS to a nonempty value.

# Restructured Text title and section.
am__rst_title = sed 's/.*/   &   /;h;s/./=/g;p;x;p;g;p;s/.*//'
am__rst_section = sed 'p;s/./=/g;p;g'

# Solaris 10 'make', and several other traditional 'make' implementations,
# pass "-e" to $(SHELL), and POSIX 2008 even requires this.  Work around it
# by disabling -e (using the XSI extension "set +e") if it's set.
am__sh_e_setup = case $$- in *e*) set +e;; esac

# Default flags passed to test drivers.
am__common_driver_flags = \
  --color-tests "$$am__color_tests" \
  --enable-hard-errors "$$am__enable_hard_errors" \
  --expect-failure "$$am__expect_failure"

# To be inserted before the command running the test.  Creates the
# directory for the log if needed.  Stores in $dir the directory
# containing $f, in $tst the test, in $log the log.  Executes the
# developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and
# passes TESTS_ENVIRONMENT.  Set up options for the wrapper that
# will run the test scripts (or their associated LOG_COMPILER, if
# thy have one).
am__check_pre =						\
$(am__sh_e_setup);					\
$(am__vpath_adj_setup) $(am__vpath_adj)			\
$(am__tty_colors);					\
srcdir=$(srcdir); export srcdir;			\
am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;		\
test "x$$am__odir" = x. || $(MKDIR_P) "$$am__odir" || exit $$?;	\
if test -f "./$$f"; then dir=./;			\
elif test -f "$$f"; then dir=;				\
else dir="$(srcdir)/"; fi;				\
tst=$$dir$$f; log='$@'; 				\
if test -n '$(DISABLE_HARD_ERRORS)'; then		\
  am__enable_hard_errors=no; 				\
else							\
  am__enable_hard_errors=yes; 				\
fi; 							\
## The use of $dir below is required to account for VPATH
## rewriting done by Sun make.
case " $(XFAIL_TESTS) " in				\
  *[\ \	]$$f[\ \	]* | *[\ \	]$$dir$$f[\ \	]*) \
    am__expect_failure=yes;;				\
  *)							\
    am__expect_failure=no;;				\
esac; 							\
$(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT)

# The names of the tests, with any registered extension removed.  Or
# equivalently, the names of the test logs, with the `.log' extension
# renoved.  This honours runtime overriding of TESTS and TEST_LOGS.
am__TEST_BASES = $(TEST_LOGS:.log=)

# This can be used instead of $(MAKE) in recipes requiring a recursive call
# to make, but which are not intended to be executed by "make -n".  See the
# GNU make manual for more details.
am__stealth_MAKE = $(MAKE)

# Recover from deleted `.trs' file; this should ensure that
# "rm -f foo.log; make foo.trs" re-run `foo.test', and re-create
# both `foo.log' and `foo.trs'.
.log.trs:
	rm -f $< $@ && $(am__stealth_MAKE) $(AM_MAKEFLAGS) $<

$(TEST_SUITE_LOG): $(TEST_LOGS)
	@$(am__sh_e_setup); $(am__tty_colors); \
	bases='$(am__TEST_BASES)'; \
	ws='[ 	]'; \
## We need to ensures that all the required `.trs' and `.log' files will
## be present and readable.  The direct dependencies of $(TEST_SUITE_LOG)
## only ensure that all the `.log' files exists; they don't ensure that
## the `.log' files are readable, and worse, they don't ensure that the
## `.trs' files even exist.
	redo_bases=`for b in $$bases; do \
	              test -f $$b.trs && test -r $$b.trs \
	                && test -f $$b.log && test -r $$b.log \
		        || echo $$b; \
	            done`; \
	if test -n "$$redo_bases"; then \
## Uh-oh, either some `.log' files were unreadable, or some `.trs' files
## were missing (or unreadable).  We need to re-run the corresponding
## tests in order to re-create them.
	  redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \
	  redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \
	  rm -f $$redo_logs && rm -f $$redo_results \
	    && $(am__stealth_MAKE) $(AM_MAKEFLAGS) $$redo_logs; \
	fi; \
## Sanity check: each unreadable or non-existent test result file should
## has been properly remade at this point, as should the corresponding log
## file.
	st=0; \
	for b in $$redo_bases; do \
	  for e in trs log; do \
	    if test ! -f $$b.$$e || test ! -r $$b.$$e; then \
	      echo "fatal: making $@: failed to create $$b.$$e" >&2; \
	      st=1; \
	    fi; \
	  done; \
	done; \
	test $$st -eq 0 || exit 1; \
## List of test result files.
	results=`for b in $$bases; do echo $$b.trs; done`; \
	test -n "$$results" || results=/dev/null; \
## Prepare data for the test suite summary.  These do not take into account
## unreadable test results, but they'll be appropriately updated later if
## needed.
	all=`  grep "^$$ws*:test-result:"           $$results | wc -l`; \
	pass=` grep "^$$ws*:test-result:$$ws*PASS"  $$results | wc -l`; \
	fail=` grep "^$$ws*:test-result:$$ws*FAIL"  $$results | wc -l`; \
	skip=` grep "^$$ws*:test-result:$$ws*SKIP"  $$results | wc -l`; \
	xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \
	xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \
	error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \
## Whether the testsuite was successful or not.
	if test `expr $$fail + $$xpass + $$error` -eq 0; then \
	  success=true; \
	else \
	  success=false; \
	fi; \
## Make $br a line of exactly 76 `=' characters, that will be used to
## enclose the testsuite summary report when displayed on the console.
	br='==================='; br=$$br$$br$$br$$br; \
## When writing the test summary to the console, we want to color a line
## reporting the count of some result *only* if at least one test
## experienced such a result.  This function is handy in this regard.
	result_count () \
	{ \
	    if test x"$$1" = x"--maybe-color"; then \
	      maybe_colorize=yes; \
	    elif test x"$$1" = x"--no-color"; then \
	      maybe_colorize=no; \
	    else \
	      echo "$@: invalid 'result_count' usage" >&2; exit 4; \
	    fi; \
	    shift; \
	    desc=$$1 count=$$2; \
	    if test $$maybe_colorize = yes && test $$count -gt 0; then \
	      color_start=$$3 color_end=$$std; \
	    else \
	      color_start= color_end=; \
	    fi; \
	    echo "$${color_start}# $$desc $$count$${color_end}"; \
	}; \
## A shell function that creates the testsuite summary.  We need it
## because we have to create *two* summaries, one for test-suite.log,
## and a possibly-colorized one for console output.
	create_testsuite_report () \
	{ \
	  result_count $$1 "TOTAL:" $$all   "$$brg"; \
	  result_count $$1 "PASS: " $$pass  "$$grn"; \
	  result_count $$1 "SKIP: " $$skip  "$$blu"; \
	  result_count $$1 "XFAIL:" $$xfail "$$lgn"; \
	  result_count $$1 "FAIL: " $$fail  "$$red"; \
	  result_count $$1 "XPASS:" $$xpass "$$red"; \
	  result_count $$1 "ERROR:" $$error "$$mgn"; \
	}; \
## Write "global" testsuite log.
	{								\
	  echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" |	\
	    $(am__rst_title);						\
	  create_testsuite_report --no-color;				\
	  echo;								\
	  echo ".. contents:: :depth: 2";				\
	  echo;								\
	  for b in $$bases; do						\
## FIXME: one fork per test -- this is horrendously inefficient!
	    if grep "^$$ws*:copy-in-global-log:$$ws*no$$ws*$$" $$b.trs \
	         >/dev/null; then continue; \
	    fi; \
## Get the declared "global result" of the test.
## FIXME: yet another one fork per test here!
	    glob_res=`sed -n -e "s/$$ws*$$//" \
	                     -e "s/^$$ws*:global-test-result:$$ws*//p" \
		        $$b.trs`; \
## If no global result is explicitly declared, we'll merely mark the
## test as "RUN" in the global test log.
	    test -n "$$glob_res" || glob_res=RUN; \
## Write the name and result of the test as an RST section title.
	    echo "$$glob_res: $$b" | $(am__rst_section); \
## If we should have remade any unreadable `.log', above.
	    if test ! -r $$b.log; then \
	      echo "fatal: making $@: $$b.log is unreadable" >&2; \
	      exit 1; \
	    fi; \
	    cat $$b.log; echo; \
	  done;	\
	} >$(TEST_SUITE_LOG).tmp;					\
	mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG);			\
## Emit the test summary on the console.
	if $$success; then						\
	  col="$$grn";							\
	 else								\
	  col="$$red";							\
	  test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG);		\
	fi;								\
## Multi line coloring is problematic with "less -R", so we really need
## to color each line individually.
	echo "$${col}$$br$${std}"; 					\
	echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}";	\
	echo "$${col}$$br$${std}"; 					\
## This is expected to go to the console, so it might have to be colorized.
	create_testsuite_report --maybe-color;				\
	echo "$$col$$br$$std";						\
	if $$success; then :; else					\
	  echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}";		\
	  if test -n "$(PACKAGE_BUGREPORT)"; then			\
	    echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}";	\
	  fi;								\
	  echo "$$col$$br$$std";					\
	fi;								\
## Be sure to exit with the proper exit status.
	$$success

RECHECK_LOGS = $(TEST_LOGS)

# Run all the tests.
check-TESTS:
## Expand $(RECHECK_LOGS) only once, to avoid exceeding line length limits.
	@list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list
	@list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list
## We always have to remove TEST_SUITE_LOG, to ensure its rule is run
## in any case even in lazy mode: otherwise, if no test needs rerunning,
## or a prior run plus reruns all happen within the same timestamp
## (can happen with a prior `make TESTS=<subset>'),
## then we get no log output.
## OTOH, this means that, in the rule for `$(TEST_SUITE_LOG)', we
## cannot use `$?' to compute the set of lazily rerun tests, lest
## we rely on .PHONY to work portably.
##
## Trailing whitespace in `TESTS = foo.test $(empty)' causes GNU make
## 3.80 to erroneously expand $(TESTS_LOGS) to `foo.log .log'.
## Work around this bug.
	@test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
	@list='$(TEST_LOGS)';						\
	list=`for f in $$list; do					\
	  test .log = $$f || echo $$f;					\
	done | tr '\012\015' '  '`;					\
	$(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$list"

AM_RECURSIVE_TARGETS += check

## -------------- ##
## Produce HTML.  ##
## -------------- ##

.log.html:
	@list='$(RST2HTML) $$RST2HTML rst2html rst2html.py';		\
	for r2h in $$list; do						\
	  if ($$r2h --version) >/dev/null 2>&1; then			\
	    R2H=$$r2h;							\
	  fi;								\
	done;								\
	if test -z "$$R2H"; then					\
	  echo >&2 "cannot find rst2html, cannot create $@";		\
	  exit 2;							\
	fi;								\
	$$R2H $< >$@.tmp
	@mv $@.tmp $@

# Be sure to run check first, and then to convert the result.
# Beware of concurrent executions.  Run "check" not "check-TESTS", as
# check-SCRIPTS and other dependencies are rebuilt by the former only.
# And expect check to fail.
check-html:
	@if $(MAKE) $(AM_MAKEFLAGS) check; then			\
	  rv=0; else rv=$$?;					\
	fi;							\
	$(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_HTML) || exit 4;	\
	exit $$rv

.PHONY: check-html
.MAKE: check-html

AM_RECURSIVE_TARGETS += check-html

## -------------------- ##
## Rechecking failures. ##
## -------------------- ##

## Rerun all tests that experienced an error or an unexpected failure.
recheck recheck-html:
	@ws='[ 	]';							\
	target=`echo $@ | sed 's,^re,,'`;				\
	bases='$(am__TEST_BASES)';					\
	list=`for b in $$bases; do 					\
## Skip tests that haven't been run, but recover gracefully from deleted
## `.trs' files.
	        test ! -f $$b.trs && test ! -f $$b.log && continue;	\
## FIXME: one fork per test -- this is horrendously inefficient!
	        grep "^$$ws*:recheck:$$ws*no$$ws*$$" $$b.trs 		\
		  >/dev/null 2>&1 || echo $$b.log; 			\
	      done | tr '\012\015' '  '`;				\
## This apparently useless munging helps to avoid a nasty bug (a
## segmentation fault!) on Solaris XPG4 make.
	list=`echo "$$list" | sed 's/ *$$//'`;				\
	$(MAKE) $(AM_MAKEFLAGS) $$target AM_MAKEFLAGS='$(AM_MAKEFLAGS) TEST_LOGS="'"$$list"'"'

.PHONY: recheck recheck-html
.MAKE: recheck recheck-html

AM_RECURSIVE_TARGETS += recheck recheck-html

else !%?PARALLEL_TESTS%

check-TESTS: $(TESTS)
	@failed=0; all=0; xfail=0; xpass=0; skip=0; \
	srcdir=$(srcdir); export srcdir; \
## Make sure Solaris VPATH-expands all members of this list, even
## the first and the last one; thus the spaces around $(TESTS)
	list=' $(TESTS) '; \
	$(am__tty_colors); \
	if test -n "$$list"; then \
	  for tst in $$list; do \
	    if test -f ./$$tst; then dir=./; \
## Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
## why we also try `dir='
	    elif test -f $$tst; then dir=; \
	    else dir="$(srcdir)/"; fi; \
	    if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \
## Success
	      all=`expr $$all + 1`; \
	      case " $(XFAIL_TESTS) " in \
	      *[\ \	]$$tst[\ \	]*) \
		xpass=`expr $$xpass + 1`; \
		failed=`expr $$failed + 1`; \
		col=$$red; res=XPASS; \
	      ;; \
	      *) \
		col=$$grn; res=PASS; \
	      ;; \
	      esac; \
	    elif test $$? -ne 77; then \
## Failure
	      all=`expr $$all + 1`; \
	      case " $(XFAIL_TESTS) " in \
	      *[\ \	]$$tst[\ \	]*) \
		xfail=`expr $$xfail + 1`; \
		col=$$lgn; res=XFAIL; \
	      ;; \
	      *) \
		failed=`expr $$failed + 1`; \
		col=$$red; res=FAIL; \
	      ;; \
	      esac; \
	    else \
## Skipped
	      skip=`expr $$skip + 1`; \
	      col=$$blu; res=SKIP; \
	    fi; \
	    echo "$${col}$$res$${std}: $$tst"; \
	  done; \
## Prepare the banner
	  if test "$$all" -eq 1; then \
	    tests="test"; \
	    All=""; \
	  else \
	    tests="tests"; \
	    All="All "; \
	  fi; \
	  if test "$$failed" -eq 0; then \
	    if test "$$xfail" -eq 0; then \
	      banner="$$All$$all $$tests passed"; \
	    else \
	      if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
	      banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
	    fi; \
	  else \
	    if test "$$xpass" -eq 0; then \
	      banner="$$failed of $$all $$tests failed"; \
	    else \
	      if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
	      banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
	    fi; \
	  fi; \
## DASHES should contain the largest line of the banner.
	  dashes="$$banner"; \
	  skipped=""; \
	  if test "$$skip" -ne 0; then \
	    if test "$$skip" -eq 1; then \
	      skipped="($$skip test was not run)"; \
	    else \
	      skipped="($$skip tests were not run)"; \
	    fi; \
	    test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
	      dashes="$$skipped"; \
	  fi; \
	  report=""; \
	  if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
	    report="Please report to $(PACKAGE_BUGREPORT)"; \
	    test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
	      dashes="$$report"; \
	  fi; \
	  dashes=`echo "$$dashes" | sed s/./=/g`; \
	  if test "$$failed" -eq 0; then \
	    col="$$grn"; \
	  else \
	    col="$$red"; \
	  fi; \
## Multi line coloring is problematic with "less -R", so we really need
## to color each line individually.
	  echo "$${col}$$dashes$${std}"; \
	  echo "$${col}$$banner$${std}"; \
	  test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
	  test -z "$$report" || echo "$${col}$$report$${std}"; \
	  echo "$${col}$$dashes$${std}"; \
	  test "$$failed" -eq 0; \
	else :; fi

endif !%?PARALLEL_TESTS%