From: Johannes Sixt Date: Wed, 02 Nov 2016 18:03:34 GMT Subject: Re: [PATCH v11 13/14] convert: add filter..process option Message-ID: <3b09d218-33bd-dc7c-235c-8954a46afc41@kdbg.org> In-Reply-To: <20161016232038.84951-14-larsxschneider@gmail.com> Am 17.10.2016 um 01:20 schrieb larsxschneider@gmail.com: > +# Compare two files and ensure that `clean` and `smudge` respectively are > +# called at least once if specified in the `expect` file. The actual > +# invocation count is not relevant because their number can vary. > +# c.f. http://public-inbox.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/ > +test_cmp_count () { > + expect=$1 > + actual=$2 > + for FILE in "$expect" "$actual" > + do > + sort "$FILE" | uniq -c | sed "s/^[ ]*//" | > + sed "s/^\([0-9]\) IN: clean/x IN: clean/" | > + sed "s/^\([0-9]\) IN: smudge/x IN: smudge/" >"$FILE.tmp" && This is not sufficiently portable. Some versions of uniq write the count left-adjusted, not right-adjusted. How about this on top: diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index a20b9f58e3..f60858c517 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -40,10 +40,9 @@ test_cmp_count () { actual=$2 for FILE in "$expect" "$actual" do - sort "$FILE" | uniq -c | sed "s/^[ ]*//" | - sed "s/^\([0-9]\) IN: clean/x IN: clean/" | - sed "s/^\([0-9]\) IN: smudge/x IN: smudge/" >"$FILE.tmp" && - mv "$FILE.tmp" "$FILE" + sort "$FILE" | uniq -c | + sed -e "s/^ *[0-9][0-9]* *IN: /x IN: /" >"$FILE.tmp" && + mv "$FILE.tmp" "$FILE" || return done && test_cmp "$expect" "$actual" } -- Hannes