t_make.sh revision 1.4 1 # $NetBSD: t_make.sh,v 1.4 2014/08/23 15:05:41 christos Exp $
2 #
3 # Copyright (c) 2008, 2010, 2014 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 # Executes make and compares the output to a golden file.
29 run_and_check()
30 {
31 local atfname="${1}"; shift
32 local makename="${1}"; shift
33
34 local srcdir="$(atf_get_srcdir)"
35 local in="${srcdir}/d_${name}.mk"
36 local out="${srcdir}/d_${name}.out"
37
38 if [ "x${name}" = "xposix" ]; then
39 # Include $(INPUTFILE) for d_posix.mk, so it can re-run make
40 # on the same makefile. Make sets $(MAKEFILE), but it is
41 # not in POSIX, so it can't be used as such. It can't be
42 # set explicitly because make always sets it itself and
43 # the test shouldn't use anything not provided for by in
44 # the POSIX standard.
45 args="INPUTFILE='${in}'"
46 atf_expect_fail 'PR/49092 [output order]'
47 atf_check -o file:"${out}" -x \
48 "make -kf'${in}' ${args} 2>&1 | sed -e 's,${srcdir}/d_,,'"
49 else
50 local testdir="$(atf_get_srcdir)/unit-tests"
51
52 atf_check -s exit:0 -o ignore -e ignore \
53 make -f "${testdir}/Makefile" "${makename}.out"
54 atf_check -o file:"${testdir}/${makename}.exp" \
55 cat "${makename}.out"
56 fi
57 }
58
59 # Defines a test case for make(1), parsing a given file and comparing the
60 # output to prerecorded results.
61 test_case()
62 {
63 local atfname="${1}"; shift # e.g. foo_bar
64 local makename="${1}"; shift # e.g. foo-bar
65 local descr="${1}"; shift
66
67 atf_test_case "${atfname}"
68 eval "${atfname}_head() { \
69 if [ -n '${descr}' ]; then \
70 atf_set descr '${descr}'; \
71 fi \
72 }"
73 eval "${atfname}_body() { \
74 run_and_check '${atfname}' '${makename}'; \
75 }"
76 }
77
78 atf_init_test_cases()
79 {
80 local filename basename atfname descr
81
82 #exec >/tmp/apb 2>&1
83 #set -x
84 for filename in "$(atf_get_srcdir)"/unit-tests/*.mk ; do
85 basename="${filename##*/}"
86 basename="${basename%.mk}"
87 atfname="$(echo "${basename}" | tr "x-" "x_")"
88 descr='' # XXX
89 test_case "${atfname}" "${basename}" "${descr}"
90 atf_add_test_case "${atfname}"
91 done
92 #set +x
93 }
94