Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/util Do not use awk to generate the test program. Ins...



details:   https://anonhg.NetBSD.org/src/rev/da65dc9a855a
branches:  trunk
changeset: 756280:da65dc9a855a
user:      jmmv <jmmv%NetBSD.org@localhost>
date:      Sat Jul 10 16:16:12 2010 +0000

description:
Do not use awk to generate the test program.  Instead, replace it with some
eval magic (which is less magic than the previous awk stuff).

diffstat:

 tests/util/config/Makefile     |   7 +--
 tests/util/config/t_config.awk |  58 --------------------------
 tests/util/config/t_config.in  |  59 ---------------------------
 tests/util/config/t_config.sh  |  91 ++++++++++++++++++++++++++++++++++++++++++
 tests/util/make/Makefile       |   6 +--
 tests/util/make/t_make.awk     |  58 --------------------------
 tests/util/make/t_make.in      |  53 ------------------------
 tests/util/make/t_make.sh      |  88 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 181 insertions(+), 239 deletions(-)

diffs (truncated from 472 to 300 lines):

diff -r c7ff11351f89 -r da65dc9a855a tests/util/config/Makefile
--- a/tests/util/config/Makefile        Sat Jul 10 15:57:37 2010 +0000
+++ b/tests/util/config/Makefile        Sat Jul 10 16:16:12 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2009/02/13 05:19:51 jmmv Exp $
+# $NetBSD: Makefile,v 1.2 2010/07/10 16:24:12 jmmv Exp $
 
 SUBDIR=                        support
 
@@ -10,11 +10,6 @@
 
 TESTS_SH=              t_config
 
-CLEANFILES+=           t_config.sh
-t_config.sh: t_config.awk t_config.in
-       ${TOOL_AWK} -f ${.CURDIR}/t_config.awk ${.CURDIR}/t_config.in >t_config.sh.tmp
-       mv t_config.sh.tmp t_config.sh
-
 FILESDIR=              ${TESTSDIR}
 FILES=                 d_deffs_redef
 FILES+=                        d_loop
diff -r c7ff11351f89 -r da65dc9a855a tests/util/config/t_config.awk
--- a/tests/util/config/t_config.awk    Sat Jul 10 15:57:37 2010 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-# $NetBSD: t_config.awk,v 1.2 2010/06/04 08:39:41 jmmv Exp $
-#
-# Copyright (c) 2008 The NetBSD Foundation, Inc.
-# All rights reserved.
-#
-# 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.
-#
-
-BEGIN { 
-       FS = ":";
-};
-
-/^tc:/ {
-       printf "atf_test_case %s\n", $3;
-       printf "%s_head()\n", $3;
-       print  "{"
-       printf "        atf_set \"descr\" \"%s\"\n", $4;
-       printf "        atf_set \"use.fs\" \"true\"\n", $4;
-       print  "}"
-       printf "%s_body()\n", $3;
-       print  "{"
-       printf "        h_%s %s\n", $2, d_$3;
-       print  "}"
-       print  ""
-
-       tcs[count++] = $3;
-
-       next
-}
-
-/^tc_list/ {
-       for (i = 0; i < count; i++) {
-               printf("        atf_add_test_case %s\n", tcs[i]);
-       }
-
-       next
-}
-
-{ print }
diff -r c7ff11351f89 -r da65dc9a855a tests/util/config/t_config.in
--- a/tests/util/config/t_config.in     Sat Jul 10 15:57:37 2010 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-# $NetBSD: t_config.in,v 1.1 2009/02/13 05:19:51 jmmv Exp $
-#
-# Copyright (c) 2008 The NetBSD Foundation, Inc.
-# All rights reserved.
-#
-# 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.
-#
-
-h_pass()
-{
-       mkdir compile
-       supportdir="$(atf_get_srcdir)/support"
-       config="$(atf_get_srcdir)/d_$1"
-
-       atf_check -o ignore \
-           config -s "${supportdir}" -b "compile/$1" "${config}"
-}
-
-h_fail()
-{
-       mkdir compile
-       supportdir="$(atf_get_srcdir)/support"
-       config="$(atf_get_srcdir)/d_$1"
-
-       atf_check -o ignore -e ignore -s ne:0 \
-           config -s "${supportdir}" -b "compile/$1" "${config}"
-}
-
-tc:pass:shadow_instance:Checks correct handling of shadowed instances
-tc:pass:loop:Checks correct handling of loops
-tc:pass:loop2:Checks correct handling of devices that can be their own parents
-tc:pass:pseudo_parent:Checks correct handling of children of pseudo devices (PR/32329)
-tc:fail:postponed_orphan:Checks that config catches adding an instance of a child of a negated instance as error
-tc:fail:no_pseudo:Checks that config catches ommited 'pseudo-device' as error (PR/34111)
-tc:fail:deffs_redef:Checks that config doesn't allow a deffs to use the same name as a previous defflag/defparam
-
-atf_init_test_cases()
-{
-tc_list
-}
diff -r c7ff11351f89 -r da65dc9a855a tests/util/config/t_config.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/util/config/t_config.sh     Sat Jul 10 16:16:12 2010 +0000
@@ -0,0 +1,91 @@
+# $NetBSD: t_config.sh,v 1.1 2010/07/10 16:24:12 jmmv Exp $
+#
+# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# 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.
+#
+
+run_and_check_pass()
+{
+       local name="${1}"; shift
+
+       mkdir compile
+       supportdir="$(atf_get_srcdir)/support"
+       config="$(atf_get_srcdir)/d_${name}"
+
+       atf_check -o ignore \
+           config -s "${supportdir}" -b "compile/${name}" "${config}"
+}
+
+run_and_check_fail()
+{
+       local name="${1}"; shift
+
+       mkdir compile
+       supportdir="$(atf_get_srcdir)/support"
+       config="$(atf_get_srcdir)/d_${name}"
+
+       atf_check -o ignore -e ignore -s ne:0 \
+           config -s "${supportdir}" -b "compile/${name}" "${config}"
+}
+
+# Defines a test case for config(1).
+test_case()
+{
+       local name="${1}"; shift
+       local type="${1}"; shift
+       local descr="${*}"
+
+       atf_test_case "${name}"
+       eval "${name}_head() { \
+               atf_set descr \"${descr}\"; \
+               atf_set use.fs true; \
+       }"
+       eval "${name}_body() { \
+               run_and_check_${type} '${name}'; \
+       }"
+}
+
+test_case shadow_instance pass "Checks correct handling of shadowed instances"
+test_case loop pass "Checks correct handling of loops"
+test_case loop2 pass "Checks correct handling of devices that can be their" \
+    "own parents"
+test_case pseudo_parent pass "Checks correct handling of children of pseudo" \
+    "devices (PR/32329)"
+test_case postponed_orphan fail "Checks that config catches adding an" \
+    "instance of a child of a negated instance as error"
+test_case no_pseudo fail "Checks that config catches ommited 'pseudo-device'" \
+    "as error (PR/34111)"
+test_case deffs_redef fail "Checks that config doesn't allow a deffs to use" \
+    "the same name as a previous defflag/defparam"
+
+atf_init_test_cases()
+{
+       atf_add_test_case shadow_instance
+       atf_add_test_case loop
+       atf_add_test_case loop2
+       atf_add_test_case pseudo_parent
+       atf_add_test_case postponed_orphan
+       atf_add_test_case no_pseudo
+       atf_add_test_case deffs_redef
+}
diff -r c7ff11351f89 -r da65dc9a855a tests/util/make/Makefile
--- a/tests/util/make/Makefile  Sat Jul 10 15:57:37 2010 +0000
+++ b/tests/util/make/Makefile  Sat Jul 10 16:16:12 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2009/02/13 05:19:52 jmmv Exp $
+# $NetBSD: Makefile,v 1.2 2010/07/10 16:16:12 jmmv Exp $
 
 NOMAN=                 # defined
 
@@ -8,10 +8,6 @@
 
 TESTS_SH=              t_make
 
-CLEANFILES+=           t_make.sh
-t_make.sh: t_make.awk t_make.in
-       ${TOOL_AWK} -f ${.CURDIR}/t_make.awk ${.CURDIR}/t_make.in > t_make.sh
-
 FILESDIR=              ${TESTSDIR}
 FILES=                 d_comment.mk
 FILES+=                        d_comment.out
diff -r c7ff11351f89 -r da65dc9a855a tests/util/make/t_make.awk
--- a/tests/util/make/t_make.awk        Sat Jul 10 15:57:37 2010 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-# $NetBSD: t_make.awk,v 1.2 2010/06/04 08:39:42 jmmv Exp $
-#
-# Copyright (c) 2008 The NetBSD Foundation, Inc.
-# All rights reserved.
-#
-# 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.
-#
-
-BEGIN { 
-       FS = ":";
-};
-
-/^tc:/ {
-       printf "atf_test_case %s\n", $2;
-       printf "%s_head()\n", $2;
-       print  "{"



Home | Main Index | Thread Index | Old Index