Module Name: src Committed By: rillig Date: Wed Aug 11 20:42:26 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/mkdep: Makefile Added Files: src/tests/usr.bin/mkdep: h_findcc.c t_findcc.sh Log Message: tests/mkdep: test findcc This function is used by both mkdep and lint. To generate a diff of this commit: cvs rdiff -u -r1.1109 -r1.1110 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/mkdep/Makefile cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/mkdep/h_findcc.c \ src/tests/usr.bin/mkdep/t_findcc.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1109 src/distrib/sets/lists/tests/mi:1.1110 --- src/distrib/sets/lists/tests/mi:1.1109 Mon Aug 9 20:07:23 2021 +++ src/distrib/sets/lists/tests/mi Wed Aug 11 20:42:26 2021 @@ -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 Index: src/tests/usr.bin/mkdep/Makefile diff -u src/tests/usr.bin/mkdep/Makefile:1.1 src/tests/usr.bin/mkdep/Makefile:1.2 --- src/tests/usr.bin/mkdep/Makefile:1.1 Mon May 30 18:14:11 2011 +++ src/tests/usr.bin/mkdep/Makefile Wed Aug 11 20:42:26 2021 @@ -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> Added files: Index: src/tests/usr.bin/mkdep/h_findcc.c diff -u /dev/null src/tests/usr.bin/mkdep/h_findcc.c:1.1 --- /dev/null Wed Aug 11 20:42:26 2021 +++ src/tests/usr.bin/mkdep/h_findcc.c Wed Aug 11 20:42:26 2021 @@ -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)"); +} Index: src/tests/usr.bin/mkdep/t_findcc.sh diff -u /dev/null src/tests/usr.bin/mkdep/t_findcc.sh:1.1 --- /dev/null Wed Aug 11 20:42:26 2021 +++ src/tests/usr.bin/mkdep/t_findcc.sh Wed Aug 11 20:42:26 2021 @@ -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 +}