t_test.sh revision 1.1
11.1Sjmmv# Copyright 2012 Google Inc.
21.1Sjmmv# All rights reserved.
31.1Sjmmv#
41.1Sjmmv# Redistribution and use in source and binary forms, with or without
51.1Sjmmv# modification, are permitted provided that the following conditions are
61.1Sjmmv# met:
71.1Sjmmv#
81.1Sjmmv# * Redistributions of source code must retain the above copyright
91.1Sjmmv#   notice, this list of conditions and the following disclaimer.
101.1Sjmmv# * Redistributions in binary form must reproduce the above copyright
111.1Sjmmv#   notice, this list of conditions and the following disclaimer in the
121.1Sjmmv#   documentation and/or other materials provided with the distribution.
131.1Sjmmv# * Neither the name of Google Inc. nor the names of its contributors
141.1Sjmmv#   may be used to endorse or promote products derived from this software
151.1Sjmmv#   without specific prior written permission.
161.1Sjmmv#
171.1Sjmmv# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181.1Sjmmv# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191.1Sjmmv# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
201.1Sjmmv# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211.1Sjmmv# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221.1Sjmmv# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
231.1Sjmmv# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241.1Sjmmv# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251.1Sjmmv# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261.1Sjmmv# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
271.1Sjmmv# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281.1Sjmmv
291.1Sjmmv# Helper function for the various one_* test cases.
301.1Sjmmv#
311.1Sjmmv# The first argument must be one of C, CXX or SH, and this indicates the
321.1Sjmmv# language of the test program.
331.1Sjmmv#
341.1Sjmmv# The second argument is the name of the test program, without an extension.
351.1Sjmmv# The corresponding source file must exist in the current directory.
361.1Sjmmvone_test() {
371.1Sjmmv	local lang="${1}"; shift
381.1Sjmmv	local name="${1}"; shift
391.1Sjmmv
401.1Sjmmv	cat >Makefile <<EOF
411.1Sjmmv.include <bsd.own.mk>
421.1SjmmvTESTSDIR = \${TESTSBASE}/fake
431.1SjmmvTESTS_${lang} = ${name}
441.1Sjmmv.include <bsd.test.mk>
451.1SjmmvEOF
461.1Sjmmv
471.1Sjmmv	atf_check -o ignore make
481.1Sjmmv	mkdir -p root/usr/tests/fake
491.1Sjmmv	create_make_conf mk.conf owngrp DESTDIR="$(pwd)/root"
501.1Sjmmv	atf_check -o ignore make install
511.1Sjmmv
521.1Sjmmv	atf_check -o match:'ident: one_tc' "./root/usr/tests/fake/${name}" -l
531.1Sjmmv}
541.1Sjmmv
551.1Sjmmvatf_test_case one_c
561.1Sjmmvone_c_body() {
571.1Sjmmv	cat >t_fake.c <<EOF
581.1Sjmmv#include <atf-c.h>
591.1SjmmvATF_TC_WITHOUT_HEAD(one_tc);
601.1SjmmvATF_TC_BODY(one_tc, tc)
611.1Sjmmv{
621.1Sjmmv	atf_tc_fail("Failing explicitly");
631.1Sjmmv}
641.1Sjmmv
651.1SjmmvATF_TP_ADD_TCS(tp)
661.1Sjmmv{
671.1Sjmmv	ATF_TP_ADD_TC(tp, one_tc);
681.1Sjmmv	return atf_no_error();
691.1Sjmmv}
701.1SjmmvEOF
711.1Sjmmv	one_test C t_fake
721.1Sjmmv}
731.1Sjmmv
741.1Sjmmvatf_test_case one_cxx
751.1Sjmmvone_cxx_body() {
761.1Sjmmv	cat >t_fake.cpp <<EOF
771.1Sjmmv#include <atf-c++.hpp>
781.1SjmmvATF_TEST_CASE_WITHOUT_HEAD(one_tc);
791.1SjmmvATF_TEST_CASE_BODY(one_tc)
801.1Sjmmv{
811.1Sjmmv	fail("Failing explicitly");
821.1Sjmmv}
831.1Sjmmv
841.1SjmmvATF_INIT_TEST_CASES(tcs)
851.1Sjmmv{
861.1Sjmmv	ATF_ADD_TEST_CASE(tcs, one_tc);
871.1Sjmmv}
881.1SjmmvEOF
891.1Sjmmv	one_test CXX t_fake
901.1Sjmmv}
911.1Sjmmv
921.1Sjmmvatf_test_case one_sh
931.1Sjmmvone_sh_body() {
941.1Sjmmv	cat >t_fake.sh <<EOF
951.1Sjmmvatf_test_case one_tc
961.1Sjmmvone_tc_body() {
971.1Sjmmv	atf_fail "Failing explicitly"
981.1Sjmmv}
991.1Sjmmv
1001.1Sjmmvatf_init_test_cases() {
1011.1Sjmmv	atf_add_test_case one_tc
1021.1Sjmmv}
1031.1SjmmvEOF
1041.1Sjmmv	one_test SH t_fake
1051.1Sjmmv}
1061.1Sjmmv
1071.1Sjmmvatf_init_test_cases() {
1081.1Sjmmv	atf_add_test_case one_c
1091.1Sjmmv	atf_add_test_case one_cxx
1101.1Sjmmv	atf_add_test_case one_sh
1111.1Sjmmv}
112