1272343Sngie# Copyright 2012 Google Inc. 2272343Sngie# All rights reserved. 3272343Sngie# 4272343Sngie# Redistribution and use in source and binary forms, with or without 5272343Sngie# modification, are permitted provided that the following conditions are 6272343Sngie# met: 7272343Sngie# 8272343Sngie# * Redistributions of source code must retain the above copyright 9272343Sngie# notice, this list of conditions and the following disclaimer. 10272343Sngie# * Redistributions in binary form must reproduce the above copyright 11272343Sngie# notice, this list of conditions and the following disclaimer in the 12272343Sngie# documentation and/or other materials provided with the distribution. 13272343Sngie# * Neither the name of Google Inc. nor the names of its contributors 14272343Sngie# may be used to endorse or promote products derived from this software 15272343Sngie# without specific prior written permission. 16272343Sngie# 17272343Sngie# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18272343Sngie# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19272343Sngie# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20272343Sngie# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21272343Sngie# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22272343Sngie# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23272343Sngie# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24272343Sngie# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25272343Sngie# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26272343Sngie# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27272343Sngie# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28272343Sngie 29272343Sngie# Helper function for the various one_* test cases. 30272343Sngie# 31272343Sngie# The first argument must be one of C, CXX or SH, and this indicates the 32272343Sngie# language of the test program. 33272343Sngie# 34272343Sngie# The second argument is the name of the test program, without an extension. 35272343Sngie# The corresponding source file must exist in the current directory. 36272343Sngieone_test() { 37272343Sngie local lang="${1}"; shift 38272343Sngie local name="${1}"; shift 39272343Sngie 40272343Sngie cat >Makefile <<EOF 41272343Sngie.include <bsd.own.mk> 42272343SngieTESTSDIR = \${TESTSBASE}/fake 43272343SngieTESTS_${lang} = ${name} 44272343Sngie.include <bsd.test.mk> 45272343SngieEOF 46272343Sngie 47272343Sngie atf_check -o ignore make 48272343Sngie mkdir -p root/usr/tests/fake 49272343Sngie create_make_conf mk.conf owngrp DESTDIR="$(pwd)/root" 50272343Sngie atf_check -o ignore make install 51272343Sngie 52272343Sngie atf_check -o match:'ident: one_tc' "./root/usr/tests/fake/${name}" -l 53272343Sngie} 54272343Sngie 55272343Sngieatf_test_case one_c 56272343Sngieone_c_body() { 57272343Sngie cat >t_fake.c <<EOF 58272343Sngie#include <atf-c.h> 59272343SngieATF_TC_WITHOUT_HEAD(one_tc); 60272343SngieATF_TC_BODY(one_tc, tc) 61272343Sngie{ 62272343Sngie atf_tc_fail("Failing explicitly"); 63272343Sngie} 64272343Sngie 65272343SngieATF_TP_ADD_TCS(tp) 66272343Sngie{ 67272343Sngie ATF_TP_ADD_TC(tp, one_tc); 68272343Sngie return atf_no_error(); 69272343Sngie} 70272343SngieEOF 71272343Sngie one_test C t_fake 72272343Sngie} 73272343Sngie 74272343Sngieatf_test_case one_cxx 75272343Sngieone_cxx_body() { 76272343Sngie cat >t_fake.cpp <<EOF 77272343Sngie#include <atf-c++.hpp> 78272343SngieATF_TEST_CASE_WITHOUT_HEAD(one_tc); 79272343SngieATF_TEST_CASE_BODY(one_tc) 80272343Sngie{ 81272343Sngie fail("Failing explicitly"); 82272343Sngie} 83272343Sngie 84272343SngieATF_INIT_TEST_CASES(tcs) 85272343Sngie{ 86272343Sngie ATF_ADD_TEST_CASE(tcs, one_tc); 87272343Sngie} 88272343SngieEOF 89272343Sngie one_test CXX t_fake 90272343Sngie} 91272343Sngie 92272343Sngieatf_test_case one_sh 93272343Sngieone_sh_body() { 94272343Sngie cat >t_fake.sh <<EOF 95272343Sngieatf_test_case one_tc 96272343Sngieone_tc_body() { 97272343Sngie atf_fail "Failing explicitly" 98272343Sngie} 99272343Sngie 100272343Sngieatf_init_test_cases() { 101272343Sngie atf_add_test_case one_tc 102272343Sngie} 103272343SngieEOF 104272343Sngie one_test SH t_fake 105272343Sngie} 106272343Sngie 107272343Sngieatf_init_test_cases() { 108272343Sngie atf_add_test_case one_c 109272343Sngie atf_add_test_case one_cxx 110272343Sngie atf_add_test_case one_sh 111272343Sngie} 112