mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
du: tests: fix the H_flag test (primarily grep usage)
This test attempts to use \t (tab intended) in a grep expression. With the former /usr/bin/grep (i.e. gnugrep), this was interpreted as a literal 't'. The expression would work anyways because the tr(1) usage would ultimately replace all of the spaces with a single newline, and they would match the paths whether they were correctly fromatted or not. Current /usr/bin/grep (i.e. bsdgrep) is less-tolerant of ordinary-escapes, a property of the underlying regex(3) engine, to make it easier to identify when stuff like this happens. In-fact, this expression broke after the switch happened. This revision does the bare basics to fix the usage by using a printf to get a literal tab character to insert into the expression. It also swaps out the manual insertion of the line prefix into the grep expression by pulling that part out of $sep and reusing it for the leading path. The secondary issue was the tr(1) usage, since tr would only replace the first character of string1 with the first character of string2. This has instead been replaced by a sed expression, which similary understands \n to be a newline on all supported versions of FreeBSD. Each path now gets prefixed with the appropriate context that should be there (i.e. numeric sequence followed by a tab). PR: 252446 Reviewed by: emaste, ngie Differential Revision: https://reviews.freebsd.org/D27983
This commit is contained in:
parent
27e90f70e0
commit
4832d2e8ae
|
@ -46,15 +46,16 @@ H_flag_body()
|
|||
{
|
||||
local paths1='testdir/A/B testdir/A testdir/C testdir'
|
||||
local paths2='testdir/A/B testdir/A testdir/C testdir'
|
||||
local sep='\n[0-9]+\t'
|
||||
local lineprefix="^[0-9]+$(printf "\t")"
|
||||
local sep="\n${lineprefix}"
|
||||
|
||||
atf_check mkdir testdir
|
||||
atf_check -x "cd testdir && mkdir A && touch A/B && ln -s A C"
|
||||
|
||||
atf_check -o save:du.out du -aAH testdir
|
||||
atf_check egrep -q "[0-9]+\t$(echo $paths1 | tr ' ' "$sep")\n" du.out
|
||||
atf_check egrep -q "${lineprefix}$(echo $paths1 | sed -e "s/ /$sep/g")" du.out
|
||||
atf_check -o save:du_C.out du -aAH testdir/C
|
||||
atf_check egrep -q "[0-9]+\t$(echo $paths2 | tr ' ' "$sep")\n" du_C.out
|
||||
atf_check egrep -q "${lineprefix}$(echo $paths2 | sed -e "s/ /$sep/g")" du_C.out
|
||||
}
|
||||
|
||||
atf_test_case I_flag
|
||||
|
|
Loading…
Reference in a new issue