1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-30 22:23:13 +03:00

Fix #1428 - zstdgrep returned 1 on match and unmatch

- Use ZCAT for testing zstdgrep in case of non-install yet
- tests: Add file test for zstdgrep
This commit is contained in:
Lzu Tao
2019-01-06 21:22:49 +07:00
parent f8c8796dfe
commit 7b6a8840c5
2 changed files with 16 additions and 16 deletions

View File

@ -22,8 +22,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
grep=grep grep=${GREP:-grep}
zcat=zstdcat zcat=${ZCAT:-zstdcat}
endofopts=0 endofopts=0
pattern_found=0 pattern_found=0
@ -31,12 +31,13 @@ grep_args=""
hyphen=0 hyphen=0
silent=0 silent=0
prg=$(basename "$0") prog=${0##*/}
# handle being called 'zegrep' or 'zfgrep' # handle being called 'zegrep' or 'zfgrep'
case "${prg}" in case $prog in
*zegrep) grep_args="-E";; *egrep*) prog=zegrep; grep_args='-E';;
*zfgrep) grep_args="-F";; *fgrep*) prog=zfgrep; grep_args='-F';;
*) prog=zstdgrep;;
esac esac
# skip all options and pass them on to grep taking care of options # skip all options and pass them on to grep taking care of options
@ -47,7 +48,7 @@ while [ "$#" -gt 0 ] && [ "${endofopts}" -eq 0 ]; do
# from GNU grep-2.5.1 -- keep in sync! # from GNU grep-2.5.1 -- keep in sync!
-[ABCDXdefm]) -[ABCDXdefm])
if [ "$#" -lt 2 ]; then if [ "$#" -lt 2 ]; then
printf '%s: missing argument for %s flag\n' "${prg}" "$1" >&2 printf '%s: missing argument for %s flag\n' "${prog}" "$1" >&2
exit 1 exit 1
fi fi
case "$1" in case "$1" in
@ -94,7 +95,7 @@ if [ "${pattern_found}" -lt 1 ]; then
elif [ "${hyphen}" -gt 0 ]; then elif [ "${hyphen}" -gt 0 ]; then
pattern="-" pattern="-"
else else
printf '%s: missing pattern\n' "${prg}" >&2 printf '%s: missing pattern\n' "${prog}" >&2
exit 1 exit 1
fi fi
fi fi
@ -113,16 +114,11 @@ else
if [ "${silent}" -lt 1 ] && [ "$#" -gt 1 ]; then if [ "${silent}" -lt 1 ] && [ "$#" -gt 1 ]; then
grep_args="-H ${grep_args}" grep_args="-H ${grep_args}"
fi fi
CUR_EXIT_CODE=0
EXIT_CODE=1
set -f set -f
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
# shellcheck disable=SC2086 # shellcheck disable=SC2086
"${zcat}" -fq -- "$1" | "${grep}" --label="${1}" ${grep_args} -- "${pattern}" - "${zcat}" -fq -- "$1" | "${grep}" --label="${1}" ${grep_args} -- "${pattern}" -
CUR_EXIT_CODE=$? [ "$?" -ne 0 ] && EXIT_CODE=1
if [ "${CUR_EXIT_CODE}" -eq 0 ] && [ "${EXIT_CODE}" -ne 1 ]; then
EXIT_CODE=0
fi
shift shift
done done
set +f set +f

View File

@ -353,8 +353,12 @@ test-gzstd: gzstd
$(RM) *.gz *.zst README2.md gz_zstd zstd_gz hello.txt $(RM) *.gz *.zst README2.md gz_zstd zstd_gz hello.txt
test-zstdgrep: gzstd test-zstdgrep: gzstd
@echo a | $(PRGDIR)/zstd | $(PRGDIR)/zstdgrep a -[ -f /tmp/zstdcat ] || ln -s $(PWD)/$(PRGDIR)/zstd /tmp/zstdcat
@echo a | $(PRGDIR)/zstd | $(PRGDIR)/zstdgrep b && return 1 || return 0 echo a | $(PRGDIR)/zstd | env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep a
echo a | $(PRGDIR)/zstd | env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep b && return 1 || return 0
-echo 'hello world' > test.txt && $(PRGDIR)/zstd test.txt
env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep hello test.txt.zst
env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep weird test.txt.zst && return 1 || return 0
test-fullbench: fullbench datagen test-fullbench: fullbench datagen
$(QEMU_SYS) ./fullbench -i1 $(QEMU_SYS) ./fullbench -i1