14d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 2809a8352SAlan Somers# 3cdb7a6fcSAlan Somers# Copyright (c) 2016 Alan Somers 4cdb7a6fcSAlan Somers# 5cdb7a6fcSAlan Somers# Redistribution and use in source and binary forms, with or without 6cdb7a6fcSAlan Somers# modification, are permitted provided that the following conditions 7cdb7a6fcSAlan Somers# are met: 8cdb7a6fcSAlan Somers# 1. Redistributions of source code must retain the above copyright 9cdb7a6fcSAlan Somers# notice, this list of conditions and the following disclaimer. 10cdb7a6fcSAlan Somers# 2. Redistributions in binary form must reproduce the above copyright 11cdb7a6fcSAlan Somers# notice, this list of conditions and the following disclaimer in the 12cdb7a6fcSAlan Somers# documentation and/or other materials provided with the distribution. 13cdb7a6fcSAlan Somers# 14cdb7a6fcSAlan Somers# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15cdb7a6fcSAlan Somers# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16cdb7a6fcSAlan Somers# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17cdb7a6fcSAlan Somers# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18cdb7a6fcSAlan Somers# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19cdb7a6fcSAlan Somers# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20cdb7a6fcSAlan Somers# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21cdb7a6fcSAlan Somers# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22cdb7a6fcSAlan Somers# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23cdb7a6fcSAlan Somers# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24cdb7a6fcSAlan Somers# SUCH DAMAGE. 25cdb7a6fcSAlan Somers# 26cdb7a6fcSAlan Somers 27cdb7a6fcSAlan Somersatf_test_case empty_r 28cdb7a6fcSAlan Somersempty_r_head() 29cdb7a6fcSAlan Somers{ 30cdb7a6fcSAlan Somers atf_set "descr" "Reverse an empty file" 31cdb7a6fcSAlan Somers} 32cdb7a6fcSAlan Somersempty_r_body() 33cdb7a6fcSAlan Somers{ 34cdb7a6fcSAlan Somers touch infile expectfile 35cdb7a6fcSAlan Somers tail -r infile > outfile 36cdb7a6fcSAlan Somers tail -r < infile > outpipe 37cdb7a6fcSAlan Somers atf_check cmp expectfile outfile 38cdb7a6fcSAlan Somers atf_check cmp expectfile outpipe 39cdb7a6fcSAlan Somers} 40cdb7a6fcSAlan Somers 41cdb7a6fcSAlan Somersatf_test_case file_r 42cdb7a6fcSAlan Somersfile_r_head() 43cdb7a6fcSAlan Somers{ 44cdb7a6fcSAlan Somers atf_set "descr" "Reverse a file" 45cdb7a6fcSAlan Somers} 46cdb7a6fcSAlan Somersfile_r_body() 47cdb7a6fcSAlan Somers{ 48cdb7a6fcSAlan Somers cat > infile <<HERE 49cdb7a6fcSAlan SomersThis is the first line 50cdb7a6fcSAlan SomersThis is the second line 51cdb7a6fcSAlan SomersThis is the third line 52cdb7a6fcSAlan SomersHERE 53cdb7a6fcSAlan Somers cat > expectfile << HERE 54cdb7a6fcSAlan SomersThis is the third line 55cdb7a6fcSAlan SomersThis is the second line 56cdb7a6fcSAlan SomersThis is the first line 57cdb7a6fcSAlan SomersHERE 58cdb7a6fcSAlan Somers tail -r infile > outfile 59cdb7a6fcSAlan Somers tail -r < infile > outpipe 60cdb7a6fcSAlan Somers atf_check cmp expectfile outfile 61cdb7a6fcSAlan Somers atf_check cmp expectfile outpipe 62cdb7a6fcSAlan Somers} 63cdb7a6fcSAlan Somers 64cdb7a6fcSAlan Somersatf_test_case file_rn2 65cdb7a6fcSAlan Somersfile_rn2_head() 66cdb7a6fcSAlan Somers{ 67cdb7a6fcSAlan Somers atf_set "descr" "Reverse the last two lines of a file" 68cdb7a6fcSAlan Somers} 69cdb7a6fcSAlan Somersfile_rn2_body() 70cdb7a6fcSAlan Somers{ 71cdb7a6fcSAlan Somers cat > infile <<HERE 72cdb7a6fcSAlan SomersThis is the first line 73cdb7a6fcSAlan SomersThis is the second line 74cdb7a6fcSAlan SomersThis is the third line 75cdb7a6fcSAlan SomersHERE 76cdb7a6fcSAlan Somers cat > expectfile << HERE 77cdb7a6fcSAlan SomersThis is the third line 78cdb7a6fcSAlan SomersThis is the second line 79cdb7a6fcSAlan SomersHERE 80cdb7a6fcSAlan Somers tail -rn2 infile > outfile 81cdb7a6fcSAlan Somers tail -rn2 < infile > outpipe 82cdb7a6fcSAlan Somers atf_check cmp expectfile outfile 83cdb7a6fcSAlan Somers atf_check cmp expectfile outpipe 84cdb7a6fcSAlan Somers} 85cdb7a6fcSAlan Somers 86d23662ecSAlan Somers# Regression test for PR 222671 87d23662ecSAlan Somers# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222671 88d23662ecSAlan Somersatf_test_case pipe_leading_newline_r 89d23662ecSAlan Somerspipe_leading_newline_r_head() 90d23662ecSAlan Somers{ 91d23662ecSAlan Somers atf_set "descr" "Reverse a pipe whose first character is a newline" 92d23662ecSAlan Somers} 93d23662ecSAlan Somerspipe_leading_newline_r_body() 94d23662ecSAlan Somers{ 95d23662ecSAlan Somers cat > expectfile << HERE 96d23662ecSAlan Somers3 97d23662ecSAlan Somers2 98d23662ecSAlan Somers1 99d23662ecSAlan Somers 100d23662ecSAlan SomersHERE 101d23662ecSAlan Somers printf '\n1\n2\n3\n' | tail -r > outfile 102d23662ecSAlan Somers printf '\n1\n2\n3\n' | tail -r > outpipe 103d23662ecSAlan Somers atf_check cmp expectfile outfile 104d23662ecSAlan Somers atf_check cmp expectfile outpipe 105d23662ecSAlan Somers} 106d23662ecSAlan Somers 107d23662ecSAlan Somersatf_test_case file_rc28 108d23662ecSAlan Somersfile_rc28_head() 109d23662ecSAlan Somers{ 110d23662ecSAlan Somers atf_set "descr" "Reverse a file and display the last 28 characters" 111d23662ecSAlan Somers} 112d23662ecSAlan Somersfile_rc28_body() 113d23662ecSAlan Somers{ 114d23662ecSAlan Somers cat > infile <<HERE 115d23662ecSAlan SomersThis is the first line 116d23662ecSAlan SomersThis is the second line 117d23662ecSAlan SomersThis is the third line 118d23662ecSAlan SomersHERE 119d23662ecSAlan Somers cat > expectfile << HERE 120d23662ecSAlan SomersThis is the third line 121d23662ecSAlan Somersline 122d23662ecSAlan SomersHERE 123d23662ecSAlan Somers tail -rc28 infile > outfile 124d23662ecSAlan Somers tail -rc28 < infile > outpipe 125d23662ecSAlan Somers atf_check cmp expectfile outfile 126d23662ecSAlan Somers atf_check cmp expectfile outpipe 127d23662ecSAlan Somers} 128d23662ecSAlan Somers 129cdb7a6fcSAlan Somersatf_test_case file_rc28 130cdb7a6fcSAlan Somersfile_rc28_head() 131cdb7a6fcSAlan Somers{ 132cdb7a6fcSAlan Somers atf_set "descr" "Reverse a file and display the last 28 characters" 133cdb7a6fcSAlan Somers} 134cdb7a6fcSAlan Somersfile_rc28_body() 135cdb7a6fcSAlan Somers{ 136cdb7a6fcSAlan Somers cat > infile <<HERE 137cdb7a6fcSAlan SomersThis is the first line 138cdb7a6fcSAlan SomersThis is the second line 139cdb7a6fcSAlan SomersThis is the third line 140cdb7a6fcSAlan SomersHERE 141cdb7a6fcSAlan Somers cat > expectfile << HERE 142cdb7a6fcSAlan SomersThis is the third line 143cdb7a6fcSAlan Somersline 144cdb7a6fcSAlan SomersHERE 145cdb7a6fcSAlan Somers tail -rc28 infile > outfile 146cdb7a6fcSAlan Somers tail -rc28 < infile > outpipe 147cdb7a6fcSAlan Somers atf_check cmp expectfile outfile 148cdb7a6fcSAlan Somers atf_check cmp expectfile outpipe 149cdb7a6fcSAlan Somers} 150cdb7a6fcSAlan Somers 151cdb7a6fcSAlan Somersatf_test_case longfile_r 152cdb7a6fcSAlan Somerslongfile_r_head() 153cdb7a6fcSAlan Somers{ 154cdb7a6fcSAlan Somers atf_set "descr" "Reverse a long file" 155cdb7a6fcSAlan Somers} 156cdb7a6fcSAlan Somerslongfile_r_body() 157cdb7a6fcSAlan Somers{ 158cdb7a6fcSAlan Somers jot -w "%0511d" 1030 0 > infile 159cdb7a6fcSAlan Somers jot -w "%0511d" 1030 1029 0 -1 > expectfile 160cdb7a6fcSAlan Somers tail -r infile > outfile 161cdb7a6fcSAlan Somers tail -r < infile > outpipe 162cdb7a6fcSAlan Somers atf_check cmp expectfile outfile 163cdb7a6fcSAlan Somers atf_check cmp expectfile outpipe 164cdb7a6fcSAlan Somers} 165cdb7a6fcSAlan Somers 166cdb7a6fcSAlan Somersatf_test_case longfile_r_enomem 167cdb7a6fcSAlan Somerslongfile_r_enomem_head() 168cdb7a6fcSAlan Somers{ 169cdb7a6fcSAlan Somers atf_set "descr" "Reverse a file that's too long to store in RAM" 170cdb7a6fcSAlan Somers} 171cdb7a6fcSAlan Somerslongfile_r_enomem_body() 172cdb7a6fcSAlan Somers{ 173cdb7a6fcSAlan Somers # When we reverse a file that's too long for RAM, tail should drop the 174cdb7a6fcSAlan Somers # first part and just print what it can. We'll check that the last 175cdb7a6fcSAlan Somers # part is ok 176cdb7a6fcSAlan Somers { 177cdb7a6fcSAlan Somers ulimit -v 32768 || atf_skip "Can't adjust ulimit" 178cdb7a6fcSAlan Somers jot -w "%01023d" 32768 0 | tail -r > outfile ; 179cdb7a6fcSAlan Somers } 180cdb7a6fcSAlan Somers if [ "$?" -ne 1 ]; then 181cdb7a6fcSAlan Somers atf_skip "Didn't get ENOMEM. Adjust test parameters" 182cdb7a6fcSAlan Somers fi 183cdb7a6fcSAlan Somers # We don't know how much of the input we dropped. So just check that 184cdb7a6fcSAlan Somers # the first ten lines of tail's output are the same as the last ten of 185cdb7a6fcSAlan Somers # the input 186cdb7a6fcSAlan Somers jot -w "%01023d" 10 32767 0 -1 > expectfile 187cdb7a6fcSAlan Somers head -n 10 outfile > outtrunc 188cdb7a6fcSAlan Somers diff expectfile outtrunc 189cdb7a6fcSAlan Somers atf_check cmp expectfile outtrunc 190cdb7a6fcSAlan Somers} 191cdb7a6fcSAlan Somers 192cdb7a6fcSAlan Somersatf_test_case longfile_r_longlines 193cdb7a6fcSAlan Somerslongfile_r_longlines_head() 194cdb7a6fcSAlan Somers{ 195cdb7a6fcSAlan Somers atf_set "descr" "Reverse a long file with extremely long lines" 196cdb7a6fcSAlan Somers} 197cdb7a6fcSAlan Somerslongfile_r_longlines_body() 198cdb7a6fcSAlan Somers{ 199cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 0 > infile 200cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 18000 >> infile 201cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 36000 >> infile 202cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 36000 > expectfile 203cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 18000 >> expectfile 204cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 0 >> expectfile 205cdb7a6fcSAlan Somers tail -r infile > outfile 206cdb7a6fcSAlan Somers tail -r < infile > outpipe 207cdb7a6fcSAlan Somers atf_check cmp expectfile outfile 208cdb7a6fcSAlan Somers atf_check cmp expectfile outpipe 209cdb7a6fcSAlan Somers} 210cdb7a6fcSAlan Somers 211cdb7a6fcSAlan Somersatf_test_case longfile_rc135782 212cdb7a6fcSAlan Somerslongfile_rc135782_head() 213cdb7a6fcSAlan Somers{ 214cdb7a6fcSAlan Somers atf_set "descr" "Reverse a long file and print the last 135,782 bytes" 215cdb7a6fcSAlan Somers} 216cdb7a6fcSAlan Somerslongfile_rc135782_body() 217cdb7a6fcSAlan Somers{ 218cdb7a6fcSAlan Somers jot -w "%063d" 9000 0 > infile 219cdb7a6fcSAlan Somers jot -w "%063d" 2121 8999 0 -1 > expectfile 220cdb7a6fcSAlan Somers echo "0000000000000000000000000000000006878" >> expectfile 221cdb7a6fcSAlan Somers tail -rc135782 infile > outfile 222cdb7a6fcSAlan Somers tail -rc135782 < infile > outpipe 223cdb7a6fcSAlan Somers atf_check cmp expectfile outfile 224cdb7a6fcSAlan Somers atf_check cmp expectfile outpipe 225cdb7a6fcSAlan Somers} 226cdb7a6fcSAlan Somers 227cdb7a6fcSAlan Somersatf_test_case longfile_rc145782_longlines 228cdb7a6fcSAlan Somerslongfile_rc145782_longlines_head() 229cdb7a6fcSAlan Somers{ 230cdb7a6fcSAlan Somers atf_set "descr" "Reverse a long file with extremely long lines and print the last 145,782 bytes" 231cdb7a6fcSAlan Somers} 232cdb7a6fcSAlan Somerslongfile_rc145782_longlines_body() 233cdb7a6fcSAlan Somers{ 234cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 0 > infile 235cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 18000 >> infile 236cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 36000 >> infile 237cdb7a6fcSAlan Somers jot -s " " -w "%07d" 18000 36000 > expectfile 238cdb7a6fcSAlan Somers echo -n "35777 " >> expectfile 239cdb7a6fcSAlan Somers jot -s " " -w "%07d" 222 35778 >> expectfile 240cdb7a6fcSAlan Somers tail -rc145782 infile > outfile 241cdb7a6fcSAlan Somers tail -rc145782 < infile > outpipe 242cdb7a6fcSAlan Somers atf_check cmp expectfile outfile 243cdb7a6fcSAlan Somers atf_check cmp expectfile outpipe 244cdb7a6fcSAlan Somers} 245cdb7a6fcSAlan Somers 246cdb7a6fcSAlan Somersatf_test_case longfile_rn2500 247cdb7a6fcSAlan Somerslongfile_rn2500_head() 248cdb7a6fcSAlan Somers{ 249cdb7a6fcSAlan Somers atf_set "descr" "Reverse a long file and print the last 2,500 lines" 250cdb7a6fcSAlan Somers} 251cdb7a6fcSAlan Somerslongfile_rn2500_body() 252cdb7a6fcSAlan Somers{ 253cdb7a6fcSAlan Somers jot -w "%063d" 9000 0 > infile 254cdb7a6fcSAlan Somers jot -w "%063d" 2500 8999 0 -1 > expectfile 255cdb7a6fcSAlan Somers tail -rn2500 infile > outfile 256cdb7a6fcSAlan Somers tail -rn2500 < infile > outpipe 257cdb7a6fcSAlan Somers atf_check cmp expectfile outfile 258cdb7a6fcSAlan Somers atf_check cmp expectfile outpipe 259cdb7a6fcSAlan Somers} 260cdb7a6fcSAlan Somers 261b2b1603eSConrad Meyeratf_test_case broken_pipe 262b2b1603eSConrad Meyerbroken_pipe_head() 263b2b1603eSConrad Meyer{ 264b2b1603eSConrad Meyer atf_set "descr" "Do not print bogus errno based output on short writes" 265b2b1603eSConrad Meyer} 266b2b1603eSConrad Meyerbroken_pipe_body() 267b2b1603eSConrad Meyer{ 2687c69f31eSEnji Cooper atf_check -o save:ints seq -f '%128g' 1 1000 26971607cbeSEnji Cooper atf_check -s ignore \ 27071607cbeSEnji Cooper -e "inline:tail: stdout\nexit code: 1\n" \ 27171607cbeSEnji Cooper -x '(tail -n 856 ints; echo exit code: $? >&2) | sleep 2' 272b2b1603eSConrad Meyer} 273b2b1603eSConrad Meyer 27458b1a126SMark Johnstonatf_test_case stdin 27558b1a126SMark Johnstonstdin_head() 27658b1a126SMark Johnston{ 27758b1a126SMark Johnston atf_set "descr" "Check basic operations on standard input" 27858b1a126SMark Johnston} 27958b1a126SMark Johnstonstdin_body() 28058b1a126SMark Johnston{ 28158b1a126SMark Johnston seq 1 5 > infile 28258b1a126SMark Johnston seq 1 5 > expectfile 28358b1a126SMark Johnston seq 5 1 > expectfile_r 28458b1a126SMark Johnston 28558b1a126SMark Johnston tail < infile > outfile 28658b1a126SMark Johnston tail -r < infile > outfile_r 28758b1a126SMark Johnston 28858b1a126SMark Johnston atf_check cmp expectfile outfile 28958b1a126SMark Johnston atf_check cmp expectfile_r outfile_r 29058b1a126SMark Johnston} 29158b1a126SMark Johnston 29258b1a126SMark Johnstonatf_test_case follow 29358b1a126SMark Johnstonfollow_head() 29458b1a126SMark Johnston{ 29558b1a126SMark Johnston atf_set "descr" "Basic regression test for -f" 29658b1a126SMark Johnston} 29758b1a126SMark Johnstonfollow_body() 29858b1a126SMark Johnston{ 29958b1a126SMark Johnston local pid 30058b1a126SMark Johnston 30158b1a126SMark Johnston seq 1 5 > expectfile 30258b1a126SMark Johnston seq 1 3 > infile 30358b1a126SMark Johnston tail -f infile > outfile & 30458b1a126SMark Johnston pid=$! 30558b1a126SMark Johnston sleep 0.1 30658b1a126SMark Johnston seq 4 5 >> infile 30758b1a126SMark Johnston sleep 0.1 30858b1a126SMark Johnston atf_check cmp expectfile outfile 30958b1a126SMark Johnston atf_check kill $pid 31058b1a126SMark Johnston} 31158b1a126SMark Johnston 31258b1a126SMark Johnstonatf_test_case follow_stdin 31358b1a126SMark Johnstonfollow_stdin_head() 31458b1a126SMark Johnston{ 31558b1a126SMark Johnston atf_set "descr" "Verify that -f works with files piped to standard input" 31658b1a126SMark Johnston} 31758b1a126SMark Johnstonfollow_stdin_body() 31858b1a126SMark Johnston{ 31958b1a126SMark Johnston local pid 32058b1a126SMark Johnston 32158b1a126SMark Johnston seq 1 5 > expectfile 32258b1a126SMark Johnston seq 1 3 > infile 32358b1a126SMark Johnston tail -f < infile > outfile & 32458b1a126SMark Johnston pid=$! 32558b1a126SMark Johnston sleep 0.1 32658b1a126SMark Johnston seq 4 5 >> infile 32758b1a126SMark Johnston sleep 0.1 32858b1a126SMark Johnston atf_check cmp expectfile outfile 32958b1a126SMark Johnston atf_check kill $pid 33058b1a126SMark Johnston} 33158b1a126SMark Johnston 332*621f4553SDag-Erling Smørgravatf_test_case follow_create 333*621f4553SDag-Erling Smørgravfollow_create_head() 334*621f4553SDag-Erling Smørgrav{ 335*621f4553SDag-Erling Smørgrav atf_set "descr" "Verify that -F works when a file is created" 336*621f4553SDag-Erling Smørgrav} 337*621f4553SDag-Erling Smørgravfollow_create_body() 338*621f4553SDag-Erling Smørgrav{ 339*621f4553SDag-Erling Smørgrav local pid 340*621f4553SDag-Erling Smørgrav 341*621f4553SDag-Erling Smørgrav rm -f infile 342*621f4553SDag-Erling Smørgrav tail -F infile > outfile & 343*621f4553SDag-Erling Smørgrav pid=$! 344*621f4553SDag-Erling Smørgrav seq 1 5 >infile 345*621f4553SDag-Erling Smørgrav sleep 2 346*621f4553SDag-Erling Smørgrav atf_check cmp infile outfile 347*621f4553SDag-Erling Smørgrav atf_check kill $pid 348*621f4553SDag-Erling Smørgrav} 349*621f4553SDag-Erling Smørgrav 35058b1a126SMark Johnstonatf_test_case follow_rename 35158b1a126SMark Johnstonfollow_rename_head() 35258b1a126SMark Johnston{ 353*621f4553SDag-Erling Smørgrav atf_set "descr" "Verify that -F works when a file is replaced" 35458b1a126SMark Johnston} 35558b1a126SMark Johnstonfollow_rename_body() 35658b1a126SMark Johnston{ 35758b1a126SMark Johnston local pid 35858b1a126SMark Johnston 35958b1a126SMark Johnston seq 1 5 > expectfile 36058b1a126SMark Johnston seq 1 3 > infile 36158b1a126SMark Johnston tail -F infile > outfile & 36258b1a126SMark Johnston pid=$! 36358b1a126SMark Johnston seq 4 5 > infile_new 36458b1a126SMark Johnston atf_check mv infile infile_old 36558b1a126SMark Johnston atf_check mv infile_new infile 36658b1a126SMark Johnston # tail -F polls for a new file every 1s. 36758b1a126SMark Johnston sleep 2 36858b1a126SMark Johnston atf_check cmp expectfile outfile 36958b1a126SMark Johnston atf_check kill $pid 37058b1a126SMark Johnston} 371cdb7a6fcSAlan Somers 372643ac419SXin LIatf_test_case silent_header 373643ac419SXin LIsilent_header_head() { 374643ac419SXin LI atf_set "descr" "Test tail(1)'s silent header feature" 375643ac419SXin LI} 376643ac419SXin LIsilent_header_body() { 377643ac419SXin LI jot 11 1 11 > file1 378643ac419SXin LI jot 11 2 12 > file2 379643ac419SXin LI jot 10 2 11 > expectfile 380643ac419SXin LI jot 10 3 12 >> expectfile 381643ac419SXin LI tail -q file1 file2 > outfile 382643ac419SXin LI atf_check cmp outfile expectfile 383643ac419SXin LI} 384643ac419SXin LI 385643ac419SXin LIatf_test_case verbose_header 386643ac419SXin LIverbose_header_head() { 387643ac419SXin LI atf_set "descr" "Test tail(1)'s verbose header feature" 388643ac419SXin LI} 389643ac419SXin LIverbose_header_body() { 390643ac419SXin LI jot 11 1 11 > file1 391643ac419SXin LI echo '==> file1 <==' > expectfile 392643ac419SXin LI jot 10 2 11 >> expectfile 393643ac419SXin LI tail -v file1 > outfile 394643ac419SXin LI atf_check cmp outfile expectfile 395643ac419SXin LI} 396643ac419SXin LI 397643ac419SXin LIatf_test_case si_number 398643ac419SXin LIsi_number_head() { 399643ac419SXin LI atf_set "descr" "Test tail(1)'s SI number feature" 400643ac419SXin LI} 401643ac419SXin LIsi_number_body() { 402643ac419SXin LI jot -b aaaaaaa 129 > file1 403643ac419SXin LI jot -b aaaaaaa 128 > expectfile 404643ac419SXin LI tail -c 1k file1 > outfile 405643ac419SXin LI atf_check cmp outfile expectfile 406643ac419SXin LI jot 1025 1 1025 > file1 407643ac419SXin LI jot 1024 2 1025 > expectfile 408643ac419SXin LI tail -n 1k file1 > outfile 409643ac419SXin LI atf_check cmp outfile expectfile 410643ac419SXin LI} 411643ac419SXin LI 412fa3af3ceSDag-Erling Smørgravatf_test_case no_lf_at_eof 413fa3af3ceSDag-Erling Smørgravno_lf_at_eof_head() 414fa3af3ceSDag-Erling Smørgrav{ 415fa3af3ceSDag-Erling Smørgrav atf_set "descr" "File does not end in newline" 416fa3af3ceSDag-Erling Smørgrav} 417fa3af3ceSDag-Erling Smørgravno_lf_at_eof_body() 418fa3af3ceSDag-Erling Smørgrav{ 419fa3af3ceSDag-Erling Smørgrav printf "a\nb\nc" >infile 420fa3af3ceSDag-Erling Smørgrav atf_check -o inline:"c" tail -1 infile 421fa3af3ceSDag-Erling Smørgrav atf_check -o inline:"b\nc" tail -2 infile 422fa3af3ceSDag-Erling Smørgrav atf_check -o inline:"a\nb\nc" tail -3 infile 423fa3af3ceSDag-Erling Smørgrav atf_check -o inline:"a\nb\nc" tail -4 infile 424fa3af3ceSDag-Erling Smørgrav} 425643ac419SXin LI 426cdb7a6fcSAlan Somersatf_init_test_cases() 427cdb7a6fcSAlan Somers{ 428cdb7a6fcSAlan Somers atf_add_test_case empty_r 429cdb7a6fcSAlan Somers atf_add_test_case file_r 430cdb7a6fcSAlan Somers atf_add_test_case file_rc28 431cdb7a6fcSAlan Somers atf_add_test_case file_rn2 432d23662ecSAlan Somers atf_add_test_case pipe_leading_newline_r 433cdb7a6fcSAlan Somers # The longfile tests are designed to exercise behavior in r_buf(), 434cdb7a6fcSAlan Somers # which operates on 128KB blocks 435cdb7a6fcSAlan Somers atf_add_test_case longfile_r 436cdb7a6fcSAlan Somers atf_add_test_case longfile_r_enomem 437cdb7a6fcSAlan Somers atf_add_test_case longfile_r_longlines 438cdb7a6fcSAlan Somers atf_add_test_case longfile_rc135782 439cdb7a6fcSAlan Somers atf_add_test_case longfile_rc145782_longlines 440cdb7a6fcSAlan Somers atf_add_test_case longfile_rn2500 44171607cbeSEnji Cooper atf_add_test_case broken_pipe 44258b1a126SMark Johnston atf_add_test_case stdin 44358b1a126SMark Johnston atf_add_test_case follow 44458b1a126SMark Johnston atf_add_test_case follow_stdin 445*621f4553SDag-Erling Smørgrav atf_add_test_case follow_create 44658b1a126SMark Johnston atf_add_test_case follow_rename 447643ac419SXin LI atf_add_test_case silent_header 448643ac419SXin LI atf_add_test_case verbose_header 449643ac419SXin LI atf_add_test_case si_number 450fa3af3ceSDag-Erling Smørgrav atf_add_test_case no_lf_at_eof 451cdb7a6fcSAlan Somers} 452