11c3f620cSEnji Cooper#!/bin/sh 21c3f620cSEnji Cooper# 3da5069e1SEnji Cooper# Copyright (c) 2017 Enji Cooper <ngie@FreeBSD.org> 41c3f620cSEnji Cooper# 51c3f620cSEnji Cooper# Redistribution and use in source and binary forms, with or without 61c3f620cSEnji Cooper# modification, are permitted provided that the following conditions 71c3f620cSEnji Cooper# are met: 81c3f620cSEnji Cooper# 1. Redistributions of source code must retain the above copyright 91c3f620cSEnji Cooper# notice, this list of conditions and the following disclaimer. 101c3f620cSEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright 111c3f620cSEnji Cooper# notice, this list of conditions and the following disclaimer in the 121c3f620cSEnji Cooper# documentation and/or other materials provided with the distribution. 131c3f620cSEnji Cooper# 141c3f620cSEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 151c3f620cSEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 161c3f620cSEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 171c3f620cSEnji Cooper# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 181c3f620cSEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 191c3f620cSEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 201c3f620cSEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 211c3f620cSEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 221c3f620cSEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 231c3f620cSEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 241c3f620cSEnji Cooper# POSSIBILITY OF SUCH DAMAGE. 251c3f620cSEnji Cooper# 261c3f620cSEnji Cooper# 271c3f620cSEnji Cooper 281c3f620cSEnji Cooper# 291c3f620cSEnji Cooper# INTRODUCTION 301c3f620cSEnji Cooper# 311c3f620cSEnji Cooper# This TAP test program mimics the structure and contents of its 321c3f620cSEnji Cooper# ATF-based counterpart. It attempts to represent various test cases 331c3f620cSEnji Cooper# in different separate functions and just calls them all from main. 341c3f620cSEnji Cooper# 351c3f620cSEnji Cooper 361c3f620cSEnji Coopertest_num=1 371c3f620cSEnji CooperTEST_COUNT=4 381c3f620cSEnji Cooper 391c3f620cSEnji Cooperresult() 401c3f620cSEnji Cooper{ 411c3f620cSEnji Cooper local result=$1; shift 421c3f620cSEnji Cooper local result_string 431c3f620cSEnji Cooper 441c3f620cSEnji Cooper result_string="$result $test_num" 451c3f620cSEnji Cooper if [ $# -gt 0 ]; then 461c3f620cSEnji Cooper result_string="$result_string - $@" 471c3f620cSEnji Cooper fi 481c3f620cSEnji Cooper echo "$result_string" 491c3f620cSEnji Cooper : $(( test_num += 1 )) 501c3f620cSEnji Cooper} 511c3f620cSEnji Cooper 521c3f620cSEnji Cooper# Auxiliary function to compare two files for equality. 531c3f620cSEnji Cooperverify_copy() { 541c3f620cSEnji Cooper if cmp -s "${1}" "${2}"; then 551c3f620cSEnji Cooper result "ok" 561c3f620cSEnji Cooper else 571c3f620cSEnji Cooper result "not ok" "${1} and ${2} differ, but they should be equal" 581c3f620cSEnji Cooper diff -u "${1}" "${2}" 591c3f620cSEnji Cooper fi 601c3f620cSEnji Cooper} 611c3f620cSEnji Cooper 621c3f620cSEnji Coopersimple_test() { 631c3f620cSEnji Cooper cp "$(dirname "${0}")/file1" . 641c3f620cSEnji Cooper if cp file1 file2; then 651c3f620cSEnji Cooper result "ok" 661c3f620cSEnji Cooper verify_copy file1 file2 671c3f620cSEnji Cooper else 681c3f620cSEnji Cooper result "not ok" "cp failed" 691c3f620cSEnji Cooper result "not ok" "# SKIP" 701c3f620cSEnji Cooper fi 711c3f620cSEnji Cooper} 721c3f620cSEnji Cooper 731c3f620cSEnji Cooperforce_test() { 741c3f620cSEnji Cooper echo 'File 3' >file3 751c3f620cSEnji Cooper chmod 400 file3 761c3f620cSEnji Cooper if cp -f file1 file3; then 771c3f620cSEnji Cooper result "ok" 781c3f620cSEnji Cooper verify_copy file1 file3 791c3f620cSEnji Cooper else 801c3f620cSEnji Cooper result "not ok" "cp -f failed" 811c3f620cSEnji Cooper result "not ok" "# SKIP" 821c3f620cSEnji Cooper fi 831c3f620cSEnji Cooper} 841c3f620cSEnji Cooper 851c3f620cSEnji Cooper# If you have read the cp_test.sh counterpart in the atf/ directory, you 861c3f620cSEnji Cooper# may think that the sequencing of tests below and the exposed behavior 871c3f620cSEnji Cooper# to the user is very similar. But you'd be wrong. 881c3f620cSEnji Cooper# 891c3f620cSEnji Cooper# There are two major differences with this and the ATF version. First off, 901c3f620cSEnji Cooper# the TAP test doesn't isolate simple_test from force_test, whereas the ATF 911c3f620cSEnji Cooper# version does. Secondly, the test script accepts arbitrary command line 921c3f620cSEnji Cooper# inputs. 931c3f620cSEnji Cooperecho "1..$TEST_COUNT" 941c3f620cSEnji Cooper 951c3f620cSEnji Coopersimple_test 961c3f620cSEnji Cooperforce_test 971c3f620cSEnji Cooperexit 0 98