From owner-svn-src-head@freebsd.org Mon Nov 20 22:55:04 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 51303DF7A4E; Mon, 20 Nov 2017 22:55:04 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2079071342; Mon, 20 Nov 2017 22:55:04 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vAKMt3nd014205; Mon, 20 Nov 2017 22:55:03 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vAKMt2nP014201; Mon, 20 Nov 2017 22:55:02 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201711202255.vAKMt2nP014201@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Mon, 20 Nov 2017 22:55:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326039 - in head: etc/mtree usr.bin/head usr.bin/head/tests X-SVN-Group: head X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: in head: etc/mtree usr.bin/head usr.bin/head/tests X-SVN-Commit-Revision: 326039 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Nov 2017 22:55:04 -0000 Author: asomers Date: Mon Nov 20 22:55:02 2017 New Revision: 326039 URL: https://svnweb.freebsd.org/changeset/base/326039 Log: Add ATF tests for head(1) Submitted by: Fred Schlecter Reviewed by: asomers, jilles MFC after: 3 weeks Differential Revision: https://github.com/freebsd/freebsd/pull/127 Added: head/usr.bin/head/tests/ head/usr.bin/head/tests/Makefile (contents, props changed) head/usr.bin/head/tests/head_test.sh (contents, props changed) Modified: head/etc/mtree/BSD.tests.dist head/usr.bin/head/Makefile Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Mon Nov 20 22:42:17 2017 (r326038) +++ head/etc/mtree/BSD.tests.dist Mon Nov 20 22:55:02 2017 (r326039) @@ -660,6 +660,8 @@ .. gzip .. + head + .. hexdump .. ident Modified: head/usr.bin/head/Makefile ============================================================================== --- head/usr.bin/head/Makefile Mon Nov 20 22:42:17 2017 (r326038) +++ head/usr.bin/head/Makefile Mon Nov 20 22:55:02 2017 (r326039) @@ -1,6 +1,11 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD$ +.include + PROG= head + +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests .include Added: head/usr.bin/head/tests/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/head/tests/Makefile Mon Nov 20 22:55:02 2017 (r326039) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +PACKAGE= tests + +ATF_TESTS_SH= head_test + +.include Added: head/usr.bin/head/tests/head_test.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/head/tests/head_test.sh Mon Nov 20 22:55:02 2017 (r326039) @@ -0,0 +1,132 @@ +# Copyright (c) 2017 Fred Schlechter +# 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 AUTHOR 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 AUTHOR 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. +# +# $FreeBSD$ + +atf_test_case empty_file +empty_file_head() { + atf_set "descr" "Test head(1)'s handling of an empty file" +} +empty_file_body() { + touch infile expectfile + head infile > outfile + head < infile > outpipe + atf_check cmp expectfile outfile + atf_check cmp expectfile outpipe +} + +atf_test_case default_no_options +default_no_options_head() { + atf_set "descr" "Test head(1)'s default mode" +} +default_no_options_body() { + #head(1) is supposed to default to 10 lines of output. Verify that it does that. + jot -b test 10 > expectfile + jot -b test 100 > infile + head infile > outfile + atf_check -e empty cmp expectfile outfile +} + +atf_test_case line_count +line_count_head() { + atf_set "descr" "Test head(1)'s -n option" +} +line_count_body() { + jot -b test 100 > outfile + head -n 50 outfile > expectfile + atf_check -o inline:" 50 expectfile\n" wc -l expectfile +} + +atf_test_case byte_count +byte_count_head() { + atf_set "descr" "Test head(1)'s -c option" +} +byte_count_body() { + jot -b test 100 > outfile + head -c 50 outfile > expectfile + atf_check -o inline:" 50 expectfile\n" wc -c expectfile +} + +atf_test_case sparse_file_text_at_beginning +sparse_file_text_at_beginning_head() { + atf_set "descr" "Test head(1)'s handling of a sparse file with text at the beginning of the file" +} +sparse_file_text_at_beginning_body () { + jot -b test 10 > outfile + truncate -s +1K outfile + head -c 512 outfile > expectfile + atf_check -o inline:" 512 expectfile\n" wc -c expectfile +} + +atf_test_case sparse_file_text_at_end +sparse_file_text_at_end_head() { + atf_set "descr" "Test head(1)'s handling of a sparse file with text at the end of the file" +} +sparse_file_text_at_end_body () { + truncate -s +1K infile + echo test >> infile + head -c 4096 < infile > outpipe + atf_check cmp infile outpipe +} + +atf_test_case missing_line_count +missing_line_count_head() { + atf_set "descr" "Test head(1)'s handling of a missing line count arg" +} +missing_line_count_body () { + jot -b test 100 > outfile + atf_check -s not-exit:0 -e not-empty head -n outfile +} + +atf_test_case invalid_line_count +invalid_line_count_head() { + atf_set "descr" "Test head(1)'s handling of an invalid line count arg" +} +invalid_line_count_body () { + jot -b test 100 > outfile + atf_check -s not-exit:0 -e not-empty head -n -10 outfile +} + +atf_test_case read_from_stdin +read_from_stdin_head() { + atf_set "descr" "Test head(1)'s reading of stdin" +} +read_from_stdin_body() { + #head(1) defaults to head -n 10 if no args are given. + jot -b test 10 > outfile + jot -b test 20 | head > expectfile + atf_check cmp outfile expectfile +} + +atf_init_test_cases() { + atf_add_test_case empty_file + atf_add_test_case default_no_options + atf_add_test_case line_count + atf_add_test_case byte_count + atf_add_test_case sparse_file_text_at_beginning + atf_add_test_case sparse_file_text_at_end + atf_add_test_case missing_line_count + atf_add_test_case invalid_line_count + atf_add_test_case read_from_stdin +}