Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/compress tests/compress: demonstrate truncatio...



details:   https://anonhg.NetBSD.org/src/rev/4ce24bd92b7f
branches:  trunk
changeset: 366351:4ce24bd92b7f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 22 17:55:08 2022 +0000

description:
tests/compress: demonstrate truncation of target file

Reported by Giorgos Keramidas in PR#19722.

diffstat:

 distrib/sets/lists/tests/mi          |   5 +-
 etc/mtree/NetBSD.dist.tests          |   3 +-
 tests/usr.bin/Makefile               |   4 +-
 tests/usr.bin/compress/Makefile      |   7 ++
 tests/usr.bin/compress/t_pr_19722.sh |  89 ++++++++++++++++++++++++++++++++++++
 5 files changed, 104 insertions(+), 4 deletions(-)

diffs (157 lines):

diff -r 4966587ea3a5 -r 4ce24bd92b7f distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun May 22 13:58:59 2022 +0000
+++ b/distrib/sets/lists/tests/mi       Sun May 22 17:55:08 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1205 2022/05/12 20:49:21 rillig Exp $
+# $NetBSD: mi,v 1.1206 2022/05/22 17:55:08 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4629,6 +4629,9 @@
 ./usr/tests/usr.bin/col/rlf2.in                                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/col/rlf3.in                                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/col/t_col                                  tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/compress                           tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/compress/Atffile                   tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/compress/t_pr_19722                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/config                             tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/config/Atffile                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/config/Kyuafile                    tests-usr.bin-tests     compattestfile,atf,kyua
diff -r 4966587ea3a5 -r 4ce24bd92b7f etc/mtree/NetBSD.dist.tests
--- a/etc/mtree/NetBSD.dist.tests       Sun May 22 13:58:59 2022 +0000
+++ b/etc/mtree/NetBSD.dist.tests       Sun May 22 17:55:08 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: NetBSD.dist.tests,v 1.191 2022/04/29 22:17:50 pgoyette Exp $
+#      $NetBSD: NetBSD.dist.tests,v 1.192 2022/05/22 17:55:08 rillig Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -429,6 +429,7 @@
 ./usr/tests/usr.bin/config/support/arch/regress/conf
 ./usr/tests/usr.bin/config/support/conf
 ./usr/tests/usr.bin/cpio
+./usr/tests/usr.bin/compress
 ./usr/tests/usr.bin/cut
 ./usr/tests/usr.bin/diff
 ./usr/tests/usr.bin/dirname
diff -r 4966587ea3a5 -r 4ce24bd92b7f tests/usr.bin/Makefile
--- a/tests/usr.bin/Makefile    Sun May 22 13:58:59 2022 +0000
+++ b/tests/usr.bin/Makefile    Sun May 22 17:55:08 2022 +0000
@@ -1,11 +1,11 @@
-#      $NetBSD: Makefile,v 1.35 2021/10/12 17:24:36 nia Exp $
+#      $NetBSD: Makefile,v 1.36 2022/05/22 17:55:08 rillig Exp $
 #
 
 .include <bsd.own.mk>
 
 TESTSDIR=       ${TESTSBASE}/usr.bin
 
-TESTS_SUBDIRS= awk basename bzip2 cc cmp config cpio col cut \
+TESTS_SUBDIRS= awk basename bzip2 cc cmp compress config cpio col cut \
                diff dirname find fstat gdb grep gzip id indent \
                infocmp jot ld locale m4 make mixerctl mkdep nbperf \
                netpgpverify patch pkill pr printf pwhash rump_server \
diff -r 4966587ea3a5 -r 4ce24bd92b7f tests/usr.bin/compress/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/compress/Makefile   Sun May 22 17:55:08 2022 +0000
@@ -0,0 +1,7 @@
+#      $NetBSD: Makefile,v 1.1 2022/05/22 17:55:08 rillig Exp $
+
+TESTSDIR=      ${TESTSBASE}/usr.bin/compress
+
+TESTS_SH=      t_pr_19722
+
+.include <bsd.test.mk>
diff -r 4966587ea3a5 -r 4ce24bd92b7f tests/usr.bin/compress/t_pr_19722.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/compress/t_pr_19722.sh      Sun May 22 17:55:08 2022 +0000
@@ -0,0 +1,89 @@
+#      $NetBSD: t_pr_19722.sh,v 1.1 2022/05/22 17:55:08 rillig Exp $
+#
+# Copyright (c) 2022 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# https://gnats.netbsd.org/19722
+#
+# Before TODO:rev from TODO:date, trying to uncompress a nonexistent or
+# malformed source file resulted in a truncated target file.
+
+
+atf_test_case 'no_source_no_target'
+no_source_no_target_body()
+{
+
+       atf_check \
+           -s 'not-exit:0' \
+           -e 'inline:uncompress: file.Z: No such file or directory\n' \
+           uncompress -f 'file'
+
+       # FIXME: The target file must not be created.
+       atf_check cat 'file'
+       atf_check test ! -f 'nonexistent.Z'
+}
+
+
+atf_test_case 'no_source_existing_target'
+no_source_existing_target_body()
+{
+
+       echo 'before' > 'file'
+
+       atf_check \
+           -s 'not-exit:0' \
+           -e 'inline:uncompress: file.Z: No such file or directory\n' \
+           uncompress -f 'file'
+
+       # FIXME: The target file must not be truncated.
+       atf_check cat 'file'
+}
+
+
+atf_test_case 'broken_source_existing_target'
+broken_source_existing_target_body()
+{
+       # If the source file is not compressed, preserve the target file.
+
+       echo 'broken' > 'file.Z'
+       echo 'before' > 'file'
+
+       atf_check \
+           -s 'not-exit:0' \
+           -e 'inline:uncompress: file.Z: Inappropriate file type or format\n' \
+           uncompress -f 'file.Z'
+
+       # FIXME: Must not be removed, must not be truncated.
+       atf_check test ! -f 'file'
+}
+
+
+atf_init_test_cases()
+{
+
+       atf_add_test_case no_source_no_target
+       atf_add_test_case no_source_existing_target
+       atf_add_test_case broken_source_existing_target
+}



Home | Main Index | Thread Index | Old Index