Module Name: src Committed By: rillig Date: Sun May 22 17:55:09 UTC 2022
Modified Files: src/distrib/sets/lists/tests: mi src/etc/mtree: NetBSD.dist.tests src/tests/usr.bin: Makefile Added Files: src/tests/usr.bin/compress: Makefile t_pr_19722.sh Log Message: tests/compress: demonstrate truncation of target file Reported by Giorgos Keramidas in PR#19722. To generate a diff of this commit: cvs rdiff -u -r1.1205 -r1.1206 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.191 -r1.192 src/etc/mtree/NetBSD.dist.tests cvs rdiff -u -r1.35 -r1.36 src/tests/usr.bin/Makefile cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/compress/Makefile \ src/tests/usr.bin/compress/t_pr_19722.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1205 src/distrib/sets/lists/tests/mi:1.1206 --- src/distrib/sets/lists/tests/mi:1.1205 Thu May 12 20:49:21 2022 +++ src/distrib/sets/lists/tests/mi Sun May 22 17:55:08 2022 @@ -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 Index: src/etc/mtree/NetBSD.dist.tests diff -u src/etc/mtree/NetBSD.dist.tests:1.191 src/etc/mtree/NetBSD.dist.tests:1.192 --- src/etc/mtree/NetBSD.dist.tests:1.191 Fri Apr 29 22:17:50 2022 +++ src/etc/mtree/NetBSD.dist.tests Sun May 22 17:55:08 2022 @@ -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 Index: src/tests/usr.bin/Makefile diff -u src/tests/usr.bin/Makefile:1.35 src/tests/usr.bin/Makefile:1.36 --- src/tests/usr.bin/Makefile:1.35 Tue Oct 12 17:24:36 2021 +++ src/tests/usr.bin/Makefile Sun May 22 17:55:08 2022 @@ -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 \ Added files: Index: src/tests/usr.bin/compress/Makefile diff -u /dev/null src/tests/usr.bin/compress/Makefile:1.1 --- /dev/null Sun May 22 17:55:09 2022 +++ src/tests/usr.bin/compress/Makefile Sun May 22 17:55:08 2022 @@ -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> Index: src/tests/usr.bin/compress/t_pr_19722.sh diff -u /dev/null src/tests/usr.bin/compress/t_pr_19722.sh:1.1 --- /dev/null Sun May 22 17:55:09 2022 +++ src/tests/usr.bin/compress/t_pr_19722.sh Sun May 22 17:55:08 2022 @@ -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 +}