From owner-svn-src-all@FreeBSD.ORG Mon Nov 25 13:30:07 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B0546FE3; Mon, 25 Nov 2013 13:30:07 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 914002964; Mon, 25 Nov 2013 13:30:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rAPDU7US053283; Mon, 25 Nov 2013 13:30:07 GMT (envelope-from jmmv@svn.freebsd.org) Received: (from jmmv@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id rAPDU7R8053281; Mon, 25 Nov 2013 13:30:07 GMT (envelope-from jmmv@svn.freebsd.org) Message-Id: <201311251330.rAPDU7R8053281@svn.freebsd.org> From: Julio Merino Date: Mon, 25 Nov 2013 13:30:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r258552 - in head/share: examples/tests/tests/plain mk X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Nov 2013 13:30:07 -0000 Author: jmmv Date: Mon Nov 25 13:30:06 2013 New Revision: 258552 URL: http://svnweb.freebsd.org/changeset/base/258552 Log: Generate plain sh test programs from a source file. Instead of assuming that plain sh test programs exist in the source tree in their final form and are marked as executable, generate them from a list of sources. By default, just assume that the source file for a program P is P.sh but allow the caller to customize the inputs. Similarly, also allow the caller to apply sed(1) replacements on the output. These will both be useful in hooking existing test code from tools/regression/ into the test suite. Approved by: rpaulo (mentor) Added: - copied unchanged from r258526, head/share/examples/tests/tests/plain/cp_test Directory Properties: head/share/examples/tests/tests/plain/cp_test.sh (props changed) Deleted: head/share/examples/tests/tests/plain/cp_test Modified: head/share/mk/plain.test.mk Copied: head/share/examples/tests/tests/plain/cp_test.sh (from r258526, head/share/examples/tests/tests/plain/cp_test) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/share/examples/tests/tests/plain/cp_test.sh Mon Nov 25 13:30:06 2013 (r258552, copy of r258526, head/share/examples/tests/tests/plain/cp_test) @@ -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 Modified: head/share/mk/plain.test.mk ============================================================================== --- head/share/mk/plain.test.mk Mon Nov 25 13:28:40 2013 (r258551) +++ head/share/mk/plain.test.mk Mon Nov 25 13:30:06 2013 (r258552) @@ -46,6 +46,16 @@ _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