xref: /freebsd/contrib/netbsd-tests/bin/sh/dotcmd/t_dotcmd.sh (revision c22165b4f1f5d38b681921797a44b3ba8c13b7e0)
1*640235e2SEnji Cooper# $NetBSD: t_dotcmd.sh,v 1.2 2016/03/27 14:57:50 christos Exp $
257718be8SEnji Cooper#
357718be8SEnji Cooper# Copyright (c) 2014 The NetBSD Foundation, Inc.
457718be8SEnji Cooper# All rights reserved.
557718be8SEnji Cooper#
657718be8SEnji Cooper# This code is derived from software contributed to The NetBSD Foundation
757718be8SEnji Cooper# by Jarmo Jaakkola.
857718be8SEnji Cooper#
957718be8SEnji Cooper# Redistribution and use in source and binary forms, with or without
1057718be8SEnji Cooper# modification, are permitted provided that the following conditions
1157718be8SEnji Cooper# are met:
1257718be8SEnji Cooper# 1. Redistributions of source code must retain the above copyright
1357718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer.
1457718be8SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
1557718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
1657718be8SEnji Cooper#    documentation and/or other materials provided with the distribution.
1757718be8SEnji Cooper#
1857718be8SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1957718be8SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2057718be8SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2157718be8SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2257718be8SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2357718be8SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2457718be8SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2557718be8SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2657718be8SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2757718be8SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2857718be8SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
2957718be8SEnji Cooper#
3057718be8SEnji Cooper
3157718be8SEnji Cooper# Test loop and function flow control statements in various scopes in a file
3257718be8SEnji Cooper# sourced by a dotcmd in various scopes.  Basically, dotcmd is like #include
3357718be8SEnji Cooper# in C/C++ so, for example, if the dotcmd is in a loop's body, a break in
3457718be8SEnji Cooper# the sourced file can be used to break out of that loop.
3557718be8SEnji Cooper
36*640235e2SEnji Cooper# Note that the standard does not require this, and allows lexically
37*640235e2SEnji Cooper# scoped interpretation of break/continue (and permits dynamic scope
38*640235e2SEnji Cooper# as an optional extension.)
39*640235e2SEnji Cooper
4057718be8SEnji Coopercmds='return break continue'
4157718be8SEnji Cooperscopes='case compound file for func subshell until while'
4257718be8SEnji Cooper
4357718be8SEnji Coopercase_ids=''
4457718be8SEnji Cooper
4557718be8SEnji Cooperfor dot_scope in ${scopes}
4657718be8SEnji Cooperdo
4757718be8SEnji Cooper    for cmd in ${cmds}
4857718be8SEnji Cooper    do
4957718be8SEnji Cooper        for cmd_scope in ${scopes}
5057718be8SEnji Cooper        do
5157718be8SEnji Cooper            case_id="${dot_scope}_${cmd}_${cmd_scope}"
5257718be8SEnji Cooper	    case_ids="${case_ids} ${case_id}"
5357718be8SEnji Cooper            atf_test_case "${case_id}"
5457718be8SEnji Cooper            eval "
5557718be8SEnji Cooper${case_id}_head()
5657718be8SEnji Cooper{
5757718be8SEnji Cooper    atf_set 'descr' \\
5857718be8SEnji Cooper        'dotcmd in ${dot_scope}, file contains ${cmd} in ${cmd_scope}'
5957718be8SEnji Cooper}
6057718be8SEnji Cooper
6157718be8SEnji Cooper${case_id}_body()
6257718be8SEnji Cooper{
6357718be8SEnji Cooper    srcdir=\$(atf_get_srcdir)
6457718be8SEnji Cooper    # for dotcmd to find the sourced files
6557718be8SEnji Cooper    PATH=\"\${PATH}:\${srcdir}\"
6657718be8SEnji Cooper    atf_check -o file:\"\${srcdir}/out/${case_id}.out\" \\
6757718be8SEnji Cooper            \"\${srcdir}/${case_id}\"
6857718be8SEnji Cooper}
6957718be8SEnji Cooper" # end eval
7057718be8SEnji Cooper        done
7157718be8SEnji Cooper    done
7257718be8SEnji Cooperdone
7357718be8SEnji Cooper
7457718be8SEnji Cooperatf_init_test_cases()
7557718be8SEnji Cooper{
7657718be8SEnji Cooper    for case_id in ${case_ids}
7757718be8SEnji Cooper    do
7857718be8SEnji Cooper        atf_add_test_case "${case_id}"
7957718be8SEnji Cooper    done
8057718be8SEnji Cooper}
81