1*0a6a1f1dSLionel Sambuc# $NetBSD: t_make.sh,v 1.7 2015/01/27 12:57:14 martin Exp $ 211be35a1SLionel Sambuc# 3*0a6a1f1dSLionel Sambuc# Copyright (c) 2008, 2010, 2014 The NetBSD Foundation, Inc. 411be35a1SLionel Sambuc# All rights reserved. 511be35a1SLionel Sambuc# 611be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 711be35a1SLionel Sambuc# modification, are permitted provided that the following conditions 811be35a1SLionel Sambuc# are met: 911be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 1011be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 1111be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 1211be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 1311be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 1411be35a1SLionel Sambuc# 1511be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1611be35a1SLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1711be35a1SLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1811be35a1SLionel Sambuc# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1911be35a1SLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2011be35a1SLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2111be35a1SLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2211be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2311be35a1SLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2411be35a1SLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2511be35a1SLionel Sambuc# POSSIBILITY OF SUCH DAMAGE. 2611be35a1SLionel Sambuc# 2711be35a1SLionel Sambuc 2811be35a1SLionel Sambuc# Executes make and compares the output to a golden file. 2911be35a1SLionel Sambucrun_and_check() 3011be35a1SLionel Sambuc{ 31*0a6a1f1dSLionel Sambuc local atfname="${1}"; shift 32*0a6a1f1dSLionel Sambuc local makename="${1}"; shift 33*0a6a1f1dSLionel Sambuc 34*0a6a1f1dSLionel Sambuc # these tests fail since the backout of the patch in PR 35*0a6a1f1dSLionel Sambuc # 49085 - adjust for more concrete PR if there is one 36*0a6a1f1dSLionel Sambuc case ${makename} in 37*0a6a1f1dSLionel Sambuc escape) atf_expect_fail "see PR toolchain/49085";; 38*0a6a1f1dSLionel Sambuc impsrc) atf_expect_fail "see PR toolchain/49085";; 39*0a6a1f1dSLionel Sambuc phony*) atf_expect_fail "see PR toolchain/49085";; 40*0a6a1f1dSLionel Sambuc posix1) atf_expect_fail "see PR toolchain/49085";; 41*0a6a1f1dSLionel Sambuc suffixes) atf_expect_fail "see PR toolchain/49085" 42*0a6a1f1dSLionel Sambuc atf_fail "this uses up all memory and then fails";; 43*0a6a1f1dSLionel Sambuc esac 4411be35a1SLionel Sambuc 4511be35a1SLionel Sambuc local srcdir="$(atf_get_srcdir)" 46*0a6a1f1dSLionel Sambuc 47*0a6a1f1dSLionel Sambuc local testdir="$(atf_get_srcdir)/unit-tests" 48*0a6a1f1dSLionel Sambuc 49*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore -e ignore \ 50*0a6a1f1dSLionel Sambuc make -f "${testdir}/Makefile" "${makename}.out" 51*0a6a1f1dSLionel Sambuc atf_check -o file:"${testdir}/${makename}.exp" cat "${makename}.out" 5211be35a1SLionel Sambuc} 5311be35a1SLionel Sambuc 5411be35a1SLionel Sambuc# Defines a test case for make(1), parsing a given file and comparing the 5511be35a1SLionel Sambuc# output to prerecorded results. 5611be35a1SLionel Sambuctest_case() 5711be35a1SLionel Sambuc{ 58*0a6a1f1dSLionel Sambuc local atfname="${1}"; shift # e.g. foo_bar 59*0a6a1f1dSLionel Sambuc local makename="${1}"; shift # e.g. foo-bar 6011be35a1SLionel Sambuc local descr="${1}"; shift 6111be35a1SLionel Sambuc 62*0a6a1f1dSLionel Sambuc atf_test_case "${atfname}" 63*0a6a1f1dSLionel Sambuc eval "${atfname}_head() { \ 64*0a6a1f1dSLionel Sambuc if [ -n '${descr}' ]; then \ 6511be35a1SLionel Sambuc atf_set descr '${descr}'; \ 66*0a6a1f1dSLionel Sambuc fi \ 6711be35a1SLionel Sambuc }" 68*0a6a1f1dSLionel Sambuc eval "${atfname}_body() { \ 69*0a6a1f1dSLionel Sambuc run_and_check '${atfname}' '${makename}'; \ 7011be35a1SLionel Sambuc }" 7111be35a1SLionel Sambuc} 7211be35a1SLionel Sambuc 7311be35a1SLionel Sambucatf_init_test_cases() 7411be35a1SLionel Sambuc{ 75*0a6a1f1dSLionel Sambuc local filename basename atfname descr 76*0a6a1f1dSLionel Sambuc 77*0a6a1f1dSLionel Sambuc for filename in "$(atf_get_srcdir)"/unit-tests/*.mk ; do 78*0a6a1f1dSLionel Sambuc basename="${filename##*/}" 79*0a6a1f1dSLionel Sambuc basename="${basename%.mk}" 80*0a6a1f1dSLionel Sambuc atfname="$(echo "${basename}" | tr "x-" "x_")" 81*0a6a1f1dSLionel Sambuc descr='' # XXX 82*0a6a1f1dSLionel Sambuc test_case "${atfname}" "${basename}" "${descr}" 83*0a6a1f1dSLionel Sambuc atf_add_test_case "${atfname}" 84*0a6a1f1dSLionel Sambuc done 8511be35a1SLionel Sambuc} 86