Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.bin/mkdep tests/mkdep: test findcc



details:   https://anonhg.NetBSD.org/src/rev/60205d5399ab
branches:  trunk
changeset: 1022886:60205d5399ab
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Aug 11 20:42:26 2021 +0000

description:
tests/mkdep: test findcc

This function is used by both mkdep and lint.

diffstat:

 distrib/sets/lists/tests/mi     |    4 +-
 tests/usr.bin/mkdep/Makefile    |   12 +++-
 tests/usr.bin/mkdep/h_findcc.c  |   16 +++++
 tests/usr.bin/mkdep/t_findcc.sh |  117 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 146 insertions(+), 3 deletions(-)

diffs (182 lines):

diff -r 5abec1c3d153 -r 60205d5399ab distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Wed Aug 11 11:16:49 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Wed Aug 11 20:42:26 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1109 2021/08/09 20:07:23 rillig Exp $
+# $NetBSD: mi,v 1.1110 2021/08/11 20:42:26 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5972,6 +5972,8 @@
 ./usr/tests/usr.bin/mkdep                              tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/mkdep/Atffile                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/mkdep/Kyuafile                     tests-usr.bin-tests     compattestfile,atf,kyua
+./usr/tests/usr.bin/mkdep/h_findcc                     tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/mkdep/t_findcc                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/mkdep/t_mkdep                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/nbperf                             tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/nbperf/Atffile                     tests-usr.bin-tests     compattestfile,atf
diff -r 5abec1c3d153 -r 60205d5399ab tests/usr.bin/mkdep/Makefile
--- a/tests/usr.bin/mkdep/Makefile      Wed Aug 11 11:16:49 2021 +0000
+++ b/tests/usr.bin/mkdep/Makefile      Wed Aug 11 20:42:26 2021 +0000
@@ -1,9 +1,17 @@
-# $NetBSD: Makefile,v 1.1 2011/05/30 18:14:11 njoly Exp $
+# $NetBSD: Makefile,v 1.2 2021/08/11 20:42:26 rillig Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/usr.bin/mkdep
 
-TESTS_SH=      t_mkdep
+TESTS_SH=      t_findcc
+TESTS_SH+=     t_mkdep
+
+BINDIR=                ${TESTSDIR}
+PROG=          h_findcc
+.PATH:         ${NETBSDSRCDIR}/usr.bin/mkdep
+SRCS=          h_findcc.c findcc.c
+CPPFLAGS+=     -I${NETBSDSRCDIR}/usr.bin/mkdep
+MAN.h_findcc=  # none
 
 .include <bsd.test.mk>
diff -r 5abec1c3d153 -r 60205d5399ab tests/usr.bin/mkdep/h_findcc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/mkdep/h_findcc.c    Wed Aug 11 20:42:26 2021 +0000
@@ -0,0 +1,16 @@
+/*     $NetBSD: h_findcc.c,v 1.1 2021/08/11 20:42:26 rillig Exp $      */
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "findcc.h"
+
+int
+main(int argc, char **argv)
+{
+       const char *cc;
+
+       assert(argc == 2);
+       cc = findcc(argv[1]);
+       printf("%s\n", cc != NULL ? cc : "(not found)");
+}
diff -r 5abec1c3d153 -r 60205d5399ab tests/usr.bin/mkdep/t_findcc.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/mkdep/t_findcc.sh   Wed Aug 11 20:42:26 2021 +0000
@@ -0,0 +1,117 @@
+# $NetBSD: t_findcc.sh,v 1.1 2021/08/11 20:42:26 rillig Exp $
+#
+# Copyright (c) 2021 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Roland Illig.
+#
+# 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.
+#
+
+n='
+'
+
+# A plain program name is searched in the PATH.  Since in this case, the
+# environment is empty, nothing is found.
+#
+atf_test_case base_not_found
+base_not_found_body() {
+       atf_check -o "inline:(not found)$n" \
+           env -i \
+               "$(atf_get_srcdir)"/h_findcc 'echo'
+}
+
+# A plain program name is searched in the PATH and, in this example, it is
+# found in '/bin'.
+#
+atf_test_case base_found
+base_found_body() {
+       atf_check -o "inline:/bin/echo$n" \
+           env -i PATH='/bin:/nonexistent' \
+               "$(atf_get_srcdir)"/h_findcc 'echo'
+}
+
+# The C compiler can be specified as a program with one or more arguments.
+# If the program name is a plain name without any slash, the argument is
+# discarded.
+#
+# XXX: Discarding the arguments feels unintended.
+#
+atf_test_case base_arg_found
+base_arg_found_body() {
+       atf_check -o "inline:/bin/echo$n" \
+           env -i PATH='/bin:/nonexistent' \
+               "$(atf_get_srcdir)"/h_findcc 'echo arg'
+}
+
+
+# If the program name contains a slash, no matter where, the program is not
+# searched in the PATH.  This is the same behavior as in /bin/sh.
+#
+atf_test_case rel_not_found
+rel_not_found_body() {
+       atf_check -o "inline:(not found)$n" \
+           env -i PATH='/' \
+               "$(atf_get_srcdir)"/h_findcc 'bin/echo'
+}
+
+# If the program name contains a slash in the middle, it is interpreted
+# relative to the current directory.
+#
+atf_test_case rel_found
+rel_found_body() {
+       mkdir bin
+       echo '#! /bin/sh' > bin/echo
+       chmod +x bin/echo
+
+       atf_check -o "inline:bin/echo$n" \
+           env -i PATH='/' \
+               "$(atf_get_srcdir)"/h_findcc 'bin/echo'
+}
+
+# If the program name contains a slash in the middle and has additional
+# arguments, the arguments are discarded.
+#
+# XXX: Discarding the arguments feels unintended.
+#
+atf_test_case rel_arg_found
+rel_arg_found_body() {
+       mkdir bin
+       echo '#! /bin/sh' > bin/echo
+       chmod +x bin/echo
+
+       atf_check -o "inline:bin/echo$n" \
+           env -i PATH='/' \
+               "$(atf_get_srcdir)"/h_findcc 'bin/echo arg'
+}
+
+
+atf_init_test_cases() {
+       atf_add_test_case base_not_found
+       atf_add_test_case base_found
+       atf_add_test_case base_arg_found
+
+       atf_add_test_case rel_not_found
+       atf_add_test_case rel_found
+       atf_add_test_case rel_arg_found
+}



Home | Main Index | Thread Index | Old Index