head	1.3;
access;
symbols
	netbsd-11-0-RC4:1.3
	netbsd-11-0-RC3:1.3
	netbsd-11-0-RC2:1.3
	netbsd-11-0-RC1:1.3
	perseant-exfatfs-base-20250801:1.3
	netbsd-11:1.3.0.14
	netbsd-11-base:1.3
	netbsd-10-1-RELEASE:1.3
	perseant-exfatfs-base-20240630:1.3
	perseant-exfatfs:1.3.0.12
	perseant-exfatfs-base:1.3
	netbsd-8-3-RELEASE:1.2
	netbsd-9-4-RELEASE:1.3
	netbsd-10-0-RELEASE:1.3
	netbsd-10-0-RC6:1.3
	netbsd-10-0-RC5:1.3
	netbsd-10-0-RC4:1.3
	netbsd-10-0-RC3:1.3
	netbsd-10-0-RC2:1.3
	netbsd-10-0-RC1:1.3
	netbsd-10:1.3.0.10
	netbsd-10-base:1.3
	netbsd-9-3-RELEASE:1.3
	cjep_sun2x-base1:1.3
	cjep_sun2x:1.3.0.8
	cjep_sun2x-base:1.3
	cjep_staticlib_x-base1:1.3
	netbsd-9-2-RELEASE:1.3
	cjep_staticlib_x:1.3.0.6
	cjep_staticlib_x-base:1.3
	netbsd-9-1-RELEASE:1.3
	phil-wifi-20200421:1.3
	phil-wifi-20200411:1.3
	is-mlppp:1.3.0.4
	is-mlppp-base:1.3
	phil-wifi-20200406:1.3
	netbsd-8-2-RELEASE:1.2
	netbsd-9-0-RELEASE:1.3
	netbsd-9-0-RC2:1.3
	netbsd-9-0-RC1:1.3
	phil-wifi-20191119:1.3
	netbsd-9:1.3.0.2
	netbsd-9-base:1.3
	phil-wifi-20190609:1.3
	netbsd-8-1-RELEASE:1.2
	netbsd-8-1-RC1:1.2
	pgoyette-compat-merge-20190127:1.2.14.1
	pgoyette-compat-20190127:1.3
	pgoyette-compat-20190118:1.3
	pgoyette-compat-1226:1.3
	pgoyette-compat-1126:1.2
	pgoyette-compat-1020:1.2
	pgoyette-compat-0930:1.2
	pgoyette-compat-0906:1.2
	netbsd-7-2-RELEASE:1.1
	pgoyette-compat-0728:1.2
	netbsd-8-0-RELEASE:1.2
	phil-wifi:1.2.0.16
	phil-wifi-base:1.2
	pgoyette-compat-0625:1.2
	netbsd-8-0-RC2:1.2
	pgoyette-compat-0521:1.2
	pgoyette-compat-0502:1.2
	pgoyette-compat-0422:1.2
	netbsd-8-0-RC1:1.2
	pgoyette-compat-0415:1.2
	pgoyette-compat-0407:1.2
	pgoyette-compat-0330:1.2
	pgoyette-compat-0322:1.2
	pgoyette-compat-0315:1.2
	netbsd-7-1-2-RELEASE:1.1
	pgoyette-compat:1.2.0.14
	pgoyette-compat-base:1.2
	netbsd-7-1-1-RELEASE:1.1
	matt-nb8-mediatek:1.2.0.12
	matt-nb8-mediatek-base:1.2
	perseant-stdc-iso10646:1.2.0.10
	perseant-stdc-iso10646-base:1.2
	netbsd-8:1.2.0.8
	netbsd-8-base:1.2
	prg-localcount2-base3:1.2
	prg-localcount2-base2:1.2
	prg-localcount2-base1:1.2
	prg-localcount2:1.2.0.6
	prg-localcount2-base:1.2
	pgoyette-localcount-20170426:1.2
	bouyer-socketcan-base1:1.2
	pgoyette-localcount-20170320:1.2
	netbsd-7-1:1.1.0.12
	netbsd-7-1-RELEASE:1.1
	netbsd-7-1-RC2:1.1
	netbsd-7-nhusb-base-20170116:1.1
	bouyer-socketcan:1.2.0.4
	bouyer-socketcan-base:1.2
	pgoyette-localcount-20170107:1.2
	netbsd-7-1-RC1:1.1
	pgoyette-localcount-20161104:1.2
	netbsd-7-0-2-RELEASE:1.1
	localcount-20160914:1.2
	netbsd-7-nhusb:1.1.0.10
	netbsd-7-nhusb-base:1.1
	pgoyette-localcount-20160806:1.2
	pgoyette-localcount-20160726:1.2
	pgoyette-localcount:1.2.0.2
	pgoyette-localcount-base:1.2
	netbsd-7-0-1-RELEASE:1.1
	netbsd-7-0:1.1.0.8
	netbsd-7-0-RELEASE:1.1
	netbsd-7-0-RC3:1.1
	netbsd-7-0-RC2:1.1
	netbsd-7-0-RC1:1.1
	tls-maxphys-base:1.1
	tls-maxphys:1.1.0.6
	netbsd-7:1.1.0.4
	netbsd-7-base:1.1
	tls-earlyentropy:1.1.0.2
	tls-earlyentropy-base:1.1;
locks; strict;
comment	@# @;


1.3
date	2018.12.04.09.47.25;	author kre;	state Exp;
branches;
next	1.2;
commitid	RfuiCZUuiicVRs2B;

1.2
date	2016.03.27.14.57.50;	author christos;	state Exp;
branches
	1.2.14.1
	1.2.16.1;
next	1.1;
commitid	fuAiBGXyJLEK9i0z;

1.1
date	2014.05.31.14.29.06;	author christos;	state Exp;
branches
	1.1.2.1
	1.1.6.1;
next	;
commitid	yODC4BejrspOoHCx;

1.2.14.1
date	2018.12.26.14.02.08;	author pgoyette;	state Exp;
branches;
next	;
commitid	xUhK8IAeBM1azj5B;

1.2.16.1
date	2019.06.10.22.09.59;	author christos;	state Exp;
branches;
next	;
commitid	jtc8rnCzWiEEHGqB;

1.1.2.1
date	2014.05.31.14.29.06;	author tls;	state dead;
branches;
next	1.1.2.2;
commitid	8ZVdBEH9XlgKCMLx;

1.1.2.2
date	2014.08.10.06.57.02;	author tls;	state Exp;
branches;
next	;
commitid	8ZVdBEH9XlgKCMLx;

1.1.6.1
date	2014.05.31.14.29.06;	author tls;	state dead;
branches;
next	1.1.6.2;
commitid	jTnpym9Qu0o4R1Nx;

1.1.6.2
date	2014.08.20.00.04.45;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;


desc
@@


1.3
log
@
Supply a missing \ ... this missing has meant that these tests
have not been testing everything they should have been testing.
Never mind, they still all succeed.
@
text
@#!/bin/sh
#
# $NetBSD: scoped_command,v 1.2 2016/03/27 14:57:50 christos Exp $
#
# Copyright (c) 2014 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Jarmo Jaakkola.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

: ${TEST_SH:=/bin/sh}

sane_sh()
{
	set -- ${TEST_SH}
	case "$#" in
	(0)   set /bin/sh;;
	(1|2) ;;
	(*)   set "$1";;   # Just ignore options if we cannot make them work
	esac

	case "$1" in
	/*)	TEST_SH="$1${2+ }$2";;
	./*)	TEST_SH="${PWD}${1#.}${2+ }$2";;
	*/*)	TEST_SH="${PWD}/$1${2+ }$2";;
	*)	TEST_SH="$( command -v "$1" )${2+ }$2";;
	esac
}

sane_sh

set -e

# USAGE:
#   scoped_command scope cmd msg var_suffix
#
# Write to stdout a piece of Bourne Shell script with _cmd_ in specific
# _scope_.  The execution of _cmd_ is bracketed by prints of "before _msg_"
# and "after _msg_, return value ${?}".  If the generated script uses
# variables, __var_suffix_ is appended to their names to allow nesting of
# scripts generated this way.
#
# _scope_ should be one of: case, compound, file, for, func, subshell,
# until, while.
# _cmd_ is the command line to execute.  Remember proper quoting!
# _msg_ is text that will be used inside single quotes.
# _var_suffix_ is a syntactically valid identifier name.

# don't rely on command lists (';')
cmd="echo 'before ${3}'
${2}
echo 'after ${3}, return value:' \${?}"

echo "#!${TEST_SH}"

[ 'func' = "${1}" ] && cat <<EOF
func()
{
    echo 'before ${3}'
    \${1}
    echo 'after ${3}'
}

echo 'before function'
func "${2}" "${3}"  # don't rely on 'shift'
echo 'after function'
EOF

[ 'case' = "${1}" ] && cat <<EOF
echo 'before case'
case 'a' in
    a)  ${cmd};;
esac
echo 'after case'
EOF

[ 'file' = "${1}" ] && cat <<EOF
${cmd}
EOF

[ 'while' = "${1}" ] && cat <<EOF
echo 'before while'
cond_${4}='true true false'
while \${cond_${4}}
do
    cond_${4}="\${cond_${4}#* }"
    ${cmd}
done
echo 'after while'
EOF

[ 'until' = "${1}" ] && cat <<EOF
echo 'before until'
cond_${4}='false false true'
until \${cond_${4}}
do
    cond_${4}="\${cond_${4}#* }"
    ${cmd}
done
echo 'after until'
EOF

[ 'for' = "${1}" ] && cat <<EOF
echo 'before for'
for i_${4} in 1 2
do
    ${cmd}
done
echo 'after for'
EOF

[ 'subshell' = "${1}" ] && cat <<EOF
(
    echo 'subshell start'
    ${cmd}
    echo 'subshell end'
)
EOF

[ 'compound' = "${1}" ] && cat <<EOF
{
    echo 'compound start'
    ${cmd};
    echo 'compound end'
}
EOF

exit 0
@


1.2
log
@Allow for testing other than /bin/sh using TEST_SH (from kre@@)
@
text
@d3 1
a3 1
# $NetBSD: scoped_command,v 1.1 2014/05/31 14:29:06 christos Exp $
d74 1
a74 1
echo 'after ${3}, return value:' ${?}"
@


1.2.16.1
log
@Sync with HEAD
@
text
@d3 1
a3 1
# $NetBSD: scoped_command,v 1.3 2018/12/04 09:47:25 kre Exp $
d74 1
a74 1
echo 'after ${3}, return value:' \${?}"
@


1.2.14.1
log
@Sync with HEAD, resolve a few conflicts
@
text
@d3 1
a3 1
# $NetBSD$
d74 1
a74 1
echo 'after ${3}, return value:' \${?}"
@


1.1
log
@PR/48843: Jarmo Jaakkola: Test cses for break/continue/return broken
inside dot commands:

 The test cases are named with the pattern
     dotscope_cmd_cmdscope,
 where dotscope is the scope in which the dot command is and cmdscope
 is the scope where cmd is in the sourced file.
@
text
@d3 1
a3 1
# $NetBSD$
d33 21
d76 1
a76 1
echo "#!/bin/sh"
@


1.1.6.1
log
@file scoped_command was added on branch tls-maxphys on 2014-08-20 00:04:45 +0000
@
text
@d1 129
@


1.1.6.2
log
@Rebase to HEAD as of a few days ago.
@
text
@a0 129
#!/bin/sh
#
# $NetBSD$
#
# Copyright (c) 2014 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Jarmo Jaakkola.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

set -e

# USAGE:
#   scoped_command scope cmd msg var_suffix
#
# Write to stdout a piece of Bourne Shell script with _cmd_ in specific
# _scope_.  The execution of _cmd_ is bracketed by prints of "before _msg_"
# and "after _msg_, return value ${?}".  If the generated script uses
# variables, __var_suffix_ is appended to their names to allow nesting of
# scripts generated this way.
#
# _scope_ should be one of: case, compound, file, for, func, subshell,
# until, while.
# _cmd_ is the command line to execute.  Remember proper quoting!
# _msg_ is text that will be used inside single quotes.
# _var_suffix_ is a syntactically valid identifier name.

# don't rely on command lists (';')
cmd="echo 'before ${3}'
${2}
echo 'after ${3}, return value:' ${?}"

echo "#!/bin/sh"

[ 'func' = "${1}" ] && cat <<EOF
func()
{
    echo 'before ${3}'
    \${1}
    echo 'after ${3}'
}

echo 'before function'
func "${2}" "${3}"  # don't rely on 'shift'
echo 'after function'
EOF

[ 'case' = "${1}" ] && cat <<EOF
echo 'before case'
case 'a' in
    a)  ${cmd};;
esac
echo 'after case'
EOF

[ 'file' = "${1}" ] && cat <<EOF
${cmd}
EOF

[ 'while' = "${1}" ] && cat <<EOF
echo 'before while'
cond_${4}='true true false'
while \${cond_${4}}
do
    cond_${4}="\${cond_${4}#* }"
    ${cmd}
done
echo 'after while'
EOF

[ 'until' = "${1}" ] && cat <<EOF
echo 'before until'
cond_${4}='false false true'
until \${cond_${4}}
do
    cond_${4}="\${cond_${4}#* }"
    ${cmd}
done
echo 'after until'
EOF

[ 'for' = "${1}" ] && cat <<EOF
echo 'before for'
for i_${4} in 1 2
do
    ${cmd}
done
echo 'after for'
EOF

[ 'subshell' = "${1}" ] && cat <<EOF
(
    echo 'subshell start'
    ${cmd}
    echo 'subshell end'
)
EOF

[ 'compound' = "${1}" ] && cat <<EOF
{
    echo 'compound start'
    ${cmd};
    echo 'compound end'
}
EOF

exit 0
@


1.1.2.1
log
@file scoped_command was added on branch tls-earlyentropy on 2014-08-10 06:57:02 +0000
@
text
@d1 129
@


1.1.2.2
log
@Rebase.
@
text
@a0 129
#!/bin/sh
#
# $NetBSD: scoped_command,v 1.1 2014/05/31 14:29:06 christos Exp $
#
# Copyright (c) 2014 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Jarmo Jaakkola.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

set -e

# USAGE:
#   scoped_command scope cmd msg var_suffix
#
# Write to stdout a piece of Bourne Shell script with _cmd_ in specific
# _scope_.  The execution of _cmd_ is bracketed by prints of "before _msg_"
# and "after _msg_, return value ${?}".  If the generated script uses
# variables, __var_suffix_ is appended to their names to allow nesting of
# scripts generated this way.
#
# _scope_ should be one of: case, compound, file, for, func, subshell,
# until, while.
# _cmd_ is the command line to execute.  Remember proper quoting!
# _msg_ is text that will be used inside single quotes.
# _var_suffix_ is a syntactically valid identifier name.

# don't rely on command lists (';')
cmd="echo 'before ${3}'
${2}
echo 'after ${3}, return value:' ${?}"

echo "#!/bin/sh"

[ 'func' = "${1}" ] && cat <<EOF
func()
{
    echo 'before ${3}'
    \${1}
    echo 'after ${3}'
}

echo 'before function'
func "${2}" "${3}"  # don't rely on 'shift'
echo 'after function'
EOF

[ 'case' = "${1}" ] && cat <<EOF
echo 'before case'
case 'a' in
    a)  ${cmd};;
esac
echo 'after case'
EOF

[ 'file' = "${1}" ] && cat <<EOF
${cmd}
EOF

[ 'while' = "${1}" ] && cat <<EOF
echo 'before while'
cond_${4}='true true false'
while \${cond_${4}}
do
    cond_${4}="\${cond_${4}#* }"
    ${cmd}
done
echo 'after while'
EOF

[ 'until' = "${1}" ] && cat <<EOF
echo 'before until'
cond_${4}='false false true'
until \${cond_${4}}
do
    cond_${4}="\${cond_${4}#* }"
    ${cmd}
done
echo 'after until'
EOF

[ 'for' = "${1}" ] && cat <<EOF
echo 'before for'
for i_${4} in 1 2
do
    ${cmd}
done
echo 'after for'
EOF

[ 'subshell' = "${1}" ] && cat <<EOF
(
    echo 'subshell start'
    ${cmd}
    echo 'subshell end'
)
EOF

[ 'compound' = "${1}" ] && cat <<EOF
{
    echo 'compound start'
    ${cmd};
    echo 'compound end'
}
EOF

exit 0
@


