Index: head/share/examples/tests/tests/plain/cp_test =================================================================== --- head/share/examples/tests/tests/plain/cp_test (revision 258551) +++ head/share/examples/tests/tests/plain/cp_test (nonexistent) @@ -1,84 +0,0 @@ -# $FreeBSD$ -# -# Copyright 2013 Google 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: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * 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. -# * Neither the name of Google Inc. nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT -# OWNER 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. - -# -# INTRODUCTION -# -# This plain test program mimics the structure and contents of its -# ATF-based counterpart. It attempts to represent various test cases -# in different separate functions and just calls them all from main. -# -# In reality, plain test programs can be much simpler. All they have -# to do is return 0 on success and non-0 otherwise. -# - -set -e - -# Prints an error message and exits. -err() { - echo "${@}" 1>&2 - exit 1 -} - -# Auxiliary function to compare two files for equality. -verify_copy() { - if ! cmp -s "${1}" "${2}"; then - diff -u "${1}" "${2}" - err "${1} and ${2} differ, but they should be equal" - fi -} - -simple_test() { - echo 'File 1' >file1 - cp file1 file2 || err "cp failed" - verify_copy file1 file2 -} - -force_test() { - echo 'File 1' >file1 - echo 'File 2' >file2 - chmod 400 file2 - cp -f file1 file2 || err "cp failed" - verify_copy file1 file2 -} - -# If you have read the cp_test.sh counterpart in the atf/ directory, you -# may think that the sequencing of tests below and the exposed behavior -# to the user is very similar. But you'd be wrong. -# -# There are two major differences with this and the ATF version. The -# first is that the code below has no provisions to detect failures in -# one test and continue running the other tests: the first failure -# causes the whole test program to exit. The second is that this -# particular "main" has no arguments: without ATF, all test programs may -# expose a different command-line interface, and this is an issue for -# consistency purposes. -simple_test -force_test Property changes on: head/share/examples/tests/tests/plain/cp_test ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:executable ## -1 +0,0 ## -* \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/share/examples/tests/tests/plain/cp_test.sh =================================================================== --- head/share/examples/tests/tests/plain/cp_test.sh (nonexistent) +++ head/share/examples/tests/tests/plain/cp_test.sh (revision 258552) @@ -0,0 +1,84 @@ +# $FreeBSD$ +# +# Copyright 2013 Google 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: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * 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. +# * Neither the name of Google Inc. nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT +# OWNER 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. + +# +# INTRODUCTION +# +# This plain test program mimics the structure and contents of its +# ATF-based counterpart. It attempts to represent various test cases +# in different separate functions and just calls them all from main. +# +# In reality, plain test programs can be much simpler. All they have +# to do is return 0 on success and non-0 otherwise. +# + +set -e + +# Prints an error message and exits. +err() { + echo "${@}" 1>&2 + exit 1 +} + +# Auxiliary function to compare two files for equality. +verify_copy() { + if ! cmp -s "${1}" "${2}"; then + diff -u "${1}" "${2}" + err "${1} and ${2} differ, but they should be equal" + fi +} + +simple_test() { + echo 'File 1' >file1 + cp file1 file2 || err "cp failed" + verify_copy file1 file2 +} + +force_test() { + echo 'File 1' >file1 + echo 'File 2' >file2 + chmod 400 file2 + cp -f file1 file2 || err "cp failed" + verify_copy file1 file2 +} + +# If you have read the cp_test.sh counterpart in the atf/ directory, you +# may think that the sequencing of tests below and the exposed behavior +# to the user is very similar. But you'd be wrong. +# +# There are two major differences with this and the ATF version. The +# first is that the code below has no provisions to detect failures in +# one test and continue running the other tests: the first failure +# causes the whole test program to exit. The second is that this +# particular "main" has no arguments: without ATF, all test programs may +# expose a different command-line interface, and this is an issue for +# consistency purposes. +simple_test +force_test Property changes on: head/share/examples/tests/tests/plain/cp_test.sh ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/share/mk/plain.test.mk =================================================================== --- head/share/mk/plain.test.mk (revision 258551) +++ head/share/mk/plain.test.mk (revision 258552) @@ -1,52 +1,62 @@ # $FreeBSD$ # # Logic to build and install plain test programs. A plain test programs it not # supposed to use any specific testing framework: all it does is run some code # and report the test's pass or fail status via a 0 or 1 exit code. .include # List of C, C++ and shell test programs to build. # # Programs listed here are built according to the semantics of bsd.prog.mk for # PROGS, PROGS_CXX and SCRIPTS, respectively. # # Test programs registered in this manner are set to be installed into TESTSDIR # (which should be overriden by the Makefile) and are not required to provide a # manpage. PLAIN_TESTS_C?= PLAIN_TESTS_CXX?= PLAIN_TESTS_SH?= .if !empty(PLAIN_TESTS_C) PROGS+= ${PLAIN_TESTS_C} _TESTS+= ${PLAIN_TESTS_C} .for _T in ${PLAIN_TESTS_C} BINDIR.${_T}= ${TESTSDIR} MAN.${_T}?= # empty SRCS.${_T}?= ${_T}.c TEST_INTERFACE.${_T}= plain .endfor .endif .if !empty(PLAIN_TESTS_CXX) PROGS_CXX+= ${PLAIN_TESTS_CXX} _TESTS+= ${PLAIN_TESTS_CXX} .for _T in ${PLAIN_TESTS_CXX} BINDIR.${_T}= ${TESTSDIR} MAN.${_T}?= # empty SRCS.${_T}?= ${_T}.cc TEST_INTERFACE.${_T}= plain .endfor .endif .if !empty(PLAIN_TESTS_SH) SCRIPTS+= ${PLAIN_TESTS_SH} _TESTS+= ${PLAIN_TESTS_SH} .for _T in ${PLAIN_TESTS_SH} SCRIPTSDIR_${_T}= ${TESTSDIR} TEST_INTERFACE.${_T}= plain +CLEANFILES+= ${_T} ${_T}.tmp +# TODO(jmmv): It seems to me that this SED and SRC functionality should +# exist in bsd.prog.mk along the support for SCRIPTS. Move it there if +# this proves to be useful within the tests. +PLAIN_TESTS_SH_SED_${_T}?= # empty +PLAIN_TESTS_SH_SRC_${_T}?= ${_T}.sh +${_T}: ${PLAIN_TESTS_SH_SRC_${_T}} + cat ${.ALLSRC} | sed ${PLAIN_TESTS_SH_SED_${_T}} >${.TARGET}.tmp + chmod +x ${.TARGET}.tmp + mv ${.TARGET}.tmp ${.TARGET} .endfor .endif .include