xref: /netbsd-src/tests/usr.bin/make/t_make.sh (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1# $NetBSD: t_make.sh,v 1.1 2012/03/17 16:33:14 jruoho Exp $
2#
3# Copyright (c) 2008, 2010 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.
29run_and_check()
30{
31	local name="${1}"; shift
32
33	local srcdir="$(atf_get_srcdir)"
34	atf_check -o file:"${srcdir}/d_${name}.out" -x \
35	    "make -k -f ${srcdir}/d_${name}.mk 2>&1 | sed -e 's,${srcdir}/d_,,'"
36}
37
38# Defines a test case for make(1), parsing a given file and comparing the
39# output to prerecorded results.
40test_case()
41{
42	local name="${1}"; shift
43	local descr="${1}"; shift
44
45	atf_test_case "${name}"
46	eval "${name}_head() { \
47		atf_set descr '${descr}'; \
48	}"
49	eval "${name}_body() { \
50		run_and_check '${name}'; \
51	}"
52}
53
54test_case comment "Checks comments (PR/17732, PR/30536)"
55test_case cond1 "Checks conditionals (PR/24420)"
56test_case dotwait "Checks .WAIT"
57test_case export "Checks .export of provided variables"
58test_case export_all "Checks .export of all global variables"
59test_case moderrs "Checks correct handling of errors in modifiers usage"
60test_case modmatch "Checks modifier :M"
61test_case modmisc "Checks modifiers specified in variables"
62test_case modorder "Checks modifier :Ox"
63test_case modts "Checks modifier :ts"
64test_case modword "Checks modifier :[]"
65test_case posix "Checks conformance to POSIX"
66test_case qequals "Checks operator ?="
67test_case ternary "Checks ternary modifier"
68test_case varcmd "Checks behavior of command line variable assignments"
69test_case unmatchedvarparen "Checks $ ( ) matches"
70
71atf_init_test_cases()
72{
73	atf_add_test_case comment
74	atf_add_test_case cond1
75	atf_add_test_case dotwait
76	atf_add_test_case export
77	atf_add_test_case export_all
78	atf_add_test_case moderrs
79	atf_add_test_case modmatch
80	atf_add_test_case modmisc
81	atf_add_test_case modorder
82	atf_add_test_case modts
83	atf_add_test_case modword
84	atf_add_test_case posix
85	atf_add_test_case qequals
86	atf_add_test_case ternary
87	atf_add_test_case varcmd
88	atf_add_test_case unmatchedvarparen
89}
90