From b8e52d3c83eeeeec088836b5840ee1ca307a612d Mon Sep 17 00:00:00 2001 From: Sean Purcell Date: Thu, 16 Mar 2017 16:06:03 -0700 Subject: [PATCH 1/3] Fix zstd not erroring on compressing to terminal without forceStdout --- programs/zstdcli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/zstdcli.c b/programs/zstdcli.c index ae49da7b..fc7ca9e3 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -635,7 +635,7 @@ int main(int argCount, const char* argv[]) /* Check if input/output defined as console; trigger an error in this case */ if (!strcmp(filenameTable[0], stdinmark) && IS_CONSOLE(stdin) ) CLEAN_RETURN(badusage(programName)); - if (outFileName && !strcmp(outFileName, stdoutmark) && IS_CONSOLE(stdout) && strcmp(filenameTable[0], stdinmark) && !(forceStdout && (operation==zom_decompress))) + if (outFileName && !strcmp(outFileName, stdoutmark) && IS_CONSOLE(stdout) && !strcmp(filenameTable[0], stdinmark) && !forceStdout && operation!=zom_decompress) CLEAN_RETURN(badusage(programName)); /* user-selected output filename, only possible with a single file */ From d973071e907ba2b9f99db6ea14c625a1307c1ac9 Mon Sep 17 00:00:00 2001 From: Sean Purcell Date: Thu, 16 Mar 2017 16:25:19 -0700 Subject: [PATCH 2/3] Add tests for compressed data on console --- tests/playTests.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/playTests.sh b/tests/playTests.sh index c493fed5..c584fe56 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -72,6 +72,10 @@ cp tmp tmp2 $ZSTD tmp2 -fo && die "-o must be followed by filename " $ECHO "test : implied stdout when input is stdin" $ECHO bob | $ZSTD | $ZSTD -d +$ECHO "test : compressed data to terminal" +$ECHO bob | $ZSTD && die "should have refused : compressed data to terminal" +$ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)" +$ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal" $ECHO "test : null-length file roundtrip" $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout $ECHO "test : decompress file with wrong suffix (must fail)" From 9a38dfa7948c8ea80b07a2f3af152d02b481c4b9 Mon Sep 17 00:00:00 2001 From: Sean Purcell Date: Fri, 17 Mar 2017 12:32:18 -0700 Subject: [PATCH 3/3] Only run IS_CONSOLE tests with a TTY --- tests/playTests.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/playTests.sh b/tests/playTests.sh index c584fe56..38a66d32 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -20,6 +20,12 @@ roundTripTest() { $DIFF -q tmp1 tmp2 } +isTerminal=false +if [ -t 0 ] && [ -t 1 ] +then + isTerminal=true +fi + isWindows=false ECHO="echo" INTOVOID="/dev/null" @@ -27,6 +33,7 @@ case "$OS" in Windows*) isWindows=true ECHO="echo -e" + INTOVOID="NUL" ;; esac @@ -72,10 +79,12 @@ cp tmp tmp2 $ZSTD tmp2 -fo && die "-o must be followed by filename " $ECHO "test : implied stdout when input is stdin" $ECHO bob | $ZSTD | $ZSTD -d +if [ "$isTerminal" = true ]; then $ECHO "test : compressed data to terminal" $ECHO bob | $ZSTD && die "should have refused : compressed data to terminal" $ECHO "test : compressed data from terminal (a hang here is a test fail, zstd is wrongly waiting on data from terminal)" $ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal" +fi $ECHO "test : null-length file roundtrip" $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout $ECHO "test : decompress file with wrong suffix (must fail)" @@ -244,7 +253,7 @@ $ZSTD -f tmp -D tmpDict1 --no-dictID $ZSTD -d tmp.zst -D tmpDict -fo result $DIFF $TESTFILE result $ECHO "- Compress with wrong argument order (must fail)" -$ZSTD tmp -Df tmpDict1 -c > /dev/null && die "-D must be followed by dictionary name " +$ZSTD tmp -Df tmpDict1 -c > $INTOVOID && die "-D must be followed by dictionary name " $ECHO "- Compress multiple files with dictionary" rm -rf dirTestDict mkdir dirTestDict